StatusValue: Add a getter for MessageSpecifier list
[mediawiki.git] / DEVELOPERS.md
blob19cf81f94fe79db13dc60deac0f95c1c6976db55
1 # MediaWiki Developers
3 Welcome to the MediaWiki community! Please see [How to become a MediaWiki
4 hacker](https://www.mediawiki.org/wiki/How_to_become_a_MediaWiki_hacker) for
5 general information on contributing to MediaWiki.
7 ## Development environment
9 MediaWiki provides an extendable local development environment based on Docker Compose. This environment provides PHP,
10 Apache, Xdebug and a SQLite database.
12 **Do not use the development environment to serve a public website! Bad things would happen!**
14 More documentation, examples, and configuration recipes are available at [mediawiki.org/wiki/MediaWiki-Docker][mw-docker].
16 Support is available on the [Libera IRC network][libera-home] in the [#mediawiki channel][libera-webchat], and on
17 Phabricator by creating tasks with the [MediaWiki-Docker][mw-docker-phab] tag.
19 [mw-docker]: https://www.mediawiki.org/wiki/MediaWiki-Docker
20 [mw-docker-phab]: https://phabricator.wikimedia.org/tag/mediawiki-docker/
21 [libera-home]: https://libera.chat/
22 [libera-webchat]: https://web.libera.chat/#mediawiki
24 ## Quickstart
26 ### 1. Requirements
28 You'll need to have Docker installed:
30 * [Docker Desktop][docker-install] for macOS or Windows.
31 * [Docker engine][docker-linux] for Linux.
33 [docker-install]: https://docs.docker.com/get-docker/
34 [docker-linux]: https://docs.docker.com/engine/install/
36 **Linux users**:
38 * We recommend installing `docker-ce`, `docker-ce-cli`, `containerd.io`, and `docker-compose-plugin` by [downloading the server
39   releases][dc-release] for your distribution rather than Docker Desktop. You can also install the [binaries][dc-binaries].
40 * Follow the instructions to ["Manage Docker as a non-root user"][dc-non-root]
42 [dc-release]: https://docs.docker.com/engine/install/
43 [dc-binaries]: https://docs.docker.com/engine/install/binaries/
44 [dc-non-root]: https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user
46 **Windows users**:
48 Running Docker from a Windows terminal and using the Windows file system will result in MediaWiki being very slow. For Windows 10 and higher, we recommend configuring Docker and Windows to use the [Windows Subsystem for Linux (WSL)](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux). Turn on WSL in your Windows settings, then run the following commands: `wsl --install -d ubuntu` and `wsl --set-version ubuntu 2`. Then go into Docker -> Settings -> General -> tick "Use the WSL 2 based engine", then go into Docker -> Settings -> Resources -> WSL Integration -> tick "Ubuntu". `git clone` the mediawiki repository into a WSL folder such as `home/yourusername/mediawiki` so that the files are inside WSL. Then you can run most of the commands in this tutorial outside of WSL, by opening PowerShell, navigating to the WSL directory with `cd \\wsl.localhost\Ubuntu\home\yourusername\mediawiki`, and executing shell commands as normal. To access WSL from PowerShell (rare but may be needed sometimes), you can use the command `ubuntu` to turn a PowerShell console into a WSL console. To navigate to WSL folders in [File Explorer](https://en.wikipedia.org/wiki/File_Explorer), show the Navigation Pane, then towards the bottom, look for "Linux" (it will be close to "This PC").
50 **Mac users**:
52 If you're using Docker Desktop and have the `Use Rosetta for x86/amd64 emulation on Apple Silicon` setting enabled, you may encounter an issue where loading the wiki results in a blank page or a 503 error. To resolve this, disable the setting and restart Docker Desktop. See [this page](https://phabricator.wikimedia.org/P49617) for more information.
54 ### 2. Download MediaWiki files
56 Download the latest MediaWiki files to your computer. One way to download the latest alpha version of MediaWiki is to
57 [install git](https://git-scm.com/), open a shell, navigate to the directory where you want to save the files, then type
58 `git clone https://gerrit.wikimedia.org/r/mediawiki/core.git mediawiki`.
60 Optional: If you plan to submit patches to this repository, you will probably want to [create a Gerrit account](https://wikitech.wikimedia.org/wiki/Help:Create_a_Wikimedia_developer_account),
61 then type `git remote set-url origin ssh://YOUR-GERRIT-USERNAME-HERE@gerrit.wikimedia.org:29418/mediawiki/core`,
62 replacing YOUR-GERRIT-USERNAME-HERE with your Gerrit username. Please see the official
63 [MediaWiki Gerrit tutorial](https://www.mediawiki.org/wiki/Gerrit/Tutorial) for more information.
65 ### 3. Prepare `.env` file
67 Using a text editor, create a `.env` file in the root of the MediaWiki core repository, and copy these contents into
68 that file:
70 ```sh
71 MW_SCRIPT_PATH=/w
72 MW_SERVER=http://localhost:8080
73 MW_DOCKER_PORT=8080
74 MEDIAWIKI_USER=Admin
75 MEDIAWIKI_PASSWORD=dockerpass
76 XDEBUG_CONFIG=
77 XDEBUG_ENABLE=true
78 XHPROF_ENABLE=true
79 ```
81 Windows users: Run the following command to add a blank user ID and group ID to your `.env` file:
83 ```sh
84 echo "
85 MW_DOCKER_UID=
86 MW_DOCKER_GID=" >> .env
87 ```
89 Non-Windows users: Run the following command to add your user ID and group ID to your `.env` file:
91 ```sh
92 echo "MW_DOCKER_UID=$(id -u)
93 MW_DOCKER_GID=$(id -g)" >> .env
94 ```
96 Linux users: If you'd like to use Xdebug features inside your IDE, then create a `docker-compose.override.yml` file as
97 well:
99 ```yaml
100 version: '3.7'
101 services:
102   mediawiki:
103     # For Linux: This extra_hosts section enables Xdebug-IDE communication:
104     extra_hosts:
105       - "host.docker.internal:host-gateway"
108 ### 4. Create the environment
110 * Start the containers:
111   ```sh
112   docker compose up -d
113   ```
114   The "up" command makes sure that the PHP and webserver containers are running (and any others in the
115   `docker-compose.yml` file). It is safe to run at any time, and will do nothing if the containers are already running.
117   The first time, it may take a few minutes to download new Docker images.
119   The `-d` argument stands for "detached" mode, which run the services in the background. If you suspect a problem with
120   one of the services, you can run it without `-d` to follow the server logs directly from your terminal. You don't have
121   to stop the services first, if you ran it with `-d` and then without, you'll get connected to the already running
122   containers including a decent back scroll of server logs.
124   Note that MediaWiki debug logs go to `/cache/*.log` files (not sent to docker).
126 * Install PHP dependencies from Composer:
127   ```sh
128   docker compose exec mediawiki composer update
129   ```
131 * Install MediaWiki:
132   ```sh
133   docker compose exec mediawiki /bin/bash /docker/install.sh
134   ```
135   Windows users: make sure you run the above command in PowerShell as it does not work in Bash.
137 * Windows users: Make sure to set the SQLite directory to be writable.
138   ```sh
139   docker compose exec mediawiki chmod -R o+rwx cache/sqlite
140   ```
142 Done! The wiki should now be available for you at <http://localhost:8080>.
144 ## Usage
146 ### Running commands
148 You can use `docker compose exec mediawiki bash` to open a Bash shell in the
149 MediaWiki container. You can then run one or more commands as needed and stay
150 within the container shell.
152 You can also run a single command in the container directly from your host
153 shell, for example: `docker compose exec mediawiki php maintenance/run.php update`.
155 ### PHPUnit
157 Run a single PHPUnit file or directory:
159 ```sh
160 docker compose exec mediawiki bash
161 instance:/w$ cd tests/phpunit
162 instance:/w/tests/phpunit$ composer phpunit -- path/to/my/test/
165 See [PHPUnit on mediawiki.org][phpunit-testing] for more examples.
167 [phpunit-testing]: https://www.mediawiki.org/wiki/Manual:PHP_unit_testing/Running_the_tests
169 ### Selenium
171 You can use [Fresh][fresh] to run [Selenium in a dedicated
172 container][selenium-dedicated]. Example usage:
174 ```sh
175 fresh-node -env -net
176 npm ci
177 npm run selenium-test
180 [selenium-dedicated]: https://www.mediawiki.org/wiki/Selenium/Getting_Started/Run_tests_using_Fresh
182 ### API Testing
184 You can use [Fresh][fresh] to run [API tests in a dedicated
185 container][api-dedicated]. Example usage:
187 ```sh
188 export MW_SERVER=http://localhost:8080/
189 export MW_SCRIPT_PATH=/w
190 export MEDIAWIKI_USER=Admin
191 export MEDIAWIKI_PASSWORD=dockerpass
192 fresh-node -env -net
193 # Create .api-testing.config.json as documented on
194 # https://www.mediawiki.org/wiki/MediaWiki_API_integration_tests
195 npm ci
196 npm run api-testing
199 [fresh]: https://github.com/wikimedia/fresh
200 [api-dedicated]: https://www.mediawiki.org/wiki/MediaWiki_API_integration_tests
202 ## Modify the development environment
204 You can override the default services from a `docker-compose.override.yml`
205 file, and make use of those overrides by changing `LocalSettings.php`.
207 Example overrides and configurations can be found under
208 [MediaWiki-Docker on mediawiki.org][mw-docker].
210 After updating `docker-compose.override.yml`, run `docker compose down`
211 followed by `docker compose up -d` for changes to take effect.
213 ### Install extra packages
215 If you need root on the container to install system packages with `apt-get` for
216 troubleshooting, you can open a shell as root with
217 `docker compose exec --user root mediawiki bash`.
219 ### Install extensions and skins
221 To install an extension or skin, follow the instructions of the mediawiki.org
222 page for the extension or skin in question, and look for any dependencies
223 or additional steps that may be needed.
225 For most extensions, only two steps are needed: download the code to the
226 right directory, and then enable the component from `LocalSettings.php`.
228 To install the Vector skin:
230 1. Clone the skin:
231     ```sh
232     cd skins/
233     git clone https://gerrit.wikimedia.org/r/mediawiki/skins/Vector
234     ```
236 2. Enable the skin, by adding the following to `LocalSettings.php`:
237     ```php
238     wfLoadSkin( 'Vector' );
239     ```
241 To install the EventLogging extension:
243 1. Clone the extension repository:
245     ```sh
246     cd extensions/
247     git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/EventLogging
248     ```
250     Alternatively, if you have extension repositories elsewhere on disk, mount each one as an overlapping volume in
251     `docker-compose.override.yml`. This is comparable to a symlink, but those are not well-supported in Docker.
253     ```yaml
254    version: '3.7'
255    services:
256      mediawiki:
257        volumes:
258          - ~/Code/EventLogging:/var/www/html/w/extensions/EventLogging:cached
259     ```
261 2. Enable the extension, by adding the following to `LocalSettings.php`:
262     ```php
263     wfLoadExtension( 'EventLogging' );
264     ```
266 ### Xdebug
268 By default, you will need to set `XDEBUG_TRIGGER=1` in the GET/POST, or as an
269 environment variable, to turn on Xdebug for a request.
271 You can also install a browser extension for controlling whether Xdebug is
272 active. See the [official Xdebug Step Debugging][step-debug], particularly the
273 "Activating Step Debugging" section, for more details.
275 [step-debug]: https://xdebug.org/docs/step_debug
277 If you wish to run Xdebug on every request, you can set
278 `start_with_request=yes` in `XDEBUG_CONFIG` in your .env file:
281 XDEBUG_CONFIG=start_with_request=yes
284 You can pass any of Xdebug's configuration values in this variable. For example:
287 XDEBUG_CONFIG=client_host=192.168.42.34 client_port=9000 log=/tmp/xdebug.log
290 This shouldn't be necessary for basic use cases, but see [the Xdebug settings
291 documentation](https://xdebug.org/docs/all_settings) for available settings.
293 ### Stop or recreate environment
295 Stop the environment, perhaps to reduce the load when working on something
296 else. This preserves the containers, to be restarted later quickly with
297 the `docker compose up -d` command.
299 ```sh
300 docker compose stop
303 Destroy and re-create the environment. This will delete the containers,
304 including any logs, caches, and other modifications you may have made
305 via the shell.
307 ```sh
308 docker compose down
309 docker compose up -d
312 ### Re-install the database
314 To empty the wiki database and re-install it:
316 * Remove or rename the `LocalSettings.php` file.
317 * Delete the `cache/sqlite` directory.
318 * Re-run the "Install MediaWiki database" command.
320 You can now restore or copy over any modifications you had in your previous `LocalSettings.php` file.
321 And if you have any additional extensions installed that required a database table, then also run:
322 `docker compose exec mediawiki php maintenance/run.php update`.
324 ## Troubleshooting
326 ### Caching
328 If you suspect a change is not applying due to caching, start by [hard
329 refreshing](https://en.wikipedia.org/wiki/Wikipedia:Bypass_your_cache) the browser.
331 If that doesn't work, you can narrow it down by disabling various server-side
332 caching layers in `LocalSettings.php`, as follows:
334 ```php
335 $wgMainCacheType = CACHE_NONE;
336 $wgMessageCacheType = CACHE_NONE;
337 $wgParserCacheType = CACHE_NONE;
338 $wgResourceLoaderMaxage = [
339   'versioned' => 0,
340   'unversioned' => 0
344 The default settings of MediaWiki are such that caching is smart and changes
345 propagate immediately. Using the above settings may slow down your wiki
346 significantly. Especially on macOS and Windows, where Docker Desktop uses
347 a VM internally and thus has longer file access times.
349 See [Manual:Caching][manual-caching] on mediawiki.org for more information.
351 [manual-caching]: https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Caching
353 ### Xdebug ports
355 Older versions of Xdebug used port 9000, which could conflict with php-fpm
356 running on the host. This document used to recommend a workaround of telling
357 your IDE to listen on a different port (e.g., 9009) and setting
358 `XDEBUG_CONFIG=remote_port=9009` in your `.env`.
360 Xdebug 3.x now uses the `client_port` value, which defaults to 9003. This
361 should no longer conflict with local php-fpm installations, but you may need
362 to change the settings in your IDE or debugger.
364 ### Linux desktop, host not found
366 The image uses `host.docker.internal` as the `client_host` value which
367 should allow Xdebug work for Docker for Mac/Windows.
369 On Linux, you need to create a `docker-compose.override.yml` file with the following
370 contents:
372 ```yaml
373 version: '3.7'
374 services:
375   mediawiki:
376     extra_hosts:
377       - "host.docker.internal:host-gateway"
380 With the latest version of Docker on Linux hosts, this _should_ work
381 transparently as long as you're using the recommended
382 `docker-compose.override.yml`. If it doesn't, first check `docker version` to
383 make sure you're running Docker 20.10.2 or above, and `docker compose version`
384 to make sure it's 1.27.4 or above.
386 If Xdebug still doesn't work, try specifying the hostname or IP address of your
387 host. The IP address works more reliably. You can obtain it by running e.g.
388 `ip -4 addr show docker0` and copying the IP address into the config in `.env`,
389 like `XDEBUG_CONFIG=remote_host=172.17.0.1`
391 ### Generating logs
393 Switching on the remote log for Xdebug comes at a performance cost so only
394 use it while troubleshooting. You can enable it like so: `XDEBUG_CONFIG=remote_log=/tmp/xdebug.log`
396 ### "(Permission Denied)" errors on running docker compose
398 See if you're able to run any docker commands to start with. Try running
399 `docker container ls`, which should also throw a permission error. If not,
400 go through the following steps to get access to the socket that the docker
401 client uses to talk to the daemon.
403 `sudo usermod -aG docker $USER`
405 And then `relogin` (or `newgrp docker`) to re-login with the new group membership.
407 ### "(Cannot access the database: Unknown error (localhost))"
409 The environment's working directory has recently changed to `/var/www/html/w`.
410 Reconfigure this in your `LocalSettings.php` by ensuring that the following
411 values are set correctly:
413 ```php
414 $wgScriptPath = '/w';
415 $wgSQLiteDataDir = "/var/www/html/w/cache/sqlite";
418 ### Windows users, "(Cannot access the database: No database connection (unknown))"
420 The permissions with the `cache/sqlite` directory have to be set manually on Windows:
422 ```sh
423 docker compose exec mediawiki chmod -R o+rwx cache/sqlite