Jump to content

User:BPirkle (WMF)/Stuff/Local Dev/MwCli

From Meta, a Wikimedia project coordination wiki

Overview

[edit]

As of 2021-12-13, I'm still working out the details on this one. Most of it so far is a fairly standard mwcli install. Relevant info here:

https://addshore.com/2021/11/mediawiki-docker-dev-in-mwcli/
https://gitlab.wikimedia.org/repos/releng/cli/-/releases
https://www.mediawiki.org/wiki/Cli

This gave me a working instance at: http://default.mediawiki.mwdd.localhost:8080/w/index.php?title=Main_Page

With phpmyadmin available at: http://phpmyadmin.mwdd.localhost:8080/

Pywikibot

[edit]

The first thing I'm doing with this install is playing around with manipulating it via Pywikibot. As of this writing, I haven't gotten very far, but I have managed to get pywikibot to log in. My config looks like this:

user-config.py:

mylang = 'en'
family = 'mwcli'
usernames['mwcli']['en'] = 'admin'

pywikibot/families/mwcli_family.py:

from pywikibot import family

# for local mw-cli dev wiki

class Family(family.Family):
    name = 'mwcli'
    langs = {
        'en': 'default.mediawiki.mwdd.localhost:8080/',
    }

/etc/hosts

I also found it necessary to add this to my /etc/hosts file (I'm on mac, FWIW).

127.0.0.1 proxy.mwdd.localhost
127.0.0.1 eventlogging.mwdd.localhost
127.0.0.1 adminer.mwdd.localhost
127.0.0.1 mailhog.mwdd.localhost
127.0.0.1 graphite.mwdd.localhost
127.0.0.1 phpmyadmin.mwdd.localhost
127.0.0.1 default.mediawiki.mwdd.localhost

I could load mwcli pages in the browser okay without those lines added, but pywikibot wouldn't connect to my local wiki.

Scripts

And then to log in, I do (from the command line, in my pywikibot/core directory):

python3 pwb.py login.py

XDebug

[edit]

(What follows is a cut-and-paste from Slack. Maybe I'll make it more presentable later, but for now I just wanted to preserve the info.)

Got xdebug working on mwcli. The critical setting of interest (as suggested at https://www.mediawiki.org/wiki/Cli/guide/Docker-Development-Environment#Using_XDebug_for_MediaWiki) was the client host.

The docs I linked above suggested I could do something like mw docker env set MEDIAWIKI_XDEBUG_CONFIG "client_host=192.168.50.238" to set that, but for whatever reason that didn't work for me, even after suspending and resuming the container. Maybe destroying and recreating it would have worked? (Update: I tried again a few months later, and this command worked without doing the things below.)

Instead, I opened a terminal into the container with mw docker mediawiki exec --user root -- bash and then added the line xdebug.client_host=192.168.50.238 to the file /etc/php/7.3/fpm/conf.d/20-xdebug.ini

Then I tried to restart php-fpm via service restart php7.3-fpm, but because php-fpm was the master service for the container, that shut down the container. So I restarted it with mw docker mediawiki resume

Because that IP is specific to the current configuration of my local network, I'll have to update it if I'm working from somewhere else, or even just if my router assigns me a different IP.

One more trick: if you're not sure what settings are actually being applied, you can add phpinfo() to your index.php file, just above the wfIndexMain(); call and it'll dump all the php settings to the output of your wiki pages. It'll be super ugly, but who else is looking at your local, right? Search for "xdebug" and you can see what settings your wiki is running with.

Wiki Farm

[edit]

mwcli makes it very very easy to create multiple wikis. Here's the command I ran to create a second wiki in my mwcli installation:

mw docker mediawiki install --dbtype=mysql --dbname=wiki2

I copied my LocalSettings.php file out in case mwcli messed with it, but it didn't. Probably still a good idea in case that ever changes.

Here's what I put in my LocalSettings.php to get different logos for each wiki, so I could easily tell my wikis apart at a glance:

if ( $wgSitename == 'mwdd-wiki2' ) {
	$wgLogos = [
		'1x' => "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Wikipedia_logo_v2_with_text_%28black%29.svg/209px-Wikipedia_logo_v2_with_text_%28black%29.svg.png",
		'icon' => "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Wikipedia_logo_v2_with_text_%28black%29.svg/209px-Wikipedia_logo_v2_with_text_%28black%29.svg.png"
	];
} else {
	$wgLogos = [
		'1x' => "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Wikipedia-logo-v2-en.svg/209px-Wikipedia-logo-v2-en.svg.png",
		'icon' => "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Wikipedia-logo-v2-en.svg/209px-Wikipedia-logo-v2-en.svg.png",
	];
}