User:ATomasevich (WMF)/Local Development Tips

Setup and basic usage
For those who want to use Docker, you have a couple of options:


 * 1) Use addshore's Mediawiki docker dev repo
 * 2) Use Monte's SDC-specific fork

The latter has an extended setup script that sets up various extensions needed for SDC development. I would highly recommend using it, or at least reviewing the setup script to see what you need. Follow the instructions in the README to get things set up, then add a few more extensions and LocalSettings config:


 * CommonsMetadata
 * MultimediaViewer
 * ParserFunctions
 * Scribunto
 * TemplateData
 * TemplateStyles

You should clone these from Gerrit, not GitHub, so you can easily pull the latest version if needed.

``` git clone ssh://@gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer.git ```
 * 1) Example

Add the extensions to your `mediawiki/LocalSettings.php` file (see the end of this page for my LocalSettings file). Next, from the root of the docker dev repo, run `./bash` to run commands on the webserver. `cd` into the directory of each of the 6 extensions you just installed and run `composer install`.

Docker commands
See the original Docker repo's README for a list of Docker commands you can run via scripts (like we just did to shell into the container via `./bash`).

Refreshing your local environment
When you pull updates for extensions you'll want to run `composer update` in that extension's directory. You can also run database updates by shelling in and running `php maintenance/update.php`.

When pulling new code for Wikibase you'll also need to pull its subprojects by running `git submodule update --init`.

Special pages
There are various "special" pages that aren't created like normal wiki pages, but rather are created via code within Mediawiki or an extension. You can view a list of them all at Special:SpecialPages (this link goes to the local version if you're using the D0cker setup).

Importing content
You can export content from other wikis and import them to your local instance. Note that this doesn't work great with large files.


 * Export: Visit Special:Export e.g. https://commons.wikimedia.org/wiki/Special:Export. Add pages via their titles, like File:Filename.jpg.
 * Import: Go to http://default.web.mw.localhost:8080/mediawiki/index.php?title=Special:Import. Be sure to include the prefix of the wiki you exported from, e.g. `commons`.

Xdebug
See instructions at the end of Monte's README for instructions on setting up Xdebug with PhpStorm or vscode. You'll also need the Xdebug Helper extension. Note that my path mapping value is slightly different from the README:

``` {	"name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9000, "pathMappings": { "/var/www/mediawiki": "${workspaceFolder}/mediawiki" } }, ```

Front-end debug mode
Add the query parameter `?debug=true` to run Resource Loader in debug mode, which will stop it from minifying and concatenating your front-end assets.

Localisation
You can add the query parameter `?uselang=fr` with any language code to view a page in that language. You can also use the language code `qqx` which will turn all language strings into the message key that defines them, which is useful for figuring out where specific messages come from.

Miscellaneous tips

 * MacOS users: add the following to your `~/.ssh/config` file to use your keychain to store your Gerrit passphrase:

``` Host * UseKeychain yes ```


 * You can experiment with the Mediawiki API on Special:ApiSandbox
 * Test a single phpunit file: `./phpunit-file default extensions/WikibaseMediaInfo/tests/phpunit/unit/WikibaseMediaInfoHooksTest.php `

Local Settings file
``` <?php require_once __DIR__. '/.docker/LocalSettings.php'; wfLoadSkin( 'Vector' ); wfLoadSkin( 'MinervaNeue' );

wfLoadExtension( 'CirrusSearch' ); wfLoadExtension( 'CommonsMetadata' ); wfLoadExtension( 'Elastica' ); wfLoadExtension( 'MachineVision' ); wfLoadExtension( 'MobileFrontend' ); wfLoadExtension( 'MultimediaViewer' ); wfLoadExtension( 'ParserFunctions' ); wfLoadExtension( 'Scribunto' ); wfLoadExtension( 'TemplateData' ); wfLoadExtension( 'TemplateStyles' ); wfLoadExtension( 'UniversalLanguageSelector' ); wfLoadExtension( 'UploadWizard' ); wfLoadExtension( 'WikibaseCirrusSearch' ); wfLoadExtension( 'WikibaseMediaInfo' );

$wgUseInstantCommons = true; $wgEnableUploads = true; $wgUseImageMagick = true; $wgScribuntoDefaultEngine = 'luastandalone'; $wgMediaViewerEnableByDefault = true; $wgPFEnableStringFunctions = true; $wgApiFrameOptions = 'SAMEORIGIN'; $wgParserCacheType = CACHE_NONE; $wgMainCacheType = CACHE_NONE; $wgCacheDirectory = false; $wgDebugLogFile = "/var/log/mediawiki/debug-{$wgDBname}.log";

// CirrusSearch require_once( "$IP/extensions/CirrusSearch/CirrusSearch.php" ); $wgCirrusSearchServers = [ "elasticsearch.svc" ]; $wgSearchType = "CirrusSearch";

// Wikibase $wgEnableWikibaseRepo = true; $wgEnableWikibaseClient = true; require_once "$IP/extensions/Wikibase/repo/Wikibase.php"; require_once "$IP/extensions/Wikibase/repo/ExampleSettings.php"; require_once "$IP/extensions/Wikibase/client/WikibaseClient.php"; require_once "$IP/extensions/Wikibase/client/ExampleSettings.php";

// WikibaseMediaInfo $wgMediaInfoEnableFilePageDepicts = true; $wgMediaInfoEnableOtherStatements = true; $wgMediaInfoShowQualifiers = true; $wgMediaInfoProperties = [ 'depicts' => 'P1', 'coordinate-location' => 'P2' ]; $wgDepictsQualifierProperties = [ 'coordinate-location' => 'P2', 'features' => 'P3' ];

// UploadWizard $wgEnableUploads = true; $wgUseImageMagick = true; $wgUploadWizardConfig[ 'wikibase' ][ 'enabled' ] = true; $wgUploadWizardConfig[ 'wikibase' ][ 'captions' ] = true; $wgUploadWizardConfig[ 'wikibase' ][ 'depicts' ] = true;

// MachineVision require_once "$IP/extensions/MachineVision/vendor/autoload.php"; $wgMachineVisionRequestLabelsOnUploadComplete = true; $wgMachineVisionRequestLabelsFromWikidataPublicApi = true; $wgMachineVisionHandlers['google'] = [ 'class' => 'MediaWiki\\Extension\\MachineVision\\Handler\\GoogleCloudVisionHandler', 'services' => [ 'MachineVisionGoogleImageAnnotatorClient', 'MachineVisionRepository', 'MachineVisionRepoGroup', 'MachineVisionDepictsSetter', 'MachineVisionLabelResolver', ],	'args' => [ // sendFileContents true, // safeSearchLimits [			'adult' => 3, 'medical' => 3, 'violent' => 4, 'racy' => 4, ],	] ]; ```