MediaWiki
REL1_24
|
00001 #!/usr/bin/env php 00002 <?php 00029 if ( !function_exists( 'version_compare' ) || ( version_compare( PHP_VERSION, '5.3.2' ) < 0 ) ) { 00030 require dirname( __FILE__ ) . '/../includes/PHPVersionError.php'; 00031 wfPHPVersionError( 'cli' ); 00032 } 00033 00034 $wgUseMasterForMaintenance = true; 00035 require_once __DIR__ . '/Maintenance.php'; 00036 00042 class UpdateMediaWiki extends Maintenance { 00043 function __construct() { 00044 parent::__construct(); 00045 $this->mDescription = "MediaWiki database updater"; 00046 $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' ); 00047 $this->addOption( 'quick', 'Skip 5 second countdown before starting' ); 00048 $this->addOption( 'doshared', 'Also update shared tables' ); 00049 $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' ); 00050 $this->addOption( 'noschema', 'Only do the updates that are not done during schema updates' ); 00051 $this->addOption( 00052 'schema', 00053 'Output SQL to do the schema updates instead of doing them. Works ' 00054 . 'even when $wgAllowSchemaUpdates is false', 00055 false, 00056 true 00057 ); 00058 $this->addOption( 'force', 'Override when $wgAllowSchemaUpdates disables this script' ); 00059 } 00060 00061 function getDbType() { 00062 /* If we used the class constant PHP4 would give a parser error here */ 00063 return 2; /* Maintenance::DB_ADMIN */ 00064 } 00065 00066 function compatChecks() { 00067 // Avoid syntax error in PHP4 00068 $minimumPcreVersion = constant( 'Installer::MINIMUM_PCRE_VERSION' ); 00069 00070 list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 ); 00071 if ( version_compare( $pcreVersion, $minimumPcreVersion, '<' ) ) { 00072 $this->error( 00073 "PCRE $minimumPcreVersion or later is required.\n" . 00074 "Your PHP binary is linked with PCRE $pcreVersion.\n\n" . 00075 "More information:\n" . 00076 "https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" . 00077 "ABORTING.\n", 00078 true ); 00079 } 00080 00081 $test = new PhpXmlBugTester(); 00082 if ( !$test->ok ) { 00083 $this->error( 00084 "Your system has a combination of PHP and libxml2 versions that is buggy\n" . 00085 "and can cause hidden data corruption in MediaWiki and other web apps.\n" . 00086 "Upgrade to libxml2 2.7.3 or later.\n" . 00087 "ABORTING (see https://bugs.php.net/bug.php?id=45996).\n", 00088 true ); 00089 } 00090 } 00091 00092 function execute() { 00093 global $wgVersion, $wgLang, $wgAllowSchemaUpdates; 00094 00095 if ( !$wgAllowSchemaUpdates 00096 && !( $this->hasOption( 'force' ) 00097 || $this->hasOption( 'schema' ) 00098 || $this->hasOption( 'noschema' ) ) 00099 ) { 00100 $this->error( "Do not run update.php on this wiki. If you're seeing this you should\n" 00101 . "probably ask for some help in performing your schema updates or use\n" 00102 . "the --noschema and --schema options to get an SQL file for someone\n" 00103 . "else to inspect and run.\n\n" 00104 . "If you know what you are doing, you can continue with --force\n", true ); 00105 } 00106 00107 $this->fileHandle = null; 00108 if ( substr( $this->getOption( 'schema' ), 0, 2 ) === "--" ) { 00109 $this->error( "The --schema option requires a file as an argument.\n", true ); 00110 } elseif ( $this->hasOption( 'schema' ) ) { 00111 $file = $this->getOption( 'schema' ); 00112 $this->fileHandle = fopen( $file, "w" ); 00113 if ( $this->fileHandle === false ) { 00114 $err = error_get_last(); 00115 $this->error( "Problem opening the schema file for writing: $file\n\t{$err['message']}", true ); 00116 } 00117 } 00118 00119 $wgLang = Language::factory( 'en' ); 00120 00121 define( 'MW_UPDATER', true ); 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 " 00146 . "(skip this countdown with --quick) ... " ); 00147 wfCountDown( 5 ); 00148 } 00149 00150 $time1 = new MWTimestamp(); 00151 00152 $shared = $this->hasOption( 'doshared' ); 00153 00154 $updates = array( 'core', 'extensions' ); 00155 if ( !$this->hasOption( 'schema' ) ) { 00156 if ( $this->hasOption( 'noschema' ) ) { 00157 $updates[] = 'noschema'; 00158 } 00159 $updates[] = 'stats'; 00160 } 00161 00162 $updater = DatabaseUpdater::newForDb( $db, $shared, $this ); 00163 $updater->doUpdates( $updates ); 00164 00165 foreach ( $updater->getPostDatabaseUpdateMaintenance() as $maint ) { 00166 $child = $this->runChild( $maint ); 00167 00168 // LoggedUpdateMaintenance is checking the updatelog itself 00169 $isLoggedUpdate = is_a( $child, 'LoggedUpdateMaintenance' ); 00170 00171 if ( !$isLoggedUpdate && $updater->updateRowExists( $maint ) ) { 00172 continue; 00173 } 00174 00175 $child->execute(); 00176 if ( !$isLoggedUpdate ) { 00177 $updater->insertUpdateRow( $maint ); 00178 } 00179 } 00180 00181 if ( !$this->hasOption( 'nopurge' ) ) { 00182 $updater->purgeCache(); 00183 } 00184 $time2 = new MWTimestamp(); 00185 00186 $timeDiff = $time2->diff( $time1 ); 00187 $this->output( "\nDone in " . $timeDiff->format( "%i:%S" ) . ".\n" ); 00188 } 00189 00190 function afterFinalSetup() { 00191 global $wgLocalisationCacheConf; 00192 00193 # Don't try to access the database 00194 # This needs to be disabled early since extensions will try to use the l10n 00195 # cache from $wgExtensionFunctions (bug 20471) 00196 $wgLocalisationCacheConf = array( 00197 'class' => 'LocalisationCache', 00198 'storeClass' => 'LCStoreNull', 00199 'storeDirectory' => false, 00200 'manualRecache' => false, 00201 ); 00202 } 00203 } 00204 00205 $maintClass = 'UpdateMediaWiki'; 00206 require_once RUN_MAINTENANCE_IF_MAIN;