/** * 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}"; }
} if (PHP_SAPI == 'cli') { # Override for sanity's sake. ini_set('display_errors', 1); } if (isset($_SERVER['SERVER_ADDR'])) { ini_set('error_append_string', ' (' . $_SERVER['SERVER_ADDR'] . ')'); } # ---------------------------------------------------------------------- # Initialisation # Get the version object for this Wiki (must be set by now, along with $IP) if (!class_exists('MWMultiVersion')) { print "No MWMultiVersion instance initialized! MWScript.php wrapper not used?\n"; exit(1); } $multiVersion = MWMultiVersion::getInstance(); set_include_path("{$IP}:/usr/local/lib/php:/usr/share/php"); ### List of some service hostnames # 'meta' : meta wiki for user editable content # 'upload' : hostname where files are hosted # 'wikidata': hostname for the data repository # 'bits' : for load.php and js/css assets # Whenever all realms/datacenters should use the same host, do not use # $wmfHostnames but use the hardcoded hostname instead. A good example are the # spam blacklists hosted on meta.wikimedia.org which you will surely want to # reuse. $wmfHostnames = array(); switch ($wmfRealm) { case 'labs': $wmfHostnames['bits'] = 'bits.beta.wmflabs.org'; $wmfHostnames['meta'] = 'meta.wikimedia.beta.wmflabs.org';
/** * Destroy the singleton instance to let a subsequent call create a new * one. This should NEVER be used on non CLI interface, that will throw an * internal error. */ public static function destroySingleton() { if (PHP_SAPI !== 'cli') { self::error('Can not destroy singleton instance when used ' . 'with non-CLI interface'); } self::$instance = null; }