/**
 * Get the location of the correct version of a MediaWiki CLI
 * entry-point file given the --wiki parameter passed in.
 *
 * This also has some other effects:
 * (a) Sets the $IP global variable (path to MediaWiki)
 * (b) Sets the MW_INSTALL_PATH environmental variable
 * (c) Changes PHP's current directory to the directory of this file.
 *
 * @param $file string File path (relative to MediaWiki dir)
 * @return string Absolute file path with proper MW location
 */
function getMediaWikiCli($file)
{
    global $IP;
    require_once __DIR__ . '/MWMultiVersion.php';
    $multiVersion = MWMultiVersion::getInstance();
    if (!$multiVersion) {
        $multiVersion = MWMultiVersion::initializeForMaintenance();
    }
    if ($multiVersion->getDatabase() === 'testwiki') {
        define('TESTWIKI', 1);
    }
    # Get the MediaWiki version running on this wiki...
    $version = $multiVersion->getVersion();
    # Get the correct MediaWiki path based on this version...
    $IP = dirname(__DIR__) . "/{$version}";
    putenv("MW_INSTALL_PATH={$IP}");
    return "{$IP}/{$file}";
}