Fix undefined $modelId in MWUnknownContentModelException
[lhc/web/wiklou.git] / maintenance / update.php
index 2ba5daf..ed8dfa9 100755 (executable)
@@ -4,7 +4,6 @@
  * Run all updaters.
  *
  * This is used when the database schema is modified and we need to apply patches.
- * It is kept compatible with php 4 parsing so that it can give out a meaningful error.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * @ingroup Maintenance
  */
 
-if ( !function_exists( 'version_compare' ) || ( version_compare( PHP_VERSION, '5.3.3' ) < 0 ) ) {
-       require dirname( __FILE__ ) . '/../includes/PHPVersionError.php';
-       wfPHPVersionError( 'cli' );
-}
-
 $wgUseMasterForMaintenance = true;
 require_once __DIR__ . '/Maintenance.php';
 
@@ -42,7 +36,7 @@ require_once __DIR__ . '/Maintenance.php';
 class UpdateMediaWiki extends Maintenance {
        function __construct() {
                parent::__construct();
-               $this->mDescription = "MediaWiki database updater";
+               $this->addDescription( 'MediaWiki database updater' );
                $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
                $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
                $this->addOption( 'doshared', 'Also update shared tables' );
@@ -63,13 +57,11 @@ class UpdateMediaWiki extends Maintenance {
        }
 
        function getDbType() {
-               /* If we used the class constant PHP4 would give a parser error here */
-               return 2; /* Maintenance::DB_ADMIN */
+               return Maintenance::DB_ADMIN;
        }
 
        function compatChecks() {
-               // Avoid syntax error in PHP4
-               $minimumPcreVersion = constant( 'Installer::MINIMUM_PCRE_VERSION' );
+               $minimumPcreVersion = Installer::MINIMUM_PCRE_VERSION;
 
                list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 );
                if ( version_compare( $pcreVersion, $minimumPcreVersion, '<' ) ) {
@@ -120,7 +112,10 @@ class UpdateMediaWiki extends Maintenance {
                        }
                }
 
-               $wgLang = Language::factory( 'en' );
+               $lang = Language::factory( 'en' );
+               // Set global language to ensure localised errors are in English (bug 20633)
+               RequestContext::getMain()->setLanguage( $lang );
+               $wgLang = $lang; // BackCompat
 
                define( 'MW_UPDATER', true );
 
@@ -147,7 +142,7 @@ class UpdateMediaWiki extends Maintenance {
 
                # Attempt to connect to the database as a privileged user
                # This will vomit up an error if there are permissions problems
-               $db = wfGetDB( DB_MASTER );
+               $db = $this->getDB( DB_MASTER );
 
                $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
                if ( $db->getType() === 'sqlite' ) {
@@ -165,7 +160,7 @@ class UpdateMediaWiki extends Maintenance {
 
                $shared = $this->hasOption( 'doshared' );
 
-               $updates = array( 'core', 'extensions' );
+               $updates = [ 'core', 'extensions' ];
                if ( !$this->hasOption( 'schema' ) ) {
                        if ( $this->hasOption( 'noschema' ) ) {
                                $updates[] = 'noschema';
@@ -180,7 +175,7 @@ class UpdateMediaWiki extends Maintenance {
                        $child = $this->runChild( $maint );
 
                        // LoggedUpdateMaintenance is checking the updatelog itself
-                       $isLoggedUpdate = is_a( $child, 'LoggedUpdateMaintenance' );
+                       $isLoggedUpdate = $child instanceof LoggedUpdateMaintenance;
 
                        if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
                                continue;
@@ -199,7 +194,7 @@ class UpdateMediaWiki extends Maintenance {
 
                $time2 = microtime( true );
 
-               $timeDiff = $wgLang->formatTimePeriod( $time2 - $time1 );
+               $timeDiff = $lang->formatTimePeriod( $time2 - $time1 );
                $this->output( "\nDone in $timeDiff.\n" );
        }
 
@@ -209,12 +204,12 @@ class UpdateMediaWiki extends Maintenance {
                # Don't try to access the database
                # This needs to be disabled early since extensions will try to use the l10n
                # cache from $wgExtensionFunctions (bug 20471)
-               $wgLocalisationCacheConf = array(
+               $wgLocalisationCacheConf = [
                        'class' => 'LocalisationCache',
                        'storeClass' => 'LCStoreNull',
                        'storeDirectory' => false,
                        'manualRecache' => false,
-               );
+               ];
        }
 }