MediaWiki  REL1_21
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                 $test = new PhpXmlBugTester();
00061                 if ( !$test->ok ) {
00062                         $this->error(
00063                                 "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
00064                                 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
00065                                 "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
00066                                 "ABORTING (see http://bugs.php.net/bug.php?id=45996).\n",
00067                                 true );
00068                 }
00069 
00070                 $test = new PhpRefCallBugTester;
00071                 $test->execute();
00072                 if ( !$test->ok ) {
00073                         $ver = phpversion();
00074                         $this->error(
00075                                 "PHP $ver is not compatible with MediaWiki due to a bug involving\n" .
00076                                 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
00077                                 "downgrade to PHP 5.3.0 to fix this.\n" .
00078                                 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n",
00079                                 true );
00080                 }
00081         }
00082 
00083         function execute() {
00084                 global $wgVersion, $wgTitle, $wgLang, $wgAllowSchemaUpdates;
00085 
00086                 if( !$wgAllowSchemaUpdates && !( $this->hasOption( 'force' ) || $this->hasOption( 'schema' ) || $this->hasOption( 'noschema' ) ) ) {
00087                         $this->error( "Do not run update.php on this wiki. If you're seeing this you should\n"
00088                                 . "probably ask for some help in performing your schema updates or use\n"
00089                                 . "the --noschema and --schema options to get an SQL file for someone\n"
00090                                 . "else to inspect and run.\n\n"
00091                                 . "If you know what you are doing, you can continue with --force\n", true );
00092                 }
00093 
00094                 $this->fileHandle = null;
00095                 if( substr( $this->getOption( 'schema' ), 0, 2 ) === "--" ) {
00096                         $this->error( "The --schema option requires a file as an argument.\n", true );
00097                 } else if( $this->hasOption( 'schema' ) ) {
00098                         $file = $this->getOption( 'schema' );
00099                         $this->fileHandle = fopen( $file, "w" );
00100                         if( $this->fileHandle === false ) {
00101                                 $err = error_get_last();
00102                                 $this->error( "Problem opening the schema file for writing: $file\n\t{$err['message']}", true );
00103                         }
00104                 }
00105 
00106                 $wgLang = Language::factory( 'en' );
00107                 $wgTitle = Title::newFromText( "MediaWiki database updater" );
00108 
00109                 $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
00110 
00111                 wfWaitForSlaves( 5 ); // let's not kill databases, shall we? ;) --tor
00112 
00113                 if ( !$this->hasOption( 'skip-compat-checks' ) ) {
00114                         $this->compatChecks();
00115                 } else {
00116                         $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
00117                         wfCountdown( 5 );
00118                 }
00119 
00120                 # Attempt to connect to the database as a privileged user
00121                 # This will vomit up an error if there are permissions problems
00122                 $db = wfGetDB( DB_MASTER );
00123 
00124                 $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
00125                 if( $db->getType() === 'sqlite' ) {
00126                         $this->output( "Using SQLite file: '{$db->mDatabaseFile}'\n" );
00127                 }
00128                 $this->output( "Depending on the size of your database this may take a while!\n" );
00129 
00130                 if ( !$this->hasOption( 'quick' ) ) {
00131                         $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
00132                         wfCountDown( 5 );
00133                 }
00134 
00135                 $shared = $this->hasOption( 'doshared' );
00136 
00137                 $updates = array( 'core', 'extensions' );
00138                 if( !$this->hasOption('schema') ) {
00139                         if( $this->hasOption('noschema') ) {
00140                                 $updates[] = 'noschema';
00141                         }
00142                         $updates[] = 'stats';
00143 
00144                         if( !$this->hasOption('nopurge') ) {
00145                                 $updates[] = 'purge';
00146                         }
00147                 }
00148 
00149                 $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
00150                 $updater->doUpdates( $updates );
00151 
00152                 foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
00153                         $child = $this->runChild( $maint );
00154 
00155                         // LoggedUpdateMaintenance is checking the updatelog itself
00156                         $isLoggedUpdate = is_a( $child, 'LoggedUpdateMaintenance' );
00157 
00158                         if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) {
00159                                 continue;
00160                         }
00161 
00162                         $child = $this->runChild( $maint );
00163                         $child->execute();
00164                         if ( !$isLoggedUpdate ) {
00165                                 $updater->insertUpdateRow( $maint );
00166                         }
00167                 }
00168 
00169                 if( !$this->hasOption('nopurge') ) {
00170                         $updater->purgeCache();
00171                 }
00172 
00173                 $this->output( "\nDone.\n" );
00174         }
00175 
00176         function afterFinalSetup() {
00177                 global $wgLocalisationCacheConf;
00178 
00179                 # Don't try to access the database
00180                 # This needs to be disabled early since extensions will try to use the l10n
00181                 # cache from $wgExtensionFunctions (bug 20471)
00182                 $wgLocalisationCacheConf = array(
00183                         'class' => 'LocalisationCache',
00184                         'storeClass' => 'LCStore_Null',
00185                         'storeDirectory' => false,
00186                         'manualRecache' => false,
00187                 );
00188         }
00189 }
00190 
00191 $maintClass = 'UpdateMediaWiki';
00192 require_once( RUN_MAINTENANCE_IF_MAIN );