MediaWiki REL1_37
doMaintenance.php
Go to the documentation of this file.
1<?php
28
29if ( !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 CommandLineInc (old school maintenance), they definitely
36// cannot be included and will proceed with execution
37// @phan-suppress-next-line PhanSuspiciousValueComparisonInGlobalScope
38if ( !Maintenance::shouldExecute() && $maintClass != CommandLineInc::class ) {
39 return;
40}
41
42// @phan-suppress-next-line PhanImpossibleConditionInGlobalScope
43if ( !$maintClass || !class_exists( $maintClass ) ) {
44 echo "\$maintClass is not set or is set to a non-existent class.\n";
45 exit( 1 );
46}
47
48// Define the MediaWiki entrypoint
49define( 'MEDIAWIKI', true );
50
51// This environment variable is ensured present by Maintenance.php.
52$IP = getenv( 'MW_INSTALL_PATH' );
53
54// Get an object to start us off
57
58// Basic sanity checks and such
59$maintenance->setup();
60
61// We used to call this variable $self, but it was moved
62// to $maintenance->mSelf. Keep that here for b/c
63$self = $maintenance->getName();
64
65// Define how settings are loaded (e.g. LocalSettings.php)
66if ( !defined( 'MW_CONFIG_CALLBACK' ) && !defined( 'MW_CONFIG_FILE' ) ) {
67 define( 'MW_CONFIG_FILE', $maintenance->loadSettings() );
68}
69
70// Custom setup for Maintenance entry point
71if ( !defined( 'MW_SETUP_CALLBACK' ) ) {
72
73 function wfMaintenanceSetup() {
75 if ( $maintenance->getDbType() === Maintenance::DB_NONE ) {
76 if ( $wgLocalisationCacheConf['storeClass'] === false
77 && ( $wgLocalisationCacheConf['store'] == 'db'
78 || ( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory ) )
79 ) {
80 $wgLocalisationCacheConf['storeClass'] = LCStoreNull::class;
81 }
82 }
83
84 $maintenance->finalSetup();
85 }
86
87 define( 'MW_SETUP_CALLBACK', 'wfMaintenanceSetup' );
88}
89
90require_once "$IP/includes/Setup.php";
91
92// Initialize main config instance
93$maintenance->setConfig( MediaWikiServices::getInstance()->getMainConfig() );
94
95// Sanity-check required extensions are installed
96$maintenance->checkRequiredExtensions();
97
98if ( $maintenance->getDbType() == Maintenance::DB_NONE ) {
99 // Be strict with maintenance tasks that claim to not need a database by
100 // disabling the storage backend.
101 MediaWikiServices::disableStorageBackend();
102}
103
104$maintenance->validateParamsAndArgs();
105
106// Do the work
107try {
108 $success = $maintenance->execute();
109} catch ( Exception $ex ) {
110 $success = false;
111 $exReportMessage = '';
112 while ( $ex ) {
113 $cls = get_class( $ex );
114 $exReportMessage .= "$cls from line {$ex->getLine()} of {$ex->getFile()}: {$ex->getMessage()}\n";
115 $exReportMessage .= $ex->getTraceAsString() . "\n";
116 $ex = $ex->getPrevious();
117 }
118 // Print the exception to stderr if possible, don't mix it in
119 // with stdout output.
120 if ( defined( 'STDERR' ) ) {
121 fwrite( STDERR, $exReportMessage );
122 } else {
123 echo $exReportMessage;
124 }
125}
126
127// Potentially debug globals
128$maintenance->globals();
129
130$maintenance->shutdown();
131
132// Exit with an error status if execute() returned false
133if ( $success === false ) {
134 exit( 1 );
135}
$wgCacheDirectory
Directory for caching data in the local filesystem.
$wgLocalisationCacheConf
Localisation cache configuration.
$maintClass
const DB_NONE
Constants for DB access type.
static shouldExecute()
Should we execute the maintenance script, or just allow it to be included as a standalone class?...
MediaWikiServices is the service locator for the application scope of MediaWiki.
$maintenance