Page MenuHomePhabricator

dispatchChanges.php accesses setting that’s not set in default Wikibase config
Closed, ResolvedPublic

Description

As a wiki admin using a more-or-less default Wikibase configuration, I want to run dispatchChanges.php to dispatch changes to client wikis (at least the repo itself).

Problem:
The repo/maintenance/dispatchChanges.php script accesses the repoDatabase setting directly on the client settings:

$clientSettings = WikibaseSettings::getClientSettings();
$repoName = $clientSettings->getSetting( 'repoSiteId' );
$repoDb = $clientSettings->getSetting( 'repoDatabase' );

However, the default configuration does not define any such setting. WikibaseClient.default.php only assigns a repoDatabase inside repositories:

$defaults['repositories'] = function ( SettingsArray $settings ) {
    // XXX: Default to having Items in the main namespace, and properties in NS 120.                                                                                     
    // That is the live setup at wikidata.org, it is NOT consistent with the example settings!                                                                           
    // FIXME: throw an exception, instead of making assumptions that may brak the site in strange ways!                                                                  
    $entityNamespaces = [
        'item' => 0,
        'property' => 120
    ];
    if ( $settings->getSetting( 'thisWikiIsTheRepo' ) ) {
        $entityNamespaces = WikibaseSettings::getRepoSettings()->getSetting( 'entityNamespaces' );
    }

    return [
        '' => [
            // Use false (meaning the local wiki's database) if this wiki is the repo,                                                                                   
            // otherwise default to null (meaning we can't access the repo's DB directly).                                                                               
            'repoDatabase' => $settings->getSetting( 'thisWikiIsTheRepo' ) ? false : null,
            'baseUri' => $settings->getSetting( 'repoUrl' ) . '/entity/',
            'entityNamespaces' => $entityNamespaces,
            'prefixMapping' => [ '' => '' ],
        ]
    ];
};

Example:

$ php extensions/Wikibase/repo/maintenance/dispatchChanges.php 
OutOfBoundsException from line 60 of /var/www/html/wiki1/extensions/Wikibase/lib/includes/SettingsArray.php: Attempt to get non-existing setting "repoDatabase"
#0 /var/www/html/wiki1/extensions/Wikibase/repo/maintenance/dispatchChanges.php(91): Wikibase\SettingsArray->getSetting('repoDatabase')
#1 /var/www/html/wiki1/extensions/Wikibase/repo/maintenance/dispatchChanges.php(245): Wikibase\DispatchChanges->getClientWikis(Array)
#2 /var/www/html/wiki1/maintenance/doMaintenance.php(99): Wikibase\DispatchChanges->execute()
#3 /var/www/html/wiki1/extensions/Wikibase/repo/maintenance/dispatchChanges.php(399): require_once('/var/www/html/w...')
#4 {main}

Workaround:
Add the following to your LocalSettings.php:

$wgWBClientSettings['repoDatabase'] = function ( \Wikibase\SettingsArray $settings ) {
    return $settings->getSetting( 'repositories' )['']['repoDatabase'];
};

This may not do the right thing if you have non-default repositories.

Screenshots/mockups:

BDD
GIVEN
AND
WHEN
AND
THEN
AND

Acceptance criteria:

Open questions: