Page MenuHomePhabricator

Update.php should allow for a wiki parameter
Closed, DeclinedPublic

Description

If you set up a wiki farm as explained in Manual:$wgConf, the update.php script will stop working for you because when you run it it has no way to know which wiki to update. There are several workarounds you can use, but none of them is simple.

The simplest solution is to allow update.php to accept a parameter called domain, which would then be used by the script to determine which wiki to update. That would simplify the process of updating each wiki in a wiki farm to running something like:

php update.php --domain=SUBDOMAIN.DOMAIN.TLD

This would require modifying the update script to accept and consume the parameter, modifying other pieces of the code to allow for selecting a wiki based on that parameter so the correct config is loaded, and modifying Manual:Update.php to reflect these changes.

Details

Event Timeline

I have found a solution for this.

First, the way a wiki family is configured should be slightly modified. See this change.

The global variable $serverName is by default not set, therefore, in the case of web requests it will be first populated in the LocalSettings.php file based on the requested URL. However, when update.php is executed, the value for $serverName would be set through a parameter. For instance if the call is made like:

php update.php --domain=en.wikipedia.org

Then the value for $serverName will be set to "en.wikipedia.org". So by the time the code gets to LocalSettings.php it already knows which server to use.

That would notably simplify updating wiki families. I will try to solicit feedback about this approach, particularly about what the global variable should be named. I will also submit a patch for update.php that would allow setting it through a CLI parameter.

Change 316288 had a related patch set uploaded (by Huji):
Update.php should allow for a wiki parameter

https://gerrit.wikimedia.org/r/316288

Not all wiki families are separated by domain; some use paths instead and this pattern will break for that.

This is also not necessary.

All maintenance scripts (including update.php) already accept a --wiki parameter that set MW_DB and MW_PREFIX constants. You just use MW_DB in your LocalSettings.php whenever it is set to decide which wiki, instead of whatever servername/path checking you normally dy.

@DanielFriesen can you please show me how that can be done? I could never get it to work using the stadnard wfConf-based wiki families.

Actually, disregard. It turns out as long as you have separate LocalSettings_**.php files for each wiki, you can use the --conf parameter to get the same result I was looking for. This means my suggestion here is unnecessary. Marking is declined.

Change 316288 abandoned by Huji:
Update.php should allow for a wiki parameter

Reason:
See T147817; this is unnecessary.

https://gerrit.wikimedia.org/r/316288

I'm not sure how $wgConf works.

In normal code it might be something like if ( defined('MW_DB') ? MW_DB === 'foowiki' : $_SERVER['SERVER_NAME'] === 'foo.mywiki.com' )

@DanielFriesen can you please show me how that can be done? I could never get it to work using the stadnard wfConf-based wiki families.

If you're using something based on https://www.mediawiki.org/wiki/Manual:$wgConf#Example, it's all in the setting of $wgDBname. You might do it like this:

if ( defined( MW_DB ) && MW_DB ) {
    // add validation to suit your environment
    $wgDBname = MW_DB;
    $wgDBprefix = MW_PREFIX;
} else {
    /* Whatever existing code you have to set $wgDBname and $wgDBprefix */
}

This may be unusual, but for a wiki farm that I maintain, we vary based on REQUEST_URI since everything lives at wiki.example.com/{foo,bar,baz}. LocalSettings.php has for example:

$wikiPath = $_SERVER["REQUEST_URI"];
if (preg_match("#^/library#", $wikiPath) === 1) {
    $wgScriptPath = "/library";
    $wgSitename = "LibraryWiki";
    $wgDBprefix = "lib_";

There's a very stupid/simple wrapper PHP script that just passes REQUEST_URI explicitly as it iterates through an array of the wikis:

foreach ($wikis as $wiki) {
    echo "Updating the " . $wiki . " wiki now...\n";
    echo shell_exec("REQUEST_URI='/" . $wiki . "' php /var/www/wikis/w/maintenance/update.php --quick");
}

You might find something similar helpful.

@MZMcBride would the EXPORT method work for you?

Yeah, that's essentially what I'm doing. I'm not sure why we're shouting "export" in the documentation.