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