]> scripts.mit.edu Git - autoinstalls/mediawiki.git/commitdiff
MediaWiki 1.17.0-scripts mediawiki-1.17.0-scripts
authorEdward Z. Yang <ezyang@mit.edu>
Sat, 25 Jun 2011 23:15:20 +0000 (19:15 -0400)
committerEdward Z. Yang <ezyang@mit.edu>
Sun, 31 Jul 2011 04:54:28 +0000 (00:54 -0400)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
1  2 
includes/installer/Installer.php
includes/installer/WebInstaller.php

index 0000000000000000000000000000000000000000,6da4f1005b107e9d1b384bcaf3fccf875fe91bb3..993aeab4cd078fdcb664886f0a350f209ff7b6ac
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,1511 +1,1492 @@@
 -
+ <?php
+ /**
+  * Base code for MediaWiki installer.
+  *
+  * @file
+  * @ingroup Deployment
+  */
+ /**
+  * This documentation group collects source code files with deployment functionality.
+  *
+  * @defgroup Deployment Deployment
+  */
+ /**
+  * Base installer class.
+  *
+  * This class provides the base for installation and update functionality
+  * for both MediaWiki core and extensions.
+  *
+  * @ingroup Deployment
+  * @since 1.17
+  */
+ abstract class Installer {
+       // This is the absolute minimum PHP version we can support
+       const MINIMUM_PHP_VERSION = '5.2.3';
+       /**
+        * @var array
+        */
+       protected $settings;
+       /**
+        * Cached DB installer instances, access using getDBInstaller().
+        *
+        * @var array
+        */
+       protected $dbInstallers = array();
+       /**
+        * Minimum memory size in MB.
+        *
+        * @var integer
+        */
+       protected $minMemorySize = 50;
+       /**
+        * Cached Title, used by parse().
+        *
+        * @var Title
+        */
+       protected $parserTitle;
+       /**
+        * Cached ParserOptions, used by parse().
+        *
+        * @var ParserOptions
+        */
+       protected $parserOptions;
+       /**
+        * Known database types. These correspond to the class names <type>Installer,
+        * and are also MediaWiki database types valid for $wgDBtype.
+        *
+        * To add a new type, create a <type>Installer class and a Database<type>
+        * class, and add a config-type-<type> message to MessagesEn.php.
+        *
+        * @var array
+        */
+       protected static $dbTypes = array(
+               'mysql',
+               'postgres',
+               'oracle',
+               'sqlite',
+       );
+       /**
+        * A list of environment check methods called by doEnvironmentChecks().
+        * These may output warnings using showMessage(), and/or abort the
+        * installation process by returning false.
+        *
+        * @var array
+        */
+       protected $envChecks = array(
+               'envCheckDB',
+               'envCheckRegisterGlobals',
+               'envCheckBrokenXML',
+               'envCheckPHP531',
+               'envCheckMagicQuotes',
+               'envCheckMagicSybase',
+               'envCheckMbstring',
+               'envCheckZE1',
+               'envCheckSafeMode',
+               'envCheckXML',
+               'envCheckPCRE',
+               'envCheckMemory',
+               'envCheckCache',
+               'envCheckDiff3',
+               'envCheckGraphics',
+               'envCheckPath',
+               'envCheckExtension',
+               'envCheckShellLocale',
+               'envCheckUploadsDirectory',
+               'envCheckLibicu',
+               'envCheckSuhosinMaxValueLength',
+       );
+       /**
+        * MediaWiki configuration globals that will eventually be passed through
+        * to LocalSettings.php. The names only are given here, the defaults
+        * typically come from DefaultSettings.php.
+        *
+        * @var array
+        */
+       protected $defaultVarNames = array(
+               'wgSitename',
+               'wgPasswordSender',
+               'wgLanguageCode',
+               'wgRightsIcon',
+               'wgRightsText',
+               'wgRightsUrl',
+               'wgMainCacheType',
+               'wgEnableEmail',
+               'wgEnableUserEmail',
+               'wgEnotifUserTalk',
+               'wgEnotifWatchlist',
+               'wgEmailAuthentication',
+               'wgDBtype',
+               'wgDiff3',
+               'wgImageMagickConvertCommand',
+               'IP',
+               'wgScriptPath',
+               'wgScriptExtension',
+               'wgMetaNamespace',
+               'wgDeletedDirectory',
+               'wgEnableUploads',
+               'wgLogo',
+               'wgShellLocale',
+               'wgSecretKey',
+               'wgUseInstantCommons',
+               'wgUpgradeKey',
+               'wgDefaultSkin',
+               'wgResourceLoaderMaxQueryLength',
+       );
+       /**
+        * Variables that are stored alongside globals, and are used for any
+        * configuration of the installation process aside from the MediaWiki
+        * configuration. Map of names to defaults.
+        *
+        * @var array
+        */
+       protected $internalDefaults = array(
+               '_UserLang' => 'en',
+               '_Environment' => false,
+               '_CompiledDBs' => array(),
+               '_SafeMode' => false,
+               '_RaiseMemory' => false,
+               '_UpgradeDone' => false,
+               '_InstallDone' => false,
+               '_Caches' => array(),
+               '_InstallPassword' => '',
+               '_SameAccount' => true,
+               '_CreateDBAccount' => false,
+               '_NamespaceType' => 'site-name',
+               '_AdminName' => '', // will be set later, when the user selects language
+               '_AdminPassword' => '',
+               '_AdminPassword2' => '',
+               '_AdminEmail' => '',
+               '_Subscribe' => false,
+               '_SkipOptional' => 'continue',
+               '_RightsProfile' => 'wiki',
+               '_LicenseCode' => 'none',
+               '_CCDone' => false,
+               '_Extensions' => array(),
+               '_MemCachedServers' => '',
+               '_UpgradeKeySupplied' => false,
+               '_ExistingDBSettings' => false,
+       );
+       /**
+        * The actual list of installation steps. This will be initialized by getInstallSteps()
+        *
+        * @var array
+        */
+       private $installSteps = array();
+       /**
+        * Extra steps for installation, for things like DatabaseInstallers to modify
+        *
+        * @var array
+        */
+       protected $extraInstallSteps = array();
+       /**
+        * Known object cache types and the functions used to test for their existence.
+        *
+        * @var array
+        */
+       protected $objectCaches = array(
+               'xcache' => 'xcache_get',
+               'apc' => 'apc_fetch',
+               'eaccel' => 'eaccelerator_get',
+               'wincache' => 'wincache_ucache_get'
+       );
+       /**
+        * User rights profiles.
+        *
+        * @var array
+        */
+       public $rightsProfiles = array(
+               'wiki' => array(),
+               'no-anon' => array(
+                       '*' => array( 'edit' => false )
+               ),
+               'fishbowl' => array(
+                       '*' => array(
+                               'createaccount' => false,
+                               'edit' => false,
+                       ),
+               ),
+               'private' => array(
+                       '*' => array(
+                               'createaccount' => false,
+                               'edit' => false,
+                               'read' => false,
+                       ),
+               ),
+       );
+       /**
+        * License types.
+        *
+        * @var array
+        */
+       public $licenses = array(
+               'cc-by-sa' => array(
+                       'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
+                       'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
+               ),
+               'cc-by-nc-sa' => array(
+                       'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
+                       'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
+               ),
+               'cc-0' => array(
+                       'url' => 'https://creativecommons.org/publicdomain/zero/1.0/',
+                       'icon' => '{$wgStylePath}/common/images/cc-0.png',
+               ),
+               'pd' => array(
+                       'url' => 'http://creativecommons.org/licenses/publicdomain/',
+                       'icon' => '{$wgStylePath}/common/images/public-domain.png',
+               ),
+               'gfdl-old' => array(
+                       'url' => 'http://www.gnu.org/licenses/old-licenses/fdl-1.2.html',
+                       'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
+               ),
+               'gfdl-current' => array(
+                       'url' => 'http://www.gnu.org/copyleft/fdl.html',
+                       'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
+               ),
+               'none' => array(
+                       'url' => '',
+                       'icon' => '',
+                       'text' => ''
+               ),
+               'cc-choose' => array(
+                       // Details will be filled in by the selector.
+                       'url' => '',
+                       'icon' => '',
+                       'text' => '',
+               ),
+       );
+       /**
+        * URL to mediawiki-announce subscription
+        */
+       protected $mediaWikiAnnounceUrl = 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce';
+       /**
+        * Supported language codes for Mailman
+        */
+       protected $mediaWikiAnnounceLanguages = array(
+               'ca', 'cs', 'da', 'de', 'en', 'es', 'et', 'eu', 'fi', 'fr', 'hr', 'hu',
+               'it', 'ja', 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru',
+               'sl', 'sr', 'sv', 'tr', 'uk'
+       );
+       /**
+        * UI interface for displaying a short message
+        * The parameters are like parameters to wfMsg().
+        * The messages will be in wikitext format, which will be converted to an
+        * output format such as HTML or text before being sent to the user.
+        */
+       public abstract function showMessage( $msg /*, ... */ );
+       /**
+        * Same as showMessage(), but for displaying errors
+        */
+       public abstract function showError( $msg /*, ... */ );
+       /**
+        * Show a message to the installing user by using a Status object
+        * @param $status Status
+        */
+       public abstract function showStatusMessage( Status $status );
+       /**
+        * Constructor, always call this from child classes.
+        */
+       public function __construct() {
+               global $wgExtensionMessagesFiles, $wgUser, $wgHooks;
+               // Disable the i18n cache and LoadBalancer
+               Language::getLocalisationCache()->disableBackend();
+               LBFactory::disableBackend();
+               // Load the installer's i18n file.
+               $wgExtensionMessagesFiles['MediawikiInstaller'] =
+                       dirname( __FILE__ ) . '/Installer.i18n.php';
+               // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
+               $wgUser = User::newFromId( 0 );
+               $this->settings = $this->internalDefaults;
+               foreach ( $this->defaultVarNames as $var ) {
+                       $this->settings[$var] = $GLOBALS[$var];
+               }
+               foreach ( self::getDBTypes() as $type ) {
+                       $installer = $this->getDBInstaller( $type );
+                       if ( !$installer->isCompiled() ) {
+                               continue;
+                       }
+                       $defaults = $installer->getGlobalDefaults();
+                       foreach ( $installer->getGlobalNames() as $var ) {
+                               if ( isset( $defaults[$var] ) ) {
+                                       $this->settings[$var] = $defaults[$var];
+                               } else {
+                                       $this->settings[$var] = $GLOBALS[$var];
+                               }
+                       }
+               }
+               $this->parserTitle = Title::newFromText( 'Installer' );
+               $this->parserOptions = new ParserOptions; // language will  be wrong :(
+               $this->parserOptions->setEditSection( false );
+       }
+       /**
+        * Get a list of known DB types.
+        */
+       public static function getDBTypes() {
+               return self::$dbTypes;
+       }
+       /**
+        * Do initial checks of the PHP environment. Set variables according to
+        * the observed environment.
+        *
+        * It's possible that this may be called under the CLI SAPI, not the SAPI
+        * that the wiki will primarily run under. In that case, the subclass should
+        * initialise variables such as wgScriptPath, before calling this function.
+        *
+        * Under the web subclass, it can already be assumed that PHP 5+ is in use
+        * and that sessions are working.
+        *
+        * @return Status
+        */
+       public function doEnvironmentChecks() {
+               $phpVersion = phpversion();
+               if( version_compare( $phpVersion, self::MINIMUM_PHP_VERSION, '>=' ) ) {
+                       $this->showMessage( 'config-env-php', $phpVersion );
+                       $good = true;
+               } else {
+                       $this->showMessage( 'config-env-php-toolow', $phpVersion, self::MINIMUM_PHP_VERSION );
+                       $good = false;
+               }
+               if( $good ) {
+                       foreach ( $this->envChecks as $check ) {
+                               $status = $this->$check();
+                               if ( $status === false ) {
+                                       $good = false;
+                               }
+                       }
+               }
+               $this->setVar( '_Environment', $good );
+               return $good ? Status::newGood() : Status::newFatal( 'config-env-bad' );
+       }
+       /**
+        * Set a MW configuration variable, or internal installer configuration variable.
+        *
+        * @param $name String
+        * @param $value Mixed
+        */
+       public function setVar( $name, $value ) {
+               $this->settings[$name] = $value;
+       }
+       /**
+        * Get an MW configuration variable, or internal installer configuration variable.
+        * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
+        * Installer variables are typically prefixed by an underscore.
+        *
+        * @param $name String
+        * @param $default Mixed
+        *
+        * @return mixed
+        */
+       public function getVar( $name, $default = null ) {
+               if ( !isset( $this->settings[$name] ) ) {
+                       return $default;
+               } else {
+                       return $this->settings[$name];
+               }
+       }
+       /**
+        * Get an instance of DatabaseInstaller for the specified DB type.
+        *
+        * @param $type Mixed: DB installer for which is needed, false to use default.
+        *
+        * @return DatabaseInstaller
+        */
+       public function getDBInstaller( $type = false ) {
+               if ( !$type ) {
+                       $type = $this->getVar( 'wgDBtype' );
+               }
+               $type = strtolower( $type );
+               if ( !isset( $this->dbInstallers[$type] ) ) {
+                       $class = ucfirst( $type ). 'Installer';
+                       $this->dbInstallers[$type] = new $class( $this );
+               }
+               return $this->dbInstallers[$type];
+       }
+       /**
+        * Determine if LocalSettings.php exists. If it does, return its variables,
+        * merged with those from AdminSettings.php, as an array.
+        *
+        * @return Array
+        */
+       public static function getExistingLocalSettings() {
+               global $IP;
+               wfSuppressWarnings();
+               $_lsExists = file_exists( "$IP/LocalSettings.php" );
+               wfRestoreWarnings();
+               if( !$_lsExists ) {
+                       return false;
+               }
+               unset($_lsExists);
+               require( "$IP/includes/DefaultSettings.php" );
+               require( "$IP/LocalSettings.php" );
+               if ( file_exists( "$IP/AdminSettings.php" ) ) {
+                       require( "$IP/AdminSettings.php" );
+               }
+               return get_defined_vars();
+       }
+       /**
+        * Get a fake password for sending back to the user in HTML.
+        * This is a security mechanism to avoid compromise of the password in the
+        * event of session ID compromise.
+        *
+        * @param $realPassword String
+        *
+        * @return string
+        */
+       public function getFakePassword( $realPassword ) {
+               return str_repeat( '*', strlen( $realPassword ) );
+       }
+       /**
+        * Set a variable which stores a password, except if the new value is a
+        * fake password in which case leave it as it is.
+        *
+        * @param $name String
+        * @param $value Mixed
+        */
+       public function setPassword( $name, $value ) {
+               if ( !preg_match( '/^\*+$/', $value ) ) {
+                       $this->setVar( $name, $value );
+               }
+       }
+       /**
+        * On POSIX systems return the primary group of the webserver we're running under.
+        * On other systems just returns null.
+        *
+        * This is used to advice the user that he should chgrp his mw-config/data/images directory as the
+        * webserver user before he can install.
+        *
+        * Public because SqliteInstaller needs it, and doesn't subclass Installer.
+        *
+        * @return mixed
+        */
+       public static function maybeGetWebserverPrimaryGroup() {
+               if ( !function_exists( 'posix_getegid' ) || !function_exists( 'posix_getpwuid' ) ) {
+                       # I don't know this, this isn't UNIX.
+                       return null;
+               }
+               # posix_getegid() *not* getmygid() because we want the group of the webserver,
+               # not whoever owns the current script.
+               $gid = posix_getegid();
+               $getpwuid = posix_getpwuid( $gid );
+               $group = $getpwuid['name'];
+               return $group;
+       }
+       /**
+        * Convert wikitext $text to HTML.
+        *
+        * This is potentially error prone since many parser features require a complete
+        * installed MW database. The solution is to just not use those features when you
+        * write your messages. This appears to work well enough. Basic formatting and
+        * external links work just fine.
+        *
+        * But in case a translator decides to throw in a #ifexist or internal link or
+        * whatever, this function is guarded to catch the attempted DB access and to present
+        * some fallback text.
+        *
+        * @param $text String
+        * @param $lineStart Boolean
+        * @return String
+        */
+       public function parse( $text, $lineStart = false ) {
+               global $wgParser;
+               try {
+                       $out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart );
+                       $html = $out->getText();
+               } catch ( DBAccessError $e ) {
+                       $html = '<!--DB access attempted during parse-->  ' . htmlspecialchars( $text );
+                       if ( !empty( $this->debug ) ) {
+                               $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
+                       }
+               }
+               return $html;
+       }
+       public function getParserOptions() {
+               return $this->parserOptions;
+       }
+       public function disableLinkPopups() {
+               $this->parserOptions->setExternalLinkTarget( false );
+       }
+       public function restoreLinkPopups() {
+               global $wgExternalLinkTarget;
+               $this->parserOptions->setExternalLinkTarget( $wgExternalLinkTarget );
+       }
+       /**
+        * Install step which adds a row to the site_stats table with appropriate
+        * initial values.
+        */
+       public function populateSiteStats( DatabaseInstaller $installer ) {
+               $status = $installer->getConnection();
+               if ( !$status->isOK() ) {
+                       return $status;
+               }
+               $status->value->insert( 'site_stats', array(
+                       'ss_row_id' => 1,
+                       'ss_total_views' => 0,
+                       'ss_total_edits' => 0,
+                       'ss_good_articles' => 0,
+                       'ss_total_pages' => 0,
+                       'ss_users' => 0,
+                       'ss_admins' => 0,
+                       'ss_images' => 0 ),
+                       __METHOD__, 'IGNORE' );
+               return Status::newGood();
+       }
+       /**
+        * Exports all wg* variables stored by the installer into global scope.
+        */
+       public function exportVars() {
+               foreach ( $this->settings as $name => $value ) {
+                       if ( substr( $name, 0, 2 ) == 'wg' ) {
+                               $GLOBALS[$name] = $value;
+                       }
+               }
+       }
+       /**
+        * Environment check for DB types.
+        */
+       protected function envCheckDB() {
+               global $wgLang;
+               $compiledDBs = array();
+               $allNames = array();
+               foreach ( self::getDBTypes() as $name ) {
+                       $db = $this->getDBInstaller( $name );
+                       $readableName = wfMsg( 'config-type-' . $name );
+                       if ( $db->isCompiled() ) {
+                               $compiledDBs[] = $name;
+                       }
+                       $allNames[] = $readableName;
+               }
+               $this->setVar( '_CompiledDBs', $compiledDBs );
+               if ( !$compiledDBs ) {
+                       $this->showError( 'config-no-db', $wgLang->commaList( $allNames ) );
+                       // FIXME: this only works for the web installer!
+                       return false;
+               }
+               // Check for FTS3 full-text search module
+               $sqlite = $this->getDBInstaller( 'sqlite' );
+               if ( $sqlite->isCompiled() ) {
+                       if( DatabaseSqlite::getFulltextSearchModule() != 'FTS3' ) {
+                               $this->showMessage( 'config-no-fts3' );
+                       }
+               }
+       }
+       /**
+        * Environment check for register_globals.
+        */
+       protected function envCheckRegisterGlobals() {
+               if( wfIniGetBool( "magic_quotes_runtime" ) ) {
+                       $this->showMessage( 'config-register-globals' );
+               }
+       }
+       /**
+        * Some versions of libxml+PHP break < and > encoding horribly
+        */
+       protected function envCheckBrokenXML() {
+               $test = new PhpXmlBugTester();
+               if ( !$test->ok ) {
+                       $this->showError( 'config-brokenlibxml' );
+                       return false;
+               }
+       }
+       /**
+        * Test PHP (probably 5.3.1, but it could regress again) to make sure that
+        * reference parameters to __call() are not converted to null
+        */
+       protected function envCheckPHP531() {
+               $test = new PhpRefCallBugTester;
+               $test->execute();
+               if ( !$test->ok ) {
+                       $this->showError( 'config-using531', phpversion() );
+                       return false;
+               }
+       }
+       /**
+        * Environment check for magic_quotes_runtime.
+        */
+       protected function envCheckMagicQuotes() {
+               if( wfIniGetBool( "magic_quotes_runtime" ) ) {
+                       $this->showError( 'config-magic-quotes-runtime' );
+                       return false;
+               }
+       }
+       /**
+        * Environment check for magic_quotes_sybase.
+        */
+       protected function envCheckMagicSybase() {
+               if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
+                       $this->showError( 'config-magic-quotes-sybase' );
+                       return false;
+               }
+       }
+       /**
+        * Environment check for mbstring.func_overload.
+        */
+       protected function envCheckMbstring() {
+               if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
+                       $this->showError( 'config-mbstring' );
+                       return false;
+               }
+       }
+       /**
+        * Environment check for zend.ze1_compatibility_mode.
+        */
+       protected function envCheckZE1() {
+               if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
+                       $this->showError( 'config-ze1' );
+                       return false;
+               }
+       }
+       /**
+        * Environment check for safe_mode.
+        */
+       protected function envCheckSafeMode() {
+               if ( wfIniGetBool( 'safe_mode' ) ) {
+                       $this->setVar( '_SafeMode', true );
+                       $this->showMessage( 'config-safe-mode' );
+               }
+       }
+       /**
+        * Environment check for the XML module.
+        */
+       protected function envCheckXML() {
+               if ( !function_exists( "utf8_encode" ) ) {
+                       $this->showError( 'config-xml-bad' );
+                       return false;
+               }
+       }
+       /**
+        * Environment check for the PCRE module.
+        */
+       protected function envCheckPCRE() {
+               if ( !function_exists( 'preg_match' ) ) {
+                       $this->showError( 'config-pcre' );
+                       return false;
+               }
+               wfSuppressWarnings();
+               $regexd = preg_replace( '/[\x{0430}-\x{04FF}]/iu', '', '-АБВГД-' );
+               wfRestoreWarnings();
+               if ( $regexd != '--' ) {
+                       $this->showError( 'config-pcre-no-utf8' );
+                       return false;
+               }
+       }
+       /**
+        * Environment check for available memory.
+        */
+       protected function envCheckMemory() {
+               $limit = ini_get( 'memory_limit' );
+               if ( !$limit || $limit == -1 ) {
+                       return true;
+               }
+               $n = wfShorthandToInteger( $limit );
+               if( $n < $this->minMemorySize * 1024 * 1024 ) {
+                       $newLimit = "{$this->minMemorySize}M";
+                       if( ini_set( "memory_limit", $newLimit ) === false ) {
+                               $this->showMessage( 'config-memory-bad', $limit );
+                       } else {
+                               $this->showMessage( 'config-memory-raised', $limit, $newLimit );
+                               $this->setVar( '_RaiseMemory', true );
+                       }
+               } else {
+                       return true;
+               }
+       }
+       /**
+        * Environment check for compiled object cache types.
+        */
+       protected function envCheckCache() {
+               $caches = array();
+               foreach ( $this->objectCaches as $name => $function ) {
+                       if ( function_exists( $function ) ) {
+                               $caches[$name] = true;
+                       }
+               }
+               if ( !$caches ) {
+                       $this->showMessage( 'config-no-cache' );
+               }
+               $this->setVar( '_Caches', $caches );
+       }
+       /**
+        * Search for GNU diff3.
+        */
+       protected function envCheckDiff3() {
+               $names = array( "gdiff3", "diff3", "diff3.exe" );
+               $versionInfo = array( '$1 --version 2>&1', 'GNU diffutils' );
+               $diff3 = self::locateExecutableInDefaultPaths( $names, $versionInfo );
+               if ( $diff3 ) {
+                       $this->setVar( 'wgDiff3', $diff3 );
+               } else {
+                       $this->setVar( 'wgDiff3', false );
+                       $this->showMessage( 'config-diff3-bad' );
+               }
+       }
+       /**
+        * Environment check for ImageMagick and GD.
+        */
+       protected function envCheckGraphics() {
+               $names = array( wfIsWindows() ? 'convert.exe' : 'convert' );
+               $convert = self::locateExecutableInDefaultPaths( $names, array( '$1 -version', 'ImageMagick' ) );
+               $this->setVar( 'wgImageMagickConvertCommand', '' );
+               if ( $convert ) {
+                       $this->setVar( 'wgImageMagickConvertCommand', $convert );
+                       $this->showMessage( 'config-imagemagick', $convert );
+                       return true;
+               } elseif ( function_exists( 'imagejpeg' ) ) {
+                       $this->showMessage( 'config-gd' );
+                       return true;
+               } else {
+                       $this->showMessage( 'config-no-scaling' );
+               }
+       }
+       /**
+        * Environment check for setting $IP and $wgScriptPath.
+        */
+       protected function envCheckPath() {
+               global $IP;
+               $IP = dirname( dirname( dirname( __FILE__ ) ) );
 -
 -              // PHP_SELF isn't available sometimes, such as when PHP is CGI but
 -              // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
 -              // to get the path to the current script... hopefully it's reliable. SIGH
 -              if ( !empty( $_SERVER['PHP_SELF'] ) ) {
 -                      $path = $_SERVER['PHP_SELF'];
 -              } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
 -                      $path = $_SERVER['SCRIPT_NAME'];
 -              } elseif ( $this->getVar( 'wgScriptPath' ) ) {
 -                      // Some kind soul has set it for us already (e.g. debconf)
 -                      return true;
 -              } else {
 -                      $this->showError( 'config-no-uri' );
 -                      return false;
 -              }
 -
 -              $uri = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
 -              $this->setVar( 'wgScriptPath', $uri );
+               $this->setVar( 'IP', $IP );
+       }
+       /**
+        * Environment check for setting the preferred PHP file extension.
+        */
+       protected function envCheckExtension() {
+               // FIXME: detect this properly
+               if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
+                       $ext = 'php5';
+               } else {
+                       $ext = 'php';
+               }
+               $this->setVar( 'wgScriptExtension', ".$ext" );
+       }
+       /**
+        * TODO: document
+        */
+       protected function envCheckShellLocale() {
+               $os = php_uname( 's' );
+               $supported = array( 'Linux', 'SunOS', 'HP-UX', 'Darwin' ); # Tested these
+               if ( !in_array( $os, $supported ) ) {
+                       return true;
+               }
+               # Get a list of available locales.
+               $ret = false;
+               $lines = wfShellExec( '/usr/bin/locale -a', $ret );
+               if ( $ret ) {
+                       return true;
+               }
+               $lines = wfArrayMap( 'trim', explode( "\n", $lines ) );
+               $candidatesByLocale = array();
+               $candidatesByLang = array();
+               foreach ( $lines as $line ) {
+                       if ( $line === '' ) {
+                               continue;
+                       }
+                       if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
+                               continue;
+                       }
+                       list( $all, $lang, $territory, $charset, $modifier ) = $m;
+                       $candidatesByLocale[$m[0]] = $m;
+                       $candidatesByLang[$lang][] = $m;
+               }
+               # Try the current value of LANG.
+               if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
+                       $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
+                       return true;
+               }
+               # Try the most common ones.
+               $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
+               foreach ( $commonLocales as $commonLocale ) {
+                       if ( isset( $candidatesByLocale[$commonLocale] ) ) {
+                               $this->setVar( 'wgShellLocale', $commonLocale );
+                               return true;
+                       }
+               }
+               # Is there an available locale in the Wiki's language?
+               $wikiLang = $this->getVar( 'wgLanguageCode' );
+               if ( isset( $candidatesByLang[$wikiLang] ) ) {
+                       $m = reset( $candidatesByLang[$wikiLang] );
+                       $this->setVar( 'wgShellLocale', $m[0] );
+                       return true;
+               }
+               # Are there any at all?
+               if ( count( $candidatesByLocale ) ) {
+                       $m = reset( $candidatesByLocale );
+                       $this->setVar( 'wgShellLocale', $m[0] );
+                       return true;
+               }
+               # Give up.
+               return true;
+       }
+       /**
+        * TODO: document
+        */
+       protected function envCheckUploadsDirectory() {
+               global $IP, $wgServer;
+               $dir = $IP . '/images/';
+               $url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/';
+               $safe = !$this->dirIsExecutable( $dir, $url );
+               if ( $safe ) {
+                       return true;
+               } else {
+                       $this->showMessage( 'config-uploads-not-safe', $dir );
+               }
+       }
+       /**
+        * Checks if suhosin.get.max_value_length is set, and if so, sets
+        * $wgResourceLoaderMaxQueryLength to that value in the generated
+        * LocalSettings file
+        */
+       protected function envCheckSuhosinMaxValueLength() {
+               $maxValueLength = ini_get( 'suhosin.get.max_value_length' );
+               if ( $maxValueLength > 0 ) {
+                       $this->showMessage( 'config-suhosin-max-value-length', $maxValueLength );
+               } else {
+                       $maxValueLength = -1;
+               }
+               $this->setVar( 'wgResourceLoaderMaxQueryLength', $maxValueLength );
+       }
+       /**
+        * Convert a hex string representing a Unicode code point to that code point.
+        * @param $c String
+        * @return string
+        */
+       protected function unicodeChar( $c ) {
+               $c = hexdec($c);
+               if ($c <= 0x7F) {
+                       return chr($c);
+               } else if ($c <= 0x7FF) {
+                       return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
+               } else if ($c <= 0xFFFF) {
+                       return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
+                               . chr(0x80 | $c & 0x3F);
+               } else if ($c <= 0x10FFFF) {
+                       return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
+                               . chr(0x80 | $c >> 6 & 0x3F)
+                               . chr(0x80 | $c & 0x3F);
+               } else {
+                       return false;
+               }
+       }
+       /**
+        * Check the libicu version
+        */
+       protected function envCheckLibicu() {
+               $utf8 = function_exists( 'utf8_normalize' );
+               $intl = function_exists( 'normalizer_normalize' );
+               /**
+                * This needs to be updated something that the latest libicu
+                * will properly normalize.  This normalization was found at
+                * http://www.unicode.org/versions/Unicode5.2.0/#Character_Additions
+                * Note that we use the hex representation to create the code
+                * points in order to avoid any Unicode-destroying during transit.
+                */
+               $not_normal_c = $this->unicodeChar("FA6C");
+               $normal_c = $this->unicodeChar("242EE");
+               $useNormalizer = 'php';
+               $needsUpdate = false;
+               /**
+                * We're going to prefer the pecl extension here unless
+                * utf8_normalize is more up to date.
+                */
+               if( $utf8 ) {
+                       $useNormalizer = 'utf8';
+                       $utf8 = utf8_normalize( $not_normal_c, UNORM_NFC );
+                       if ( $utf8 !== $normal_c ) $needsUpdate = true;
+               }
+               if( $intl ) {
+                       $useNormalizer = 'intl';
+                       $intl = normalizer_normalize( $not_normal_c, Normalizer::FORM_C );
+                       if ( $intl !== $normal_c ) $needsUpdate = true;
+               }
+               // Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8', 'config-unicode-using-intl'
+               if( $useNormalizer === 'php' ) {
+                       $this->showMessage( 'config-unicode-pure-php-warning' );
+               } else {
+                       $this->showMessage( 'config-unicode-using-' . $useNormalizer );
+                       if( $needsUpdate ) {
+                               $this->showMessage( 'config-unicode-update-warning' );
+                       }
+               }
+       }
+       /**
+        * Get an array of likely places we can find executables. Check a bunch
+        * of known Unix-like defaults, as well as the PATH environment variable
+        * (which should maybe make it work for Windows?)
+        *
+        * @return Array
+        */
+       protected static function getPossibleBinPaths() {
+               return array_merge(
+                       array( '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
+                               '/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ),
+                       explode( PATH_SEPARATOR, getenv( 'PATH' ) )
+               );
+       }
+       /**
+        * Search a path for any of the given executable names. Returns the
+        * executable name if found. Also checks the version string returned
+        * by each executable.
+        *
+        * Used only by environment checks.
+        *
+        * @param $path String: path to search
+        * @param $names Array of executable names
+        * @param $versionInfo Boolean false or array with two members:
+        *               0 => Command to run for version check, with $1 for the full executable name
+        *               1 => String to compare the output with
+        *
+        * If $versionInfo is not false, only executables with a version
+        * matching $versionInfo[1] will be returned.
+        */
+       public static function locateExecutable( $path, $names, $versionInfo = false ) {
+               if ( !is_array( $names ) ) {
+                       $names = array( $names );
+               }
+               foreach ( $names as $name ) {
+                       $command = $path . DIRECTORY_SEPARATOR . $name;
+                       wfSuppressWarnings();
+                       $file_exists = file_exists( $command );
+                       wfRestoreWarnings();
+                       if ( $file_exists ) {
+                               if ( !$versionInfo ) {
+                                       return $command;
+                               }
+                               $file = str_replace( '$1', wfEscapeShellArg( $command ), $versionInfo[0] );
+                               if ( strstr( wfShellExec( $file ), $versionInfo[1] ) !== false ) {
+                                       return $command;
+                               }
+                       }
+               }
+               return false;
+       }
+       /**
+        * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
+        * @see locateExecutable()
+        */
+       public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
+               foreach( self::getPossibleBinPaths() as $path ) {
+                       $exe = self::locateExecutable( $path, $names, $versionInfo );
+                       if( $exe !== false ) {
+                               return $exe;
+                       }
+               }
+               return false;
+       }
+       /**
+        * Checks if scripts located in the given directory can be executed via the given URL.
+        *
+        * Used only by environment checks.
+        */
+       public function dirIsExecutable( $dir, $url ) {
+               $scriptTypes = array(
+                       'php' => array(
+                               "<?php echo 'ex' . 'ec';",
+                               "#!/var/env php5\n<?php echo 'ex' . 'ec';",
+                       ),
+               );
+               // it would be good to check other popular languages here, but it'll be slow.
+               wfSuppressWarnings();
+               foreach ( $scriptTypes as $ext => $contents ) {
+                       foreach ( $contents as $source ) {
+                               $file = 'exectest.' . $ext;
+                               if ( !file_put_contents( $dir . $file, $source ) ) {
+                                       break;
+                               }
+                               try {
+                                       $text = Http::get( $url . $file, array( 'timeout' => 3 ) );
+                               }
+                               catch( MWException $e ) {
+                                       // Http::get throws with allow_url_fopen = false and no curl extension.
+                                       $text = null;
+                               }
+                               unlink( $dir . $file );
+                               if ( $text == 'exec' ) {
+                                       wfRestoreWarnings();
+                                       return $ext;
+                               }
+                       }
+               }
+               wfRestoreWarnings();
+               return false;
+       }
+       /**
+        * ParserOptions are constructed before we determined the language, so fix it
+        */
+       public function setParserLanguage( $lang ) {
+               $this->parserOptions->setTargetLanguage( $lang );
+               $this->parserOptions->setUserLang( $lang->getCode() );
+       }
+       /**
+        * Overridden by WebInstaller to provide lastPage parameters.
+        */
+       protected function getDocUrl( $page ) {
+               return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
+       }
+       /**
+        * Finds extensions that follow the format /extensions/Name/Name.php,
+        * and returns an array containing the value for 'Name' for each found extension.
+        *
+        * @return array
+        */
+       public function findExtensions() {
+               if( $this->getVar( 'IP' ) === null ) {
+                       return false;
+               }
+               $exts = array();
+               $dir = $this->getVar( 'IP' ) . '/extensions';
+               $dh = opendir( $dir );
+               while ( ( $file = readdir( $dh ) ) !== false ) {
+                       if( file_exists( "$dir/$file/$file.php" ) ) {
+                               $exts[] = $file;
+                       }
+               }
+               return $exts;
+       }
+       /**
+        * Installs the auto-detected extensions.
+        *
+        * @return Status
+        */
+       protected function includeExtensions() {
+               global $IP;
+               $exts = $this->getVar( '_Extensions' );
+               $IP = $this->getVar( 'IP' );
+               /**
+                * We need to include DefaultSettings before including extensions to avoid
+                * warnings about unset variables. However, the only thing we really
+                * want here is $wgHooks['LoadExtensionSchemaUpdates']. This won't work
+                * if the extension has hidden hook registration in $wgExtensionFunctions,
+                * but we're not opening that can of worms
+                * @see https://bugzilla.wikimedia.org/show_bug.cgi?id=26857
+                */
+               global $wgAutoloadClasses;
+               require( "$IP/includes/DefaultSettings.php" );
+               foreach( $exts as $e ) {
+                       require_once( $IP . '/extensions' . "/$e/$e.php" );
+               }
+               $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ?
+                       $wgHooks['LoadExtensionSchemaUpdates'] : array();
+               // Unset everyone else's hooks. Lord knows what someone might be doing
+               // in ParserFirstCallInit (see bug 27171)
+               $GLOBALS['wgHooks'] = array( 'LoadExtensionSchemaUpdates' => $hooksWeWant );
+               return Status::newGood();
+       }
+       /**
+        * Get an array of install steps. Should always be in the format of
+        * array(
+        *   'name'     => 'someuniquename',
+        *   'callback' => array( $obj, 'method' ),
+        * )
+        * There must be a config-install-$name message defined per step, which will
+        * be shown on install.
+        *
+        * @param $installer DatabaseInstaller so we can make callbacks
+        * @return array
+        */
+       protected function getInstallSteps( DatabaseInstaller $installer ) {
+               $coreInstallSteps = array(
+                       array( 'name' => 'database',   'callback' => array( $installer, 'setupDatabase' ) ),
+                       array( 'name' => 'tables',     'callback' => array( $installer, 'createTables' ) ),
+                       array( 'name' => 'interwiki',  'callback' => array( $installer, 'populateInterwikiTable' ) ),
+                       array( 'name' => 'stats',      'callback' => array( $this, 'populateSiteStats' ) ),
+                       array( 'name' => 'keys',       'callback' => array( $this, 'generateKeys' ) ),
+                       array( 'name' => 'sysop',      'callback' => array( $this, 'createSysop' ) ),
+                       array( 'name' => 'mainpage',   'callback' => array( $this, 'createMainpage' ) ),
+               );
+               // Build the array of install steps starting from the core install list,
+               // then adding any callbacks that wanted to attach after a given step
+               foreach( $coreInstallSteps as $step ) {
+                       $this->installSteps[] = $step;
+                       if( isset( $this->extraInstallSteps[ $step['name'] ] ) ) {
+                               $this->installSteps = array_merge(
+                                       $this->installSteps,
+                                       $this->extraInstallSteps[ $step['name'] ]
+                               );
+                       }
+               }
+               // Prepend any steps that want to be at the beginning
+               if( isset( $this->extraInstallSteps['BEGINNING'] ) ) {
+                       $this->installSteps = array_merge(
+                               $this->extraInstallSteps['BEGINNING'],
+                               $this->installSteps
+                       );
+               }
+               // Extensions should always go first, chance to tie into hooks and such
+               if( count( $this->getVar( '_Extensions' ) ) ) {
+                       array_unshift( $this->installSteps,
+                               array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) )
+                       );
+                       $this->installSteps[] = array(
+                               'name' => 'extension-tables',
+                               'callback' => array( $installer, 'createExtensionTables' )
+                       );
+               }
+               return $this->installSteps;
+       }
+       /**
+        * Actually perform the installation.
+        *
+        * @param $startCB Array A callback array for the beginning of each step
+        * @param $endCB Array A callback array for the end of each step
+        *
+        * @return Array of Status objects
+        */
+       public function performInstallation( $startCB, $endCB ) {
+               $installResults = array();
+               $installer = $this->getDBInstaller();
+               $installer->preInstall();
+               $steps = $this->getInstallSteps( $installer );
+               foreach( $steps as $stepObj ) {
+                       $name = $stepObj['name'];
+                       call_user_func_array( $startCB, array( $name ) );
+                       // Perform the callback step
+                       $status = call_user_func( $stepObj['callback'], $installer );
+                       // Output and save the results
+                       call_user_func( $endCB, $name, $status );
+                       $installResults[$name] = $status;
+                       // If we've hit some sort of fatal, we need to bail.
+                       // Callback already had a chance to do output above.
+                       if( !$status->isOk() ) {
+                               break;
+                       }
+               }
+               if( $status->isOk() ) {
+                       $this->setVar( '_InstallDone', true );
+               }
+               return $installResults;
+       }
+       /**
+        * Generate $wgSecretKey. Will warn if we had to use mt_rand() instead of
+        * /dev/urandom
+        *
+        * @return Status
+        */
+       public function generateKeys() {
+               $keys = array( 'wgSecretKey' => 64 );
+               if ( strval( $this->getVar( 'wgUpgradeKey' ) ) === '' ) {
+                       $keys['wgUpgradeKey'] = 16;
+               }
+               return $this->doGenerateKeys( $keys );
+       }
+       /**
+        * Generate a secret value for variables using either
+        * /dev/urandom or mt_rand(). Produce a warning in the later case.
+        *
+        * @param $keys Array
+        * @return Status
+        */
+       protected function doGenerateKeys( $keys ) {
+               $status = Status::newGood();
+               wfSuppressWarnings();
+               $file = fopen( "/dev/urandom", "r" );
+               wfRestoreWarnings();
+               foreach ( $keys as $name => $length ) {
+                       if ( $file ) {
+                                       $secretKey = bin2hex( fread( $file, $length / 2 ) );
+                       } else {
+                               $secretKey = '';
+                               for ( $i = 0; $i < $length / 8; $i++ ) {
+                                       $secretKey .= dechex( mt_rand( 0, 0x7fffffff ) );
+                               }
+                       }
+                       $this->setVar( $name, $secretKey );
+               }
+               if ( $file ) {
+                       fclose( $file );
+               } else {
+                       $names = array_keys ( $keys );
+                       $names = preg_replace( '/^(.*)$/', '\$$1', $names );
+                       global $wgLang;
+                       $status->warning( 'config-insecure-keys', $wgLang->listToText( $names ), count( $names ) );
+               }
+               return $status;
+       }
+       /**
+        * Create the first user account, grant it sysop and bureaucrat rights
+        *
+        * @return Status
+        */
+       protected function createSysop() {
+               $name = $this->getVar( '_AdminName' );
+               $user = User::newFromName( $name );
+               if ( !$user ) {
+                       // We should've validated this earlier anyway!
+                       return Status::newFatal( 'config-admin-error-user', $name );
+               }
+               if ( $user->idForName() == 0 ) {
+                       $user->addToDatabase();
+                       try {
+                               $user->setPassword( $this->getVar( '_AdminPassword' ) );
+                       } catch( PasswordError $pwe ) {
+                               return Status::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
+                       }
+                       $user->addGroup( 'sysop' );
+                       $user->addGroup( 'bureaucrat' );
+                       if( $this->getVar( '_AdminEmail' ) ) {
+                               $user->setEmail( $this->getVar( '_AdminEmail' ) );
+                       }
+                       $user->saveSettings();
+                       // Update user count
+                       $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
+                       $ssUpdate->doUpdate();
+               }
+               $status = Status::newGood();
+               if( $this->getVar( '_Subscribe' ) && $this->getVar( '_AdminEmail' ) ) {
+                       $this->subscribeToMediaWikiAnnounce( $status );
+               }
+               return $status;
+       }
+       private function subscribeToMediaWikiAnnounce( Status $s ) {
+               $params = array(
+                       'email'    => $this->getVar( '_AdminEmail' ),
+                       'language' => 'en',
+                       'digest'   => 0
+               );
+               // Mailman doesn't support as many languages as we do, so check to make
+               // sure their selected language is available
+               $myLang = $this->getVar( '_UserLang' );
+               if( in_array( $myLang, $this->mediaWikiAnnounceLanguages ) ) {
+                       $myLang = $myLang == 'pt-br' ? 'pt_BR' : $myLang; // rewrite to Mailman's pt_BR
+                       $params['language'] = $myLang;
+               }
+               $res = MWHttpRequest::factory( $this->mediaWikiAnnounceUrl,
+                       array( 'method' => 'POST', 'postData' => $params ) )->execute();
+               if( !$res->isOK() ) {
+                       $s->warning( 'config-install-subscribe-fail', $res->getMessage() );
+               }
+       }
+       /**
+        * Insert Main Page with default content.
+        *
+        * @return Status
+        */
+       protected function createMainpage( DatabaseInstaller $installer ) {
+               $status = Status::newGood();
+               try {
+                       $article = new Article( Title::newMainPage() );
+                       $article->doEdit( wfMsgForContent( 'mainpagetext' ) . "\n\n" .
+                                                               wfMsgForContent( 'mainpagedocfooter' ),
+                                                               '',
+                                                               EDIT_NEW,
+                                                               false,
+                                                               User::newFromName( 'MediaWiki default' ) );
+               } catch (MWException $e) {
+                       //using raw, because $wgShowExceptionDetails can not be set yet
+                       $status->fatal( 'config-install-mainpage-failed', $e->getMessage() );
+               }
+               return $status;
+       }
+       /**
+        * Override the necessary bits of the config to run an installation.
+        */
+       public static function overrideConfig() {
+               define( 'MW_NO_SESSION', 1 );
+               // Don't access the database
+               $GLOBALS['wgUseDatabaseMessages'] = false;
+               // Debug-friendly
+               $GLOBALS['wgShowExceptionDetails'] = true;
+               // Don't break forms
+               $GLOBALS['wgExternalLinkTarget'] = '_blank';
+               // Extended debugging
+               $GLOBALS['wgShowSQLErrors'] = true;
+               $GLOBALS['wgShowDBErrorBacktrace'] = true;
+               // Allow multiple ob_flush() calls
+               $GLOBALS['wgDisableOutputCompression'] = true;
+               // Use a sensible cookie prefix (not my_wiki)
+               $GLOBALS['wgCookiePrefix'] = 'mw_installer';
+               // Some of the environment checks make shell requests, remove limits
+               $GLOBALS['wgMaxShellMemory'] = 0;
+       }
+       /**
+        * Add an installation step following the given step.
+        *
+        * @param $callback Array A valid installation callback array, in this form:
+        *    array( 'name' => 'some-unique-name', 'callback' => array( $obj, 'function' ) );
+        * @param $findStep String the step to find. Omit to put the step at the beginning
+        */
+       public function addInstallStep( $callback, $findStep = 'BEGINNING' ) {
+               $this->extraInstallSteps[$findStep][] = $callback;
+       }
+ }
index 0000000000000000000000000000000000000000,b75db74e18ae05c336ec3e4a7e387a226b0da136..7d3001327895b7f0ae434085012eedddb8f3f701
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,1034 +1,1048 @@@
+ <?php
+ /**
+  * Core installer web interface.
+  *
+  * @file
+  * @ingroup Deployment
+  */
+ /**
+  * Class for the core installer web interface.
+  *
+  * @ingroup Deployment
+  * @since 1.17
+  */
+ class WebInstaller extends Installer {
+       /**
+        * @var WebInstallerOutput
+        */
+       public $output;
+       /**
+        * WebRequest object.
+        *
+        * @var WebRequest
+        */
+       public $request;
+       /**
+        * Cached session array.
+        *
+        * @var array
+        */
+       protected $session;
+       /**
+        * Captured PHP error text. Temporary.
+        * @var array
+        */
+       protected $phpErrors;
+       /**
+        * The main sequence of page names. These will be displayed in turn.
+        * To add one:
+        *    * Add it here
+        *    * Add a config-page-<name> message
+        *    * Add a WebInstaller_<name> class
+        * @var array
+        */
+       public $pageSequence = array(
+               'Language',
+               'ExistingWiki',
+               'Welcome',
+               'DBConnect',
+               'Upgrade',
+               'DBSettings',
+               'Name',
+               'Options',
+               'Install',
+               'Complete',
+       );
+       /**
+        * Out of sequence pages, selectable by the user at any time.
+        * @var array
+        */
+       protected $otherPages = array(
+               'Restart',
+               'Readme',
+               'ReleaseNotes',
+               'Copying',
+               'UpgradeDoc', // Can't use Upgrade due to Upgrade step
+       );
+       /**
+        * Array of pages which have declared that they have been submitted, have validated
+        * their input, and need no further processing.
+        * @var array
+        */
+       protected $happyPages;
+       /**
+        * List of "skipped" pages. These are pages that will automatically continue
+        * to the next page on any GET request. To avoid breaking the "back" button,
+        * they need to be skipped during a back operation.
+        * @var array
+        */
+       protected $skippedPages;
+       /**
+        * Flag indicating that session data may have been lost.
+        * @var bool
+        */
+       public $showSessionWarning = false;
+       /**
+        * Numeric index of the page we're on
+        * @var int
+        */
+       protected $tabIndex = 1;
+       /**
+        * Name of the page we're on
+        * @var string
+        */
+       protected $currentPageName;
+       /**
+        * Constructor.
+        *
+        * @param $request WebRequest
+        */
+       public function __construct( WebRequest $request ) {
+               parent::__construct();
+               $this->output = new WebInstallerOutput( $this );
+               $this->request = $request;
+               // Add parser hooks
+               global $wgParser;
+               $wgParser->setHook( 'downloadlink', array( $this, 'downloadLinkHook' ) );
+               $wgParser->setHook( 'doclink', array( $this, 'docLink' ) );
+       }
+       /**
+        * Main entry point.
+        *
+        * @param $session Array: initial session array
+        *
+        * @return Array: new session array
+        */
+       public function execute( array $session ) {
+               $this->session = $session;
+               if ( isset( $session['settings'] ) ) {
+                       $this->settings = $session['settings'] + $this->settings;
+               }
+               $this->exportVars();
+               $this->setupLanguage();
+               if( ( $this->getVar( '_InstallDone' ) || $this->getVar( '_UpgradeDone' ) )
+                       && $this->request->getVal( 'localsettings' ) )
+               {
+                       $this->request->response()->header( 'Content-type: application/x-httpd-php' );
+                       $this->request->response()->header(
+                               'Content-Disposition: attachment; filename="LocalSettings.php"'
+                       );
+                       $ls = new LocalSettingsGenerator( $this );
+                       $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
+                       foreach( $rightsProfile as $group => $rightsArr ) {
+                               $ls->setGroupRights( $group, $rightsArr );
+                       }
+                       echo $ls->getText();
+                       return $this->session;
+               }
+               $cssDir = $this->request->getVal( 'css' );
+               if( $cssDir ) {
+                       $cssDir = ( $cssDir == 'rtl' ? 'rtl' : 'ltr' );
+                       $this->request->response()->header( 'Content-type: text/css' );
+                       echo $this->output->getCSS( $cssDir );
+                       return $this->session;
+               }
+               if ( isset( $session['happyPages'] ) ) {
+                       $this->happyPages = $session['happyPages'];
+               } else {
+                       $this->happyPages = array();
+               }
+               if ( isset( $session['skippedPages'] ) ) {
+                       $this->skippedPages = $session['skippedPages'];
+               } else {
+                       $this->skippedPages = array();
+               }
+               $lowestUnhappy = $this->getLowestUnhappy();
+               # Special case for Creative Commons partner chooser box.
+               if ( $this->request->getVal( 'SubmitCC' ) ) {
+                       $page = $this->getPageByName( 'Options' );
+                       $this->output->useShortHeader();
+                       $this->output->allowFrames();
+                       $page->submitCC();
+                       return $this->finish();
+               }
+               if ( $this->request->getVal( 'ShowCC' ) ) {
+                       $page = $this->getPageByName( 'Options' );
+                       $this->output->useShortHeader();
+                       $this->output->allowFrames();
+                       $this->output->addHTML( $page->getCCDoneBox() );
+                       return $this->finish();
+               }
+               # Get the page name.
+               $pageName = $this->request->getVal( 'page' );
+               if ( in_array( $pageName, $this->otherPages ) ) {
+                       # Out of sequence
+                       $pageId = false;
+                       $page = $this->getPageByName( $pageName );
+               } else {
+                       # Main sequence
+                       if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
+                               $pageId = $lowestUnhappy;
+                       } else {
+                               $pageId = array_search( $pageName, $this->pageSequence );
+                       }
+                       # If necessary, move back to the lowest-numbered unhappy page
+                       if ( $pageId > $lowestUnhappy ) {
+                               $pageId = $lowestUnhappy;
+                               if ( $lowestUnhappy == 0 ) {
+                                       # Knocked back to start, possible loss of session data.
+                                       $this->showSessionWarning = true;
+                               }
+                       }
+                       $pageName = $this->pageSequence[$pageId];
+                       $page = $this->getPageByName( $pageName );
+               }
+               # If a back button was submitted, go back without submitting the form data.
+               if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) {
+                       if ( $this->request->getVal( 'lastPage' ) ) {
+                               $nextPage = $this->request->getVal( 'lastPage' );
+                       } elseif ( $pageId !== false ) {
+                               # Main sequence page
+                               # Skip the skipped pages
+                               $nextPageId = $pageId;
+                               do {
+                                       $nextPageId--;
+                                       $nextPage = $this->pageSequence[$nextPageId];
+                               } while( isset( $this->skippedPages[$nextPage] ) );
+                       } else {
+                               $nextPage = $this->pageSequence[$lowestUnhappy];
+                       }
+                       $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
+                       return $this->finish();
+               }
+               # Execute the page.
+               $this->currentPageName = $page->getName();
+               $this->startPageWrapper( $pageName );
+               $result = $page->execute();
+               $this->endPageWrapper();
+               if ( $result == 'skip' ) {
+                       # Page skipped without explicit submission.
+                       # Skip it when we click "back" so that we don't just go forward again.
+                       $this->skippedPages[$pageName] = true;
+                       $result = 'continue';
+               } else {
+                       unset( $this->skippedPages[$pageName] );
+               }
+               # If it was posted, the page can request a continue to the next page.
+               if ( $result === 'continue' && !$this->output->headerDone() ) {
+                       if ( $pageId !== false ) {
+                               $this->happyPages[$pageId] = true;
+                       }
+                       $lowestUnhappy = $this->getLowestUnhappy();
+                       if ( $this->request->getVal( 'lastPage' ) ) {
+                               $nextPage = $this->request->getVal( 'lastPage' );
+                       } elseif ( $pageId !== false ) {
+                               $nextPage = $this->pageSequence[$pageId + 1];
+                       } else {
+                               $nextPage = $this->pageSequence[$lowestUnhappy];
+                       }
+                       if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
+                               $nextPage = $this->pageSequence[$lowestUnhappy];
+                       }
+                       $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
+               }
+               return $this->finish();
+       }
+       /**
+        * Find the next page in sequence that hasn't been completed
+        * @return int
+        */
+       public function getLowestUnhappy() {
+               if ( count( $this->happyPages ) == 0 ) {
+                       return 0;
+               } else {
+                       return max( array_keys( $this->happyPages ) ) + 1;
+               }
+       }
+       /**
+        * Start the PHP session. This may be called before execute() to start the PHP session.
+        */
+       public function startSession() {
+               if( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
+                       // Done already
+                       return true;
+               }
+               $this->phpErrors = array();
+               set_error_handler( array( $this, 'errorHandler' ) );
+               session_start();
+               restore_error_handler();
+               if ( $this->phpErrors ) {
+                       $this->showError( 'config-session-error', $this->phpErrors[0] );
+                       return false;
+               }
+               return true;
+       }
+       /**
+        * Get a hash of data identifying this MW installation.
+        *
+        * This is used by mw-config/index.php to prevent multiple installations of MW
+        * on the same cookie domain from interfering with each other.
+        */
+       public function getFingerprint() {
+               // Get the base URL of the installation
+               $url = $this->request->getFullRequestURL();
+               if ( preg_match( '!^(.*\?)!', $url, $m) ) {
+                       // Trim query string
+                       $url = $m[1];
+               }
+               if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
+                       // This... seems to try to get the base path from
+                       // the /mw-config/index.php. Kinda scary though?
+                       $url = $m[1];
+               }
+               return md5( serialize( array(
+                       'local path' => dirname( dirname( __FILE__ ) ),
+                       'url' => $url,
+                       'version' => $GLOBALS['wgVersion']
+               ) ) );
+       }
+       /**
+        * Show an error message in a box. Parameters are like wfMsg().
+        */
+       public function showError( $msg /*...*/ ) {
+               $args = func_get_args();
+               array_shift( $args );
+               $args = array_map( 'htmlspecialchars', $args );
+               $msg = wfMsgReal( $msg, $args, false, false, false );
+               $this->output->addHTML( $this->getErrorBox( $msg ) );
+       }
+       /**
+        * Temporary error handler for session start debugging.
+        */
+       public function errorHandler( $errno, $errstr ) {
+               $this->phpErrors[] = $errstr;
+       }
+       /**
+        * Clean up from execute()
+        *
+        * @return array
+        */
+       public function finish() {
+               $this->output->output();
+               $this->session['happyPages'] = $this->happyPages;
+               $this->session['skippedPages'] = $this->skippedPages;
+               $this->session['settings'] = $this->settings;
+               return $this->session;
+       }
+       /**
+        * We're restarting the installation, reset the session, happyPages, etc
+        */
+       public function reset() {
+               $this->session = array();
+               $this->happyPages = array();
+               $this->settings = array();
+       }
+       /**
+        * Get a URL for submission back to the same script.
+        *
+        * @param $query: Array
+        * @return string
+        */
+       public function getUrl( $query = array() ) {
+               $url = $this->request->getRequestURL();
+               # Remove existing query
+               $url = preg_replace( '/\?.*$/', '', $url );
+               if ( $query ) {
+                       $url .= '?' . wfArrayToCGI( $query );
+               }
+               return $url;
+       }
+       /**
+        * Get a WebInstallerPage by name.
+        *
+        * @param $pageName String
+        * @return WebInstallerPage
+        */
+       public function getPageByName( $pageName ) {
+               // Totally lame way to force autoload of WebInstallerPage.php
+               class_exists( 'WebInstallerPage' );
+               $pageClass = 'WebInstaller_' . $pageName;
+               return new $pageClass( $this );
+       }
+       /**
+        * Get a session variable.
+        *
+        * @param $name String
+        * @param $default
+        */
+       public function getSession( $name, $default = null ) {
+               if ( !isset( $this->session[$name] ) ) {
+                       return $default;
+               } else {
+                       return $this->session[$name];
+               }
+       }
+       /**
+        * Set a session variable.
+        * @param $name String key for the variable
+        * @param $value Mixed
+        */
+       public function setSession( $name, $value ) {
+               $this->session[$name] = $value;
+       }
+       /**
+        * Get the next tabindex attribute value.
+        * @return int
+        */
+       public function nextTabIndex() {
+               return $this->tabIndex++;
+       }
+       /**
+        * Initializes language-related variables.
+        */
+       public function setupLanguage() {
+               global $wgLang, $wgContLang, $wgLanguageCode;
+               if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
+                       $wgLanguageCode = $this->getAcceptLanguage();
+                       $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
+                       $this->setVar( 'wgLanguageCode', $wgLanguageCode );
+                       $this->setVar( '_UserLang', $wgLanguageCode );
+               } else {
+                       $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
+                       $wgLang = Language::factory( $this->getVar( '_UserLang' ) );
+                       $wgContLang = Language::factory( $wgLanguageCode );
+               }
+       }
+       /**
+        * Retrieves MediaWiki language from Accept-Language HTTP header.
+        *
+        * @return string
+        */
+       public function getAcceptLanguage() {
+               global $wgLanguageCode, $wgRequest;
+               $mwLanguages = Language::getLanguageNames();
+               $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
+               foreach ( $headerLanguages as $lang ) {
+                       if ( isset( $mwLanguages[$lang] ) ) {
+                               return $lang;
+                       }
+               }
+               return $wgLanguageCode;
+       }
+       /**
+        * Called by execute() before page output starts, to show a page list.
+        *
+        * @param $currentPageName String
+        */
+       private function startPageWrapper( $currentPageName ) {
+               $s = "<div class=\"config-page-wrapper\">\n";
+               $s .= "<div class=\"config-page\">\n";
+               $s .= "<div class=\"config-page-list\"><ul>\n";
+               $lastHappy = -1;
+               foreach ( $this->pageSequence as $id => $pageName ) {
+                       $happy = !empty( $this->happyPages[$id] );
+                       $s .= $this->getPageListItem(
+                               $pageName,
+                               $happy || $lastHappy == $id - 1,
+                               $currentPageName
+                       );
+                       if ( $happy ) {
+                               $lastHappy = $id;
+                       }
+               }
+               $s .= "</ul><br/><ul>\n";
+               $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
+               $s .= "</ul></div>\n"; // end list pane
+               $s .= Html::element( 'h2', array(),
+                               wfMsg( 'config-page-' . strtolower( $currentPageName ) ) );
+               $this->output->addHTMLNoFlush( $s );
+       }
+       /**
+        * Get a list item for the page list.
+        *
+        * @param $pageName String
+        * @param $enabled Boolean
+        * @param $currentPageName String
+        *
+        * @return string
+        */
+       private function getPageListItem( $pageName, $enabled, $currentPageName ) {
+               $s = "<li class=\"config-page-list-item\">";
+               $name = wfMsg( 'config-page-' . strtolower( $pageName ) );
+               if ( $enabled ) {
+                       $query = array( 'page' => $pageName );
+                       if ( !in_array( $pageName, $this->pageSequence ) ) {
+                               if ( in_array( $currentPageName, $this->pageSequence ) ) {
+                                       $query['lastPage'] = $currentPageName;
+                               }
+                               $link = Html::element( 'a',
+                                       array(
+                                               'href' => $this->getUrl( $query )
+                                       ),
+                                       $name
+                               );
+                       } else {
+                               $link = htmlspecialchars( $name );
+                       }
+                       if ( $pageName == $currentPageName ) {
+                               $s .= "<span class=\"config-page-current\">$link</span>";
+                       } else {
+                               $s .= $link;
+                       }
+               } else {
+                       $s .= Html::element( 'span',
+                               array(
+                                       'class' => 'config-page-disabled'
+                               ),
+                               $name
+                       );
+               }
+               $s .= "</li>\n";
+               return $s;
+       }
+       /**
+        * Output some stuff after a page is finished.
+        */
+       private function endPageWrapper() {
+               $this->output->addHTMLNoFlush(
+                                       "<div class=\"visualClear\"></div>\n" .
+                               "</div>\n" .
+                               "<div class=\"visualClear\"></div>\n" .
+                       "</div>" );
+       }
+       /**
+        * Get HTML for an error box with an icon.
+        *
+        * @param $text String: wikitext, get this with wfMsgNoTrans()
+        */
+       public function getErrorBox( $text ) {
+               return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
+       }
+       /**
+        * Get HTML for a warning box with an icon.
+        *
+        * @param $text String: wikitext, get this with wfMsgNoTrans()
+        */
+       public function getWarningBox( $text ) {
+               return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
+       }
+       /**
+        * Get HTML for an info box with an icon.
+        *
+        * @param $text String: wikitext, get this with wfMsgNoTrans()
+        * @param $icon String: icon name, file in skins/common/images
+        * @param $class String: additional class name to add to the wrapper div
+        */
+       public function getInfoBox( $text, $icon = 'info-32.png', $class = false ) {
+               $s =
+                       "<div class=\"config-info $class\">\n" .
+                               "<div class=\"config-info-left\">\n" .
+                               Html::element( 'img',
+                                       array(
+                                               'src' => '../skins/common/images/' . $icon,
+                                               'alt' => wfMsg( 'config-information' ),
+                                       )
+                               ) . "\n" .
+                               "</div>\n" .
+                               "<div class=\"config-info-right\">\n" .
+                                       $this->parse( $text, true ) . "\n" .
+                               "</div>\n" .
+                               "<div style=\"clear: left;\"></div>\n" .
+                       "</div>\n";
+               return $s;
+       }
+       /**
+        * Get small text indented help for a preceding form field.
+        * Parameters like wfMsg().
+        */
+       public function getHelpBox( $msg /*, ... */ ) {
+               $args = func_get_args();
+               array_shift( $args );
+               $args = array_map( 'htmlspecialchars', $args );
+               $text = wfMsgReal( $msg, $args, false, false, false );
+               $html = htmlspecialchars( $text );
+               $html = $this->parse( $text, true );
+               return "<div class=\"mw-help-field-container\">\n" .
+                          "<span class=\"mw-help-field-hint\">" . wfMsgHtml( 'config-help' ) . "</span>\n" .
+                          "<span class=\"mw-help-field-data\">" . $html . "</span>\n" .
+                          "</div>\n";
+       }
+       /**
+        * Output a help box.
+        * @param $msg String key for wfMsg()
+        */
+       public function showHelpBox( $msg /*, ... */ ) {
+               $args = func_get_args();
+               $html = call_user_func_array( array( $this, 'getHelpBox' ), $args );
+               $this->output->addHTML( $html );
+       }
+       /**
+        * Show a short informational message.
+        * Output looks like a list.
+        *
+        * @param $msg string
+        */
+       public function showMessage( $msg /*, ... */ ) {
+               $args = func_get_args();
+               array_shift( $args );
+               $html = '<div class="config-message">' .
+                       $this->parse( wfMsgReal( $msg, $args, false, false, false ) ) .
+                       "</div>\n";
+               $this->output->addHTML( $html );
+       }
+       /**
+        * @param $status Status
+        */
+       public function showStatusMessage( Status $status ) {
+               $text = $status->getWikiText();
+               $this->output->addWikiText(
+                       "<div class=\"config-message\">\n" .
+                       $text .
+                       "</div>"
+               );
+       }
+       /**
+        * Label a control by wrapping a config-input div around it and putting a
+        * label before it.
+        */
+       public function label( $msg, $forId, $contents, $helpData = "" ) {
+               if ( strval( $msg ) == '' ) {
+                       $labelText = '&#160;';
+               } else {
+                       $labelText = wfMsgHtml( $msg );
+               }
+               $attributes = array( 'class' => 'config-label' );
+               if ( $forId ) {
+                       $attributes['for'] = $forId;
+               }
+               return
+                       "<div class=\"config-block\">\n" .
+                       "  <div class=\"config-block-label\">\n" .
+                       Xml::tags( 'label',
+                               $attributes,
+                               $labelText ) . "\n" .
+                               $helpData .
+                       "  </div>\n" .
+                       "  <div class=\"config-block-elements\">\n" .
+                               $contents .
+                       "  </div>\n" .
+                       "</div>\n";
+       }
+       /**
+        * Get a labelled text box to configure a variable.
+        *
+        * @param $params Array
+        *    Parameters are:
+        *      var:        The variable to be configured (required)
+        *      label:      The message name for the label (required)
+        *      attribs:    Additional attributes for the input element (optional)
+        *      controlName: The name for the input element (optional)
+        *      value:      The current value of the variable (optional)
+        *      help:           The html for the help text (optional)
+        */
+       public function getTextBox( $params ) {
+               if ( !isset( $params['controlName'] ) ) {
+                       $params['controlName'] = 'config_' . $params['var'];
+               }
+               if ( !isset( $params['value'] ) ) {
+                       $params['value'] = $this->getVar( $params['var'] );
+               }
+               if ( !isset( $params['attribs'] ) ) {
+                       $params['attribs'] = array();
+               }
+               if ( !isset( $params['help'] ) ) {
+                       $params['help'] = "";
+               }
+               return
+                       $this->label(
+                               $params['label'],
+                               $params['controlName'],
+                               Xml::input(
+                                       $params['controlName'],
+                                       30, // intended to be overridden by CSS
+                                       $params['value'],
+                                       $params['attribs'] + array(
+                                               'id' => $params['controlName'],
+                                               'class' => 'config-input-text',
+                                               'tabindex' => $this->nextTabIndex()
+                                       )
+                               ),
+                               $params['help']
+                       );
+       }
+       /**
+        * Get a labelled textarea to configure a variable
+        *
+        * @param $params Array
+        *    Parameters are:
+        *      var:        The variable to be configured (required)
+        *      label:      The message name for the label (required)
+        *      attribs:    Additional attributes for the input element (optional)
+        *      controlName: The name for the input element (optional)
+        *      value:      The current value of the variable (optional)
+        *      help:           The html for the help text (optional)
+        */
+       public function getTextArea( $params ) {
+               if ( !isset( $params['controlName'] ) ) {
+                       $params['controlName'] = 'config_' . $params['var'];
+               }
+               if ( !isset( $params['value'] ) ) {
+                       $params['value'] = $this->getVar( $params['var'] );
+               }
+               if ( !isset( $params['attribs'] ) ) {
+                       $params['attribs'] = array();
+               }
+               if ( !isset( $params['help'] ) ) {
+                       $params['help'] = "";
+               }
+               return
+                       $this->label(
+                               $params['label'],
+                               $params['controlName'],
+                               Xml::textarea(
+                                       $params['controlName'],
+                                       $params['value'],
+                                       30,
+                                       5,
+                                       $params['attribs'] + array(
+                                               'id' => $params['controlName'],
+                                               'class' => 'config-input-text',
+                                               'tabindex' => $this->nextTabIndex()
+                                       )
+                               ),
+                               $params['help']
+                       );
+       }
+       /**
+        * Get a labelled password box to configure a variable.
+        *
+        * Implements password hiding
+        * @param $params Array
+        *    Parameters are:
+        *      var:        The variable to be configured (required)
+        *      label:      The message name for the label (required)
+        *      attribs:    Additional attributes for the input element (optional)
+        *      controlName: The name for the input element (optional)
+        *      value:      The current value of the variable (optional)
+        *      help:           The html for the help text (optional)
+        */
+       public function getPasswordBox( $params ) {
+               if ( !isset( $params['value'] ) ) {
+                       $params['value'] = $this->getVar( $params['var'] );
+               }
+               if ( !isset( $params['attribs'] ) ) {
+                       $params['attribs'] = array();
+               }
+               $params['value'] = $this->getFakePassword( $params['value'] );
+               $params['attribs']['type'] = 'password';
+               return $this->getTextBox( $params );
+       }
+       /**
+        * Get a labelled checkbox to configure a boolean variable.
+        *
+        * @param $params Array
+        *    Parameters are:
+        *      var:        The variable to be configured (required)
+        *      label:      The message name for the label (required)
+        *      attribs:    Additional attributes for the input element (optional)
+        *      controlName: The name for the input element (optional)
+        *      value:      The current value of the variable (optional)
+        *      help:           The html for the help text (optional)
+        */
+       public function getCheckBox( $params ) {
+               if ( !isset( $params['controlName'] ) ) {
+                       $params['controlName'] = 'config_' . $params['var'];
+               }
+               if ( !isset( $params['value'] ) ) {
+                       $params['value'] = $this->getVar( $params['var'] );
+               }
+               if ( !isset( $params['attribs'] ) ) {
+                       $params['attribs'] = array();
+               }
+               if ( !isset( $params['help'] ) ) {
+                       $params['help'] = "";
+               }
+               if( isset( $params['rawtext'] ) ) {
+                       $labelText = $params['rawtext'];
+               } else {
+                       $labelText = $this->parse( wfMsg( $params['label'] ) );
+               }
+               return
+                       "<div class=\"config-input-check\">\n" .
+                       $params['help'] .
+                       "<label>\n" .
+                       Xml::check(
+                               $params['controlName'],
+                               $params['value'],
+                               $params['attribs'] + array(
+                                       'id' => $params['controlName'],
+                                       'tabindex' => $this->nextTabIndex(),
+                               )
+                       ) .
+                       $labelText . "\n" .
+                       "</label>\n" .
+                       "</div>\n";
+       }
+       /**
+        * Get a set of labelled radio buttons.
+        *
+        * @param $params Array
+        *    Parameters are:
+        *      var:            The variable to be configured (required)
+        *      label:          The message name for the label (required)
+        *      itemLabelPrefix: The message name prefix for the item labels (required)
+        *      values:         List of allowed values (required)
+        *      itemAttribs     Array of attribute arrays, outer key is the value name (optional)
+        *      commonAttribs   Attribute array applied to all items
+        *      controlName:    The name for the input element (optional)
+        *      value:          The current value of the variable (optional)
+        *      help:           The html for the help text (optional)
+        */
+       public function getRadioSet( $params ) {
+               if ( !isset( $params['controlName']  ) ) {
+                       $params['controlName'] = 'config_' . $params['var'];
+               }
+               if ( !isset( $params['value'] ) ) {
+                       $params['value'] = $this->getVar( $params['var'] );
+               }
+               if ( !isset( $params['label'] ) ) {
+                       $label = '';
+               } else {
+                       $label = $params['label'];
+               }
+               if ( !isset( $params['help'] ) ) {
+                       $params['help'] = "";
+               }
+               $s = "<ul>\n";
+               foreach ( $params['values'] as $value ) {
+                       $itemAttribs = array();
+                       if ( isset( $params['commonAttribs'] ) ) {
+                               $itemAttribs = $params['commonAttribs'];
+                       }
+                       if ( isset( $params['itemAttribs'][$value] ) ) {
+                               $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
+                       }
+                       $checked = $value == $params['value'];
+                       $id = $params['controlName'] . '_' . $value;
+                       $itemAttribs['id'] = $id;
+                       $itemAttribs['tabindex'] = $this->nextTabIndex();
+                       $s .=
+                               '<li>' .
+                               Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
+                               '&#160;' .
+                               Xml::tags( 'label', array( 'for' => $id ), $this->parse(
+                                       wfMsgNoTrans( $params['itemLabelPrefix'] . strtolower( $value ) )
+                               ) ) .
+                               "</li>\n";
+               }
+               $s .= "</ul>\n";
+               return $this->label( $label, $params['controlName'], $s, $params['help'] );
+       }
+       /**
+        * Output an error or warning box using a Status object.
+        */
+       public function showStatusBox( $status ) {
+               if( !$status->isGood() ) {
+                       $text = $status->getWikiText();
+                       if( $status->isOk() ) {
+                               $box = $this->getWarningBox( $text );
+                       } else {
+                               $box = $this->getErrorBox( $text );
+                       }
+                       $this->output->addHTML( $box );
+               }
+       }
+       /**
+        * Convenience function to set variables based on form data.
+        * Assumes that variables containing "password" in the name are (potentially
+        * fake) passwords.
+        *
+        * @param $varNames Array
+        * @param $prefix String: the prefix added to variables to obtain form names
+        */
+       public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
+               $newValues = array();
+               foreach ( $varNames as $name ) {
+                       $value = trim( $this->request->getVal( $prefix . $name ) );
+                       $newValues[$name] = $value;
+                       if ( $value === null ) {
+                               // Checkbox?
+                               $this->setVar( $name, false );
+                       } else {
+                               if ( stripos( $name, 'password' ) !== false ) {
+                                       $this->setPassword( $name, $value );
+                               } else {
+                                       $this->setVar( $name, $value );
+                               }
+                       }
+               }
++              // PHP_SELF isn't available sometimes, such as when PHP is CGI but
++              // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
++              // to get the path to the current script... hopefully it's reliable. SIGH
++              $path = false;
++              if ( !empty( $_SERVER['PHP_SELF'] ) ) {
++                      $path = $_SERVER['PHP_SELF'];
++              } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
++                      $path = $_SERVER['SCRIPT_NAME'];
++              }
++              if ($path !== false) {
++                      $uri = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
++                      $this->setVar( 'wgScriptPath', $uri );
++              }
++
+               return $newValues;
+       }
+       /**
+        * Helper for Installer::docLink()
+        */
+       protected function getDocUrl( $page ) {
+               $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
+               if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
+                       $url .= '&lastPage=' . urlencode( $this->currentPageName );
+               }
+               return $url;
+       }
+       /**
+        * Extension tag hook for a documentation link.
+        */
+       public function docLink( $linkText, $attribs, $parser ) {
+               $url = $this->getDocUrl( $attribs['href'] );
+               return '<a href="' . htmlspecialchars( $url ) . '">' .
+                       htmlspecialchars( $linkText ) .
+                       '</a>';
+       }
+       
+       /**
+        * Helper for "Download LocalSettings" link on WebInstall_Complete
+        * @return String Html for download link
+        */
+       public function downloadLinkHook( $text, $attribs, $parser  ) {
+               $img = Html::element( 'img', array(
+                       'src' => '../skins/common/images/download-32.png',
+                       'width' => '32',
+                       'height' => '32',
+               ) );
+               $anchor = Html::rawElement( 'a',
+                       array( 'href' => $this->getURL( array( 'localsettings' => 1 ) ) ),
+                       $img . ' ' . wfMsgHtml( 'config-download-localsettings' ) );
+               return Html::rawElement( 'div', array( 'class' => 'config-download-link' ), $anchor );
+       }
+ }