MediaWiki  REL1_19
update.php
Go to the documentation of this file.
00001 <?php
00028 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.2.3' ) < 0 ) ) {
00029         echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP 5.2.3 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( dirname( __FILE__ ) . '/Maintenance.php' );
00036 
00037 class UpdateMediaWiki extends Maintenance {
00038 
00039         function __construct() {
00040                 parent::__construct();
00041                 $this->mDescription = "MediaWiki database updater";
00042                 $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
00043                 $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
00044                 $this->addOption( 'doshared', 'Also update shared tables' );
00045                 $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
00046                 $this->addOption( 'force', 'Override when $wgAllowSchemaUpdates disables this script' );
00047         }
00048 
00049         function getDbType() {
00050                 /* If we used the class constant PHP4 would give a parser error here */
00051                 return 2 /* Maintenance::DB_ADMIN */;
00052         }
00053 
00054         function compatChecks() {
00055                 $test = new PhpXmlBugTester();
00056                 if ( !$test->ok ) {
00057                         $this->error(
00058                                 "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
00059                                 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
00060                                 "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
00061                                 "ABORTING (see http://bugs.php.net/bug.php?id=45996).\n",
00062                                 true );
00063                 }
00064 
00065                 $test = new PhpRefCallBugTester;
00066                 $test->execute();
00067                 if ( !$test->ok ) {
00068                         $ver = phpversion();
00069                         $this->error(
00070                                 "PHP $ver is not compatible with MediaWiki due to a bug involving\n" .
00071                                 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
00072                                 "downgrade to PHP 5.3.0 to fix this.\n" .
00073                                 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n",
00074                                 true );
00075                 }
00076         }
00077 
00078         function execute() {
00079                 global $wgVersion, $wgTitle, $wgLang, $wgAllowSchemaUpdates;
00080 
00081                 if( !$wgAllowSchemaUpdates && !$this->hasOption( 'force' ) ) {
00082                         $this->error( "Do not run update.php on this wiki. If you're seeing this you should\n"
00083                                 . "probably ask for some help in performing your schema updates.\n\n"
00084                                 . "If you know what you are doing, you can continue with --force", true );
00085                 }
00086 
00087                 $wgLang = Language::factory( 'en' );
00088                 $wgTitle = Title::newFromText( "MediaWiki database updater" );
00089 
00090                 $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
00091 
00092                 wfWaitForSlaves( 5 ); // let's not kill databases, shall we? ;) --tor
00093 
00094                 if ( !$this->hasOption( 'skip-compat-checks' ) ) {
00095                         $this->compatChecks();
00096                 } else {
00097                         $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
00098                         wfCountdown( 5 );
00099                 }
00100 
00101                 # Attempt to connect to the database as a privileged user
00102                 # This will vomit up an error if there are permissions problems
00103                 $db = wfGetDB( DB_MASTER );
00104 
00105                 $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
00106                 $this->output( "Depending on the size of your database this may take a while!\n" );
00107 
00108                 if ( !$this->hasOption( 'quick' ) ) {
00109                         $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
00110                         wfCountDown( 5 );
00111                 }
00112 
00113                 $shared = $this->hasOption( 'doshared' );
00114 
00115                 $updates = array( 'core', 'extensions', 'stats' );
00116                 if( !$this->hasOption('nopurge') ) {
00117                         $updates[] = 'purge';
00118                 }
00119 
00120                 $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
00121                 $updater->doUpdates( $updates );
00122 
00123                 foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
00124                         if ( $updater->updateRowExists( $maint ) ) {
00125                                 continue;
00126                         }
00127                         $child = $this->runChild( $maint );
00128                         $child->execute();
00129                         $updater->insertUpdateRow( $maint );
00130                 }
00131 
00132                 $this->output( "\nDone.\n" );
00133         }
00134 
00135         function afterFinalSetup() {
00136                 global $wgLocalisationCacheConf;
00137 
00138                 # Don't try to access the database
00139                 # This needs to be disabled early since extensions will try to use the l10n
00140                 # cache from $wgExtensionFunctions (bug 20471)
00141                 $wgLocalisationCacheConf = array(
00142                         'class' => 'LocalisationCache',
00143                         'storeClass' => 'LCStore_Null',
00144                         'storeDirectory' => false,
00145                         'manualRecache' => false,
00146                 );
00147         }
00148 }
00149 
00150 $maintClass = 'UpdateMediaWiki';
00151 require_once( RUN_MAINTENANCE_IF_MAIN );