MediaWiki  master
doMaintenance.php
Go to the documentation of this file.
1 <?php
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 CommandLineInc (old school maintenance), they definitely
36 // cannot be included and will proceed with execution
37 // @phan-suppress-next-line PhanSuspiciousValueComparisonInGlobalScope
38 if ( !Maintenance::shouldExecute() && $maintClass != CommandLineInc::class ) {
39  return;
40 }
41 
42 // @phan-suppress-next-line PhanImpossibleConditionInGlobalScope
43 if ( !$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
49 define( '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)
66 if ( !defined( 'MW_CONFIG_CALLBACK' ) && !defined( 'MW_CONFIG_FILE' ) ) {
67  define( 'MW_CONFIG_FILE', $maintenance->loadSettings() );
68 }
69 
70 // Custom setup for Maintenance entry point
71 if ( !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 
90 require_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 
98 if ( $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
107 try {
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
133 if ( $success === false ) {
134  exit( 1 );
135 }
$maintClass
$maintClass
Definition: addChangeTag.php:62
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:185
$wgCacheDirectory
$wgCacheDirectory
Directory for caching data in the local filesystem.
Definition: DefaultSettings.php:2741
$success
$success
Definition: NoLocalSettings.php:42
$wgLocalisationCacheConf
$wgLocalisationCacheConf
Localisation cache configuration.
Definition: DefaultSettings.php:3083
$maintenance
$maintenance
Definition: doMaintenance.php:56
Maintenance\shouldExecute
static shouldExecute()
Should we execute the maintenance script, or just allow it to be included as a standalone class?...
Definition: Maintenance.php:192
Maintenance\DB_NONE
const DB_NONE
Constants for DB access type.
Definition: Maintenance.php:64
$IP
$IP
Definition: doMaintenance.php:52
$self
$self
Definition: doMaintenance.php:63