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