MediaWiki  REL1_22
update.php
Go to the documentation of this file.
00001 <?php
00028 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.3.2' ) < 0 ) ) {
00029     require dirname( __FILE__ ) . '/../includes/PHPVersionError.php';
00030     wfPHPVersionError( 'cli' );
00031 }
00032 
00033 $wgUseMasterForMaintenance = true;
00034 require_once __DIR__ . '/Maintenance.php';
00035 
00041 class UpdateMediaWiki extends Maintenance {
00042     function __construct() {
00043         parent::__construct();
00044         $this->mDescription = "MediaWiki database updater";
00045         $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
00046         $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
00047         $this->addOption( 'doshared', 'Also update shared tables' );
00048         $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
00049         $this->addOption( 'noschema', 'Only do the updates that are not done during schema updates' );
00050         $this->addOption( 'schema', 'Output SQL to do the schema updates instead of doing them.  Works even when $wgAllowSchemaUpdates is false', false, true );
00051         $this->addOption( 'force', 'Override when $wgAllowSchemaUpdates disables this script' );
00052     }
00053 
00054     function getDbType() {
00055         /* If we used the class constant PHP4 would give a parser error here */
00056         return 2 /* Maintenance::DB_ADMIN */;
00057     }
00058 
00059     function compatChecks() {
00060         // Avoid syntax error in PHP4
00061         $minimumPcreVersion = constant( 'Installer::MINIMUM_PCRE_VERSION' );
00062 
00063         list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 );
00064         if ( version_compare( $pcreVersion, $minimumPcreVersion, '<' ) ) {
00065             $this->error(
00066                 "PCRE $minimumPcreVersion or later is required.\n" .
00067                 "Your PHP binary is linked with PCRE $pcreVersion.\n\n" .
00068                 "More information:\n" .
00069                 "https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" .
00070                 "ABORTING.\n",
00071                 true );
00072         }
00073 
00074         $test = new PhpXmlBugTester();
00075         if ( !$test->ok ) {
00076             $this->error(
00077                 "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
00078                 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
00079                 "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
00080                 "ABORTING (see http://bugs.php.net/bug.php?id=45996).\n",
00081                 true );
00082         }
00083 
00084         $test = new PhpRefCallBugTester;
00085         $test->execute();
00086         if ( !$test->ok ) {
00087             $ver = phpversion();
00088             $this->error(
00089                 "PHP $ver is not compatible with MediaWiki due to a bug involving\n" .
00090                 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
00091                 "downgrade to PHP 5.3.0 to fix this.\n" .
00092                 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n",
00093                 true );
00094         }
00095     }
00096 
00097     function execute() {
00098         global $wgVersion, $wgTitle, $wgLang, $wgAllowSchemaUpdates;
00099 
00100         if ( !$wgAllowSchemaUpdates && !( $this->hasOption( 'force' ) || $this->hasOption( 'schema' ) || $this->hasOption( 'noschema' ) ) ) {
00101             $this->error( "Do not run update.php on this wiki. If you're seeing this you should\n"
00102                 . "probably ask for some help in performing your schema updates or use\n"
00103                 . "the --noschema and --schema options to get an SQL file for someone\n"
00104                 . "else to inspect and run.\n\n"
00105                 . "If you know what you are doing, you can continue with --force\n", true );
00106         }
00107 
00108         $this->fileHandle = null;
00109         if ( substr( $this->getOption( 'schema' ), 0, 2 ) === "--" ) {
00110             $this->error( "The --schema option requires a file as an argument.\n", true );
00111         } elseif ( $this->hasOption( 'schema' ) ) {
00112             $file = $this->getOption( 'schema' );
00113             $this->fileHandle = fopen( $file, "w" );
00114             if ( $this->fileHandle === false ) {
00115                 $err = error_get_last();
00116                 $this->error( "Problem opening the schema file for writing: $file\n\t{$err['message']}", true );
00117             }
00118         }
00119 
00120         $wgLang = Language::factory( 'en' );
00121         $wgTitle = Title::newFromText( "MediaWiki database updater" );
00122 
00123         $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
00124 
00125         wfWaitForSlaves( 5 ); // let's not kill databases, shall we? ;) --tor
00126 
00127         if ( !$this->hasOption( 'skip-compat-checks' ) ) {
00128             $this->compatChecks();
00129         } else {
00130             $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
00131             wfCountdown( 5 );
00132         }
00133 
00134         # Attempt to connect to the database as a privileged user
00135         # This will vomit up an error if there are permissions problems
00136         $db = wfGetDB( DB_MASTER );
00137 
00138         $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
00139         if ( $db->getType() === 'sqlite' ) {
00140             $this->output( "Using SQLite file: '{$db->mDatabaseFile}'\n" );
00141         }
00142         $this->output( "Depending on the size of your database this may take a while!\n" );
00143 
00144         if ( !$this->hasOption( 'quick' ) ) {
00145             $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
00146             wfCountDown( 5 );
00147         }
00148 
00149         $shared = $this->hasOption( 'doshared' );
00150 
00151         $updates = array( 'core', 'extensions' );
00152         if ( !$this->hasOption( 'schema' ) ) {
00153             if ( $this->hasOption( 'noschema' ) ) {
00154                 $updates[] = 'noschema';
00155             }
00156             $updates[] = 'stats';
00157         }
00158 
00159         $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
00160         $updater->doUpdates( $updates );
00161 
00162         foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
00163             $child = $this->runChild( $maint );
00164 
00165             // LoggedUpdateMaintenance is checking the updatelog itself
00166             $isLoggedUpdate = is_a( $child, 'LoggedUpdateMaintenance' );
00167 
00168             if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
00169                 continue;
00170             }
00171 
00172             $child->execute();
00173             if ( !$isLoggedUpdate ) {
00174                 $updater->insertUpdateRow( $maint );
00175             }
00176         }
00177 
00178         if ( !$this->hasOption( 'nopurge' ) ) {
00179             $updater->purgeCache();
00180         }
00181 
00182         $this->output( "\nDone.\n" );
00183     }
00184 
00185     function afterFinalSetup() {
00186         global $wgLocalisationCacheConf;
00187 
00188         # Don't try to access the database
00189         # This needs to be disabled early since extensions will try to use the l10n
00190         # cache from $wgExtensionFunctions (bug 20471)
00191         $wgLocalisationCacheConf = array(
00192             'class' => 'LocalisationCache',
00193             'storeClass' => 'LCStore_Null',
00194             'storeDirectory' => false,
00195             'manualRecache' => false,
00196         );
00197     }
00198 }
00199 
00200 $maintClass = 'UpdateMediaWiki';
00201 require_once RUN_MAINTENANCE_IF_MAIN;