* (bug 28945) Keyboard shortcuts on history page no longer work in 1.18
[lhc/web/wiklou.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 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @file
24 * @todo document
25 * @ingroup Maintenance
26 */
27
28 // Include global constants, including MW_VERSION and MW_MIN_PHP_VERSION
29 require_once( dirname( dirname( __FILE__ ) ) . '/includes/Defines.php' );
30
31 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ) ) {
32 echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP " .
33 MW_MIN_PHP_VERSION . "or higher. ABORTING.\n" .
34 "Check if you have a newer php executable with a different name, such as php5.\n";
35 die( 1 );
36 }
37
38 $wgUseMasterForMaintenance = true;
39 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
40
41 class UpdateMediaWiki extends Maintenance {
42
43 function __construct() {
44 parent::__construct();
45 $this->mDescription = "MediaWiki database updater";
46 $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
47 $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
48 $this->addOption( 'doshared', 'Also update shared tables' );
49 $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
50 }
51
52 function getDbType() {
53 /* If we used the class constant PHP4 would give a parser error here */
54 return 2 /* Maintenance::DB_ADMIN */;
55 }
56
57 function compatChecks() {
58 $test = new PhpXmlBugTester();
59 if ( !$test->ok ) {
60 $this->error(
61 "Your system has a combination of PHP and libxml2 versions which is buggy\n" .
62 "and can cause hidden data corruption in MediaWiki and other web apps.\n" .
63 "Upgrade to PHP 5.2.9 or later and libxml2 2.7.3 or later!\n" .
64 "ABORTING (see http://bugs.php.net/bug.php?id=45996).\n",
65 true );
66 }
67
68 $test = new PhpRefCallBugTester;
69 $test->execute();
70 if ( !$test->ok ) {
71 $ver = phpversion();
72 $this->error(
73 "PHP $ver is not compatible with MediaWiki due to a bug involving\n" .
74 "reference parameters to __call. Upgrade to PHP 5.3.2 or higher, or \n" .
75 "downgrade to PHP 5.3.0 to fix this.\n" .
76 "ABORTING (see http://bugs.php.net/bug.php?id=50394 for details)\n",
77 true );
78 }
79 }
80
81 function execute() {
82 global $wgVersion, $wgTitle, $wgLang;
83
84 $wgLang = Language::factory( 'en' );
85 $wgTitle = Title::newFromText( "MediaWiki database updater" );
86
87 $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
88
89 if ( !$this->hasOption( 'skip-compat-checks' ) ) {
90 $this->compatChecks();
91 } else {
92 $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
93 wfCountdown( 5 );
94 }
95
96 # Attempt to connect to the database as a privileged user
97 # This will vomit up an error if there are permissions problems
98 $db = wfGetDB( DB_MASTER );
99
100 $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
101 $this->output( "Depending on the size of your database this may take a while!\n" );
102
103 if ( !$this->hasOption( 'quick' ) ) {
104 $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
105 wfCountDown( 5 );
106 }
107
108 $shared = $this->hasOption( 'doshared' );
109
110 $updates = array('core','extensions');
111 if( !$this->hasOption('nopurge') ) {
112 $updates[] = 'purge';
113 }
114
115 $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
116 $updater->doUpdates( $updates );
117
118 foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
119 $child = $this->runChild( $maint );
120 $child->execute();
121 }
122
123 $this->output( "\nDone.\n" );
124 }
125
126 function afterFinalSetup() {
127 global $wgLocalisationCacheConf;
128
129 # Don't try to access the database
130 # This needs to be disabled early since extensions will try to use the l10n
131 # cache from $wgExtensionFunctions (bug 20471)
132 $wgLocalisationCacheConf = array(
133 'class' => 'LocalisationCache',
134 'storeClass' => 'LCStore_Null',
135 'storeDirectory' => false,
136 'manualRecache' => false,
137 );
138 }
139 }
140
141 $maintClass = 'UpdateMediaWiki';
142 require_once( RUN_MAINTENANCE_IF_MAIN );