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
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.
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.
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
24 * @author Chad Horohoe <chad@anyonecanedit.org>
26 * @ingroup Maintenance
28 use MediaWiki\MediaWikiServices
;
30 if ( !defined( 'RUN_MAINTENANCE_IF_MAIN' ) ) {
31 echo "This file must be included after Maintenance.php\n";
35 // Wasn't included from the file scope, halt execution (probably wanted the class)
36 // If a class is using commandLine.inc (old school maintenance), they definitely
37 // cannot be included and will proceed with execution
38 if ( !Maintenance
::shouldExecute() && $maintClass != 'CommandLineInc' ) {
42 if ( !$maintClass ||
!class_exists( $maintClass ) ) {
43 echo "\$maintClass is not set or is set to a non-existent class.\n";
47 // Get an object to start us off
48 /** @var Maintenance $maintenance */
49 $maintenance = new $maintClass();
51 // Basic sanity checks and such
52 $maintenance->setup();
54 // We used to call this variable $self, but it was moved
55 // to $maintenance->mSelf. Keep that here for b/c
56 $self = $maintenance->getName();
58 # Start the autoloader, so that extensions can derive classes from core files
59 require_once "$IP/includes/AutoLoader.php";
60 # Grab profiling functions
61 require_once "$IP/includes/profiler/ProfilerFunctions.php";
65 if ( file_exists( "$IP/StartProfiler.php" ) ) {
66 require "$IP/StartProfiler.php";
69 // Some other requires
70 require_once "$IP/includes/Defines.php";
71 require_once "$IP/includes/DefaultSettings.php";
72 require_once "$IP/includes/GlobalFunctions.php";
74 # Load composer's autoloader if present
75 if ( is_readable( "$IP/vendor/autoload.php" ) ) {
76 require_once "$IP/vendor/autoload.php";
79 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
80 # Use a callback function to configure MediaWiki
81 call_user_func( MW_CONFIG_CALLBACK
);
83 // Require the configuration (probably LocalSettings.php)
84 require $maintenance->loadSettings();
87 if ( $maintenance->getDbType() === Maintenance
::DB_NONE
) {
88 if ( $wgLocalisationCacheConf['storeClass'] === false
89 && ( $wgLocalisationCacheConf['store'] == 'db'
90 ||
( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory ) )
92 $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';
96 $maintenance->finalSetup();
98 require_once "$IP/includes/Setup.php";
100 // Initialize main config instance
101 $maintenance->setConfig( MediaWikiServices
::getInstance()->getMainConfig() );
103 // Sanity-check required extensions are installed
104 $maintenance->checkRequiredExtensions();
106 // A good time when no DBs have writes pending is around lag checks.
107 // This avoids having long running scripts just OOM and lose all the updates.
108 $maintenance->setAgentAndTriggers();
111 $maintenance->execute();
113 // Potentially debug globals
114 $maintenance->globals();
116 // Perform deferred updates.
117 $lbFactory = MediaWikiServices
::getInstance()->getDBLoadBalancerFactory();
118 $lbFactory->commitMasterChanges( $maintClass );
119 DeferredUpdates
::doUpdates();
121 // log profiling info
122 wfLogProfilingData();
124 // Commit and close up!
125 $lbFactory->commitMasterChanges( 'doMaintenance' );
126 $lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT
);