MediaWiki  REL1_20
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         echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP 5.3.2 or higher. ABORTING.\n" .
00030         "Check if you have a newer php executable with a different name, such as php5.\n";
00031         die( 1 );
00032 }
00033 
00034 $wgUseMasterForMaintenance = true;
00035 require_once( __DIR__ . '/Maintenance.php' );
00036 
00042 class UpdateMediaWiki extends Maintenance {
00043 
00044         function __construct() {
00045                 parent::__construct();
00046                 $this->mDescription = "MediaWiki database updater";
00047                 $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
00048                 $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
00049                 $this->addOption( 'doshared', 'Also update shared tables' );
00050                 $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
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' ) ) {
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.\n\n"
00089                                 . "If you know what you are doing, you can continue with --force", true );
00090                 }
00091 
00092                 $wgLang = Language::factory( 'en' );
00093                 $wgTitle = Title::newFromText( "MediaWiki database updater" );
00094 
00095                 $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
00096 
00097                 wfWaitForSlaves( 5 ); // let's not kill databases, shall we? ;) --tor
00098 
00099                 if ( !$this->hasOption( 'skip-compat-checks' ) ) {
00100                         $this->compatChecks();
00101                 } else {
00102                         $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
00103                         wfCountdown( 5 );
00104                 }
00105 
00106                 # Attempt to connect to the database as a privileged user
00107                 # This will vomit up an error if there are permissions problems
00108                 $db = wfGetDB( DB_MASTER );
00109 
00110                 $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
00111                 $this->output( "Depending on the size of your database this may take a while!\n" );
00112 
00113                 if ( !$this->hasOption( 'quick' ) ) {
00114                         $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
00115                         wfCountDown( 5 );
00116                 }
00117 
00118                 $shared = $this->hasOption( 'doshared' );
00119 
00120                 $updates = array( 'core', 'extensions', 'stats' );
00121                 if( !$this->hasOption('nopurge') ) {
00122                         $updates[] = 'purge';
00123                 }
00124 
00125                 $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
00126                 $updater->doUpdates( $updates );
00127 
00128                 foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
00129                         if ( $updater->updateRowExists( $maint ) ) {
00130                                 continue;
00131                         }
00132                         $child = $this->runChild( $maint );
00133                         $child->execute();
00134                         $updater->insertUpdateRow( $maint );
00135                 }
00136 
00137                 $this->output( "\nDone.\n" );
00138         }
00139 
00140         function afterFinalSetup() {
00141                 global $wgLocalisationCacheConf;
00142 
00143                 # Don't try to access the database
00144                 # This needs to be disabled early since extensions will try to use the l10n
00145                 # cache from $wgExtensionFunctions (bug 20471)
00146                 $wgLocalisationCacheConf = array(
00147                         'class' => 'LocalisationCache',
00148                         'storeClass' => 'LCStore_Null',
00149                         'storeDirectory' => false,
00150                         'manualRecache' => false,
00151                 );
00152         }
00153 }
00154 
00155 $maintClass = 'UpdateMediaWiki';
00156 require_once( RUN_MAINTENANCE_IF_MAIN );