function provideSymlinkPathAndTarget()
 {
     $stage_dir = __DIR__ . '/../..';
     $paths = array();
     $jsonPath = getRealmSpecificFilename("{$stage_dir}/wikiversions.json");
     $versionRows = MWWikiversions::readWikiVersionsFile($jsonPath);
     $activeVersions = array();
     $versions = array();
     foreach ($versionRows as $dbName => $version) {
         if (!isset($activeVersions[$version])) {
             // already listed?
             $activeVersions[$version] = 1;
             $version = substr($version, 4);
             // remove 'php-'
             $versions[] = $version;
         }
     }
     foreach ($versions as $version) {
         foreach (array('extensions', 'skins', 'resources') as $link) {
             $path = "{$stage_dir}/w/static/{$version}/{$link}";
             $target = MEDIAWIKI_DEPLOYMENT_DIR . "/php-{$version}/{$link}";
             $paths[] = array($path, $target);
         }
     }
     return $paths;
 }
function wmfImportSources(&$sources)
{
    global $wgConf, $IP, $lang;
    $wikipedias = array_flip(MWWikiversions::readDbListFile(getRealmSpecificFilename("{$IP}/../wikipedia.dblist")));
    $privates = array_flip(MWWikiversions::readDbListFile(getRealmSpecificFilename("{$IP}/../private.dblist")));
    // REMEMBER when editing this function, the values here are *interwiki prefixes*.
    // Sometimes the interwiki map does things you don't expect.
    // Look at dumpInterwiki.php in WikimediaMaintenance for guidance.
    // Enforce a sensible order
    $sources = array('meta', 'commons', 'incubator', 'wikipedia' => array(), 'wiktionary' => array(), 'wikibooks' => array(), 'wikinews' => array(), 'wikiquote' => array(), 'wikisource' => array('oldwikisource'), 'wikiversity' => array('betawikiversity'), 'wikivoyage' => array(), 'chapter' => array(), 'foundation', 'mediawikiwiki', 'nostalgia', 'outreach', 'strategy', 'tenwiki', 'testwiki', 'test2wiki', 'testwikidata', 'usability', 'wikidata', 'wikispecies', 'wikitech', 'wmania' => array('wm2005', 'wm2006', 'wm2007', 'wm2008', 'wm2009', 'wm2010', 'wm2011', 'wm2012', 'wm2013', 'wm2014', 'wm2015', 'wm2016'));
    // Add all regular language projects as import sources
    foreach ($wgConf->getLocalDatabases() as $dbname) {
        // No importing from private wikis
        if (isset($privates[$dbname])) {
            continue;
        }
        list($project, $subdomain) = $wgConf->siteFromDB($dbname);
        if ($project === 'wikimedia') {
            $sources['chapter'][] = $subdomain;
        } elseif ($subdomain === 'en' || $subdomain === $lang) {
            // Put $lang and en at the top for convenience
            array_unshift($sources[$project], $subdomain);
        } elseif (($project !== 'wikipedia' || isset($wikipedias[$dbname])) && $subdomain !== 'beta') {
            $sources[$project][] = $subdomain;
        }
    }
}
/**
 * Prints the MW version associated with a specified wikidb (as listed e.g. in all.dblist).
 * @param $dbName string
 * @return string MW code version (e.g. "php-x.xx" or "php-trunk")
 */
function getWikiVersion($dbName)
{
    $phpFilename = getRealmSpecificFilename(MEDIAWIKI_DEPLOYMENT_DIR . '/wikiversions.php');
    $wikiversions = (include $phpFilename);
    if (!is_array($wikiversions)) {
        print "Unable to open {$phpFilename}.\n";
        exit(1);
    }
    if (empty($wikiversions[$dbName])) {
        print "{$cdbFilename} has no version entry for `{$dbName}`.\n";
        exit(1);
    }
    return $wikiversions[$dbName];
}
 function loadDbFile($realm, $datacenter)
 {
     global $wmfRealm, $wmfDatacenter;
     list($oldRealm, $oldDatacenter) = array($wmfRealm, $wmfDatacenter);
     list($wmfRealm, $wmfDatacenter) = array($realm, $datacenter);
     # "properly" load db.php in local context:
     $wgDBname = 'testwiki';
     $wgDBuser = '******';
     $wgDBpassword = '******';
     if (!defined('DBO_DEFAULT')) {
         define('DBO_DEFAULT', 16);
     }
     include getRealmSpecificFilename(__DIR__ . '/../wmf-config/db.php');
     list($wmfRealm, $wmfDatacenter) = array($oldRealm, $oldDatacenter);
     return $wgLBFactoryConf;
 }
function updateWikiversions()
{
    global $argv;
    $common = MEDIAWIKI_STAGING_DIR;
    $jsonPath = getRealmSpecificFilename(MEDIAWIKI_STAGING_DIR . '/wikiversions.json');
    if (count($argv) !== 3) {
        print "Usage: updateWikiversions <name>.dblist php-X.XX-wmf.X\n";
        exit(1);
    }
    $dbListName = basename($argv[1], '.dblist');
    $dbList = MWWikiversions::readDbListFile($dbListName);
    $newVersion = $argv[2];
    if (!preg_match(MEDIAWIKI_DIRECTORY_REGEX, $newVersion) || !is_dir("{$common}/{$newVersion}")) {
        print "Invalid version specifier: {$newVersion}\n";
        exit(1);
    }
    if (file_exists($jsonPath)) {
        $versionRows = MWWikiversions::readWikiVersionsFile($jsonPath);
    } else {
        if ($dbListName !== 'all') {
            echo "No {$jsonPath} file and not invoked with 'all'. Cowardly refusing to act.\n";
            exit(1);
        }
        echo "{$jsonPath} not found -- rebuilding from scratch!\n";
        $versionRows = array();
    }
    $inserted = 0;
    $migrated = 0;
    foreach ($dbList as $dbName) {
        if (!isset($versionRows[$dbName])) {
            $inserted++;
        } else {
            $migrated++;
        }
        $versionRows[$dbName] = $newVersion;
    }
    $total = count($versionRows);
    ksort($versionRows);
    MWWikiversions::writeWikiVersionsFile($jsonPath, $versionRows);
    echo "Updated {$jsonPath}: {$inserted} inserted, {$migrated} migrated.\n";
}
function getActiveWikiVersions()
{
    global $argv;
    $options = str_replace('--home', '--staging', $argv);
    // accept '--home' as an alias for '--staging', for back-compat.
    array_shift($options);
    // first item is this file
    if (in_array('--staging', $options)) {
        $jsonPath = getRealmSpecificFilename(MEDIAWIKI_STAGING_DIR . '/wikiversions.json');
    } else {
        $jsonPath = getRealmSpecificFilename(MEDIAWIKI_DEPLOYMENT_DIR . '/wikiversions.json');
    }
    # Get all the wikiversion rows in wikiversions.json...
    try {
        $versionRows = MWWikiversions::readWikiVersionsFile($jsonPath);
    } catch (Exception $e) {
        if (in_array('--report', $options)) {
            throw $e;
            // show error
        } else {
            die(1);
            // silent death
        }
    }
    $result = $activeVersions = array();
    foreach ($versionRows as $dbName => $version) {
        if (!isset($activeVersions[$version])) {
            // already listed?
            $activeVersions[$version] = 1;
            $version = substr($version, 4);
            // remove 'php-'
            if (in_array('--withdb', $options)) {
                $result[] = "{$version}={$dbName}";
            } else {
                $result[] = "{$version}";
            }
        }
    }
    return $result;
}
 /**
  * @dataProvider provideFilenames
  */
 function testRealmFilenames($expected, $filename, $realm = null, $datacenter = null)
 {
     global $wmfRealm, $wmfDatacenter;
     // save globals
     $old['realm'] = $wmfRealm;
     $old['datacenter'] = $wmfDatacenter;
     if ($realm !== null) {
         $wmfRealm = $realm;
     }
     if ($datacenter !== null) {
         $wmfDatacenter = $datacenter;
     }
     # The function requires a real path:
     $basePath = self::$fixturesDir . "/";
     $specific = getRealmSpecificFilename($basePath . $filename);
     # Which we strip before comparaison
     $specific = str_replace($basePath, '', $specific);
     $this->assertEquals($expected, $specific);
     // restore globals
     $wmfRealm = $old['realm'];
     $wmfDatacenter = $old['datacenter'];
 }