]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/update.php
MediaWiki 1.17.0-scripts
[autoinstallsdev/mediawiki.git] / maintenance / update.php
1 <?php
2 /**
3  * Run all updaters.
4  *
5  * This is used when the database schema is modified and we need to apply patches.
6  * It is kept compatible with php 4 parsing so that it can give out a meaningful error.
7  *
8  * @file
9  * @todo document
10  * @ingroup Maintenance
11  */
12
13 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.2.3' ) < 0 ) ) {
14         echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP 5.2.3 or higher. ABORTING.\n" .
15         "Check if you have a newer php executable with a different name, such as php5.\n";
16         die( 1 );
17 }
18
19 $wgUseMasterForMaintenance = true;
20 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
21
22 class UpdateMediaWiki extends Maintenance {
23
24         function __construct() {
25                 parent::__construct();
26                 $this->mDescription = "MediaWiki database updater";
27                 $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
28                 $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
29                 $this->addOption( 'doshared', 'Also update shared tables' );
30                 $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
31         }
32
33         function getDbType() {
34                 /* If we used the class constant PHP4 would give a parser error here */
35                 return 2 /* Maintenance::DB_ADMIN */;
36         }
37
38         function compatChecks() {
39                 $test = new PhpXmlBugTester();
40                 if ( !$test->ok ) {
41                         $this->error(
42                                 "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
43                                 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
44                                 "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
45                                 "ABORTING (see http://bugs.php.net/bug.php?id=45996).\n",
46                                 true );
47                 }
48
49                 $test = new PhpRefCallBugTester;
50                 $test->execute();
51                 if ( !$test->ok ) {
52                         $ver = phpversion();
53                         $this->error(
54                                 "PHP $ver is not compatible with MediaWiki due to a bug involving\n" .
55                                 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
56                                 "downgrade to PHP 5.3.0 to fix this.\n" .
57                                 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n",
58                                 true );
59                 }
60         }
61
62         function execute() {
63                 global $wgVersion, $wgTitle, $wgLang;
64
65                 $wgLang = Language::factory( 'en' );
66                 $wgTitle = Title::newFromText( "MediaWiki database updater" );
67
68                 $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
69
70                 if ( !$this->hasOption( 'skip-compat-checks' ) ) {
71                         $this->compatChecks();
72                 } else {
73                         $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
74                         wfCountdown( 5 );
75                 }
76
77                 # Attempt to connect to the database as a privileged user
78                 # This will vomit up an error if there are permissions problems
79                 $db = wfGetDB( DB_MASTER );
80
81                 $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
82                 $this->output( "Depending on the size of your database this may take a while!\n" );
83
84                 if ( !$this->hasOption( 'quick' ) ) {
85                         $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
86                         wfCountDown( 5 );
87                 }
88
89                 $shared = $this->hasOption( 'doshared' );
90
91                 $updates = array('core','extensions');
92                 if( !$this->hasOption('nopurge') ) {
93                         $updates[] = 'purge';
94                 }
95
96                 $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
97                 $updater->doUpdates( $updates );
98
99                 foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
100                         $child = $this->runChild( $maint );
101                         $child->execute();
102                 }
103
104                 $this->output( "\nDone.\n" );
105         }
106
107         function afterFinalSetup() {
108                 global $wgLocalisationCacheConf;
109
110                 # Don't try to access the database
111                 # This needs to be disabled early since extensions will try to use the l10n
112                 # cache from $wgExtensionFunctions (bug 20471)
113                 $wgLocalisationCacheConf = array(
114                         'class' => 'LocalisationCache',
115                         'storeClass' => 'LCStore_Null',
116                         'storeDirectory' => false,
117                         'manualRecache' => false,
118                 );
119         }
120 }
121
122 $maintClass = 'UpdateMediaWiki';
123 require_once( RUN_MAINTENANCE_IF_MAIN );