User:ATomasevich (WMF)/Local Development Tips

The following are local development environment setup instructions and tips somewhat specific to Structured Data.

Setup and basic usage

edit

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.

# Example
git clone ssh://<YOUR_GERRIT_USERNAME>@gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer.git

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

edit

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

edit

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.

Local environment content

edit

Special pages

edit

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

edit

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

Debugging

edit

Xdebug

edit

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

edit

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

edit

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

edit
  • 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

edit
<?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;