Ensure $collationConds is defined on all paths
[lhc/web/wiklou.git] / maintenance / doMaintenance.php
1 <?php
2 /**
3 * We want to make this whole thing as seamless as possible to the
4 * end-user. Unfortunately, we can't do _all_ of the work in the class
5 * because A) included files are not in global scope, but in the scope
6 * of their caller, and B) MediaWiki has way too many globals. So instead
7 * we'll kinda fake it, and do the requires() inline. <3 PHP
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @author Chad Horohoe <chad@anyonecanedit.org>
25 * @file
26 * @ingroup Maintenance
27 */
28
29 if ( !defined( 'RUN_MAINTENANCE_IF_MAIN' ) ) {
30 echo "This file must be included after Maintenance.php\n";
31 exit( 1 );
32 }
33
34 // Wasn't included from the file scope, halt execution (probably wanted the class)
35 // If a class is using commandLine.inc (old school maintenance), they definitely
36 // cannot be included and will proceed with execution
37 if( !Maintenance::shouldExecute() && $maintClass != 'CommandLineInc' ) {
38 return;
39 }
40
41 if ( !$maintClass || !class_exists( $maintClass ) ) {
42 echo "\$maintClass is not set or is set to a non-existent class.\n";
43 exit( 1 );
44 }
45
46 // Get an object to start us off
47 $maintenance = new $maintClass();
48
49 // Basic sanity checks and such
50 $maintenance->setup();
51
52 // We used to call this variable $self, but it was moved
53 // to $maintenance->mSelf. Keep that here for b/c
54 $self = $maintenance->getName();
55
56 // Detect compiled mode
57 try {
58 $r = new ReflectionFunction( 'wfHipHopCompilerVersion' );
59 } catch ( ReflectionException $e ) {
60 $r = false;
61 }
62
63 if ( $r ) {
64 define( 'MW_COMPILED', 1 );
65 }
66
67 # Get the MWInit class
68 if ( !defined( 'MW_COMPILED' ) ) {
69 require_once( "$IP/includes/Init.php" );
70 }
71
72 # Setup the profiler
73 global $IP;
74 if ( !defined( 'MW_COMPILED' ) && file_exists( "$IP/StartProfiler.php" ) ) {
75 require_once( "$IP/StartProfiler.php" );
76 } else {
77 require_once( MWInit::compiledPath( 'includes/ProfilerStub.php' ) );
78 }
79
80 // Some other requires
81 if ( !defined( 'MW_COMPILED' ) ) {
82 require_once( "$IP/includes/AutoLoader.php" );
83 require_once( "$IP/includes/Defines.php" );
84 }
85 require_once( "$IP/includes/DefaultSettings.php" );
86
87 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
88 # Use a callback function to configure MediaWiki
89 MWFunction::call( MW_CONFIG_CALLBACK );
90 } elseif ( file_exists( "$IP/wmf-config/wikimedia-mode" ) ) {
91 // Load settings, using wikimedia-mode if needed
92 // Fixme: replace this hack with general farm-friendly code
93 # TODO FIXME! Wikimedia-specific stuff needs to go away to an ext
94 # Maybe a hook?
95 global $cluster;
96 $wgWikiFarm = true;
97 $cluster = 'pmtpa';
98 require_once( MWInit::compiledPath( 'includes/SiteConfiguration.php' ) );
99 require( MWInit::interpretedPath( 'wmf-config/wgConf.php' ) );
100 $maintenance->loadWikimediaSettings();
101 require( MWInit::interpretedPath( '/wmf-config/CommonSettings.php' ) );
102 } else {
103 require_once( $maintenance->loadSettings() );
104 }
105
106 if ( $maintenance->getDbType() === Maintenance::DB_ADMIN &&
107 is_readable( "$IP/AdminSettings.php" ) )
108 {
109 require( MWInit::interpretedPath( 'AdminSettings.php' ) );
110 }
111 $maintenance->finalSetup();
112 // Some last includes
113 require_once( MWInit::compiledPath( 'includes/Setup.php' ) );
114 require_once( MWInit::compiledPath( 'maintenance/install-utils.inc' ) );
115
116 // Much much faster startup than creating a title object
117 $wgTitle = null;
118
119 // Do the work
120 try {
121 $maintenance->execute();
122
123 // Potentially debug globals
124 $maintenance->globals();
125 } catch ( MWException $mwe ) {
126 echo( $mwe->getText() );
127 exit( 1 );
128 }
129