MediaWiki
master
doMaintenance.php
Go to the documentation of this file.
1
<?php
27
use
MediaWiki\MediaWikiServices
;
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
56
$maintenance
=
new
$maintClass
();
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() {
74
global
$maintenance
,
$wgLocalisationCacheConf
,
$wgCacheDirectory
;
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
}
else
{
103
// A good time when no DBs have writes pending is around lag checks.
104
// This avoids having long running scripts just OOM and lose all the updates.
105
$maintenance
->setAgentAndTriggers();
106
}
107
108
$maintenance
->validateParamsAndArgs();
109
110
// Do the work
111
try
{
112
$success
=
$maintenance
->execute();
113
}
catch
( Exception $ex ) {
114
$success
=
false
;
115
$exReportMessage =
''
;
116
while
( $ex ) {
117
$cls = get_class( $ex );
118
$exReportMessage .=
"$cls from line {$ex->getLine()} of {$ex->getFile()}: {$ex->getMessage()}\n"
;
119
$exReportMessage .= $ex->getTraceAsString() .
"\n"
;
120
$ex = $ex->getPrevious();
121
}
122
// Print the exception to stderr if possible, don't mix it in
123
// with stdout output.
124
if
( defined(
'STDERR'
) ) {
125
fwrite( STDERR, $exReportMessage );
126
}
else
{
127
echo $exReportMessage;
128
}
129
}
130
131
// Potentially debug globals
132
$maintenance
->globals();
133
134
$maintenance
->shutdown();
135
136
// Exit with an error status if execute() returned false
137
if
(
$success
===
false
) {
138
exit( 1 );
139
}
$maintClass
$maintClass
Definition:
addChangeTag.php:62
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition:
MediaWikiServices.php:173
$wgCacheDirectory
$wgCacheDirectory
Directory for caching data in the local filesystem.
Definition:
DefaultSettings.php:2510
$success
$success
Definition:
NoLocalSettings.php:42
$wgLocalisationCacheConf
$wgLocalisationCacheConf
Localisation cache configuration.
Definition:
DefaultSettings.php:2850
$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:188
Maintenance\DB_NONE
const DB_NONE
Constants for DB access type.
Definition:
Maintenance.php:60
$IP
$IP
Definition:
doMaintenance.php:52
$self
$self
Definition:
doMaintenance.php:63
maintenance
doMaintenance.php
Generated on Sat Mar 20 2021 18:10:38 for MediaWiki by
1.8.19