Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
CRAP | n/a |
0 / 0 |
|
wfMaintenanceSetup | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
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 | * @file |
25 | * @ingroup Maintenance |
26 | */ |
27 | |
28 | use MediaWiki\Maintenance\MaintenanceRunner; |
29 | use MediaWiki\Settings\SettingsBuilder; |
30 | |
31 | // No AutoLoader yet |
32 | require_once __DIR__ . '/includes/MaintenanceRunner.php'; |
33 | require_once __DIR__ . '/includes/MaintenanceParameters.php'; |
34 | |
35 | if ( !defined( 'RUN_MAINTENANCE_IF_MAIN' ) ) { |
36 | echo "This file must be included after Maintenance.php\n"; |
37 | exit( 1 ); |
38 | } |
39 | |
40 | // Wasn't included from the file scope, halt execution (probably wanted the class). |
41 | // This typically happens when a maintenance script is executed using run.php. |
42 | // @phan-suppress-next-line PhanSuspiciousValueComparisonInGlobalScope |
43 | if ( !MaintenanceRunner::shouldExecute() && $maintClass != CommandLineInc::class ) { |
44 | return; |
45 | } |
46 | |
47 | // @phan-suppress-next-line PhanImpossibleConditionInGlobalScope |
48 | if ( !$maintClass || !class_exists( $maintClass ) ) { |
49 | echo "\$maintClass is not set or is set to a non-existent class.\n"; |
50 | exit( 1 ); |
51 | } |
52 | |
53 | // Define the MediaWiki entrypoint |
54 | define( 'MEDIAWIKI', true ); |
55 | |
56 | $IP = wfDetectInstallPath(); |
57 | require_once "$IP/includes/AutoLoader.php"; |
58 | |
59 | $runner = new MaintenanceRunner(); |
60 | $runner->initForClass( $maintClass, $GLOBALS['argv'] ); |
61 | |
62 | // We used to call this variable $self, but it was moved |
63 | // to $maintenance->mSelf. Keep that here for b/c |
64 | $self = $runner->getName(); |
65 | |
66 | $runner->defineSettings(); |
67 | |
68 | // Custom setup for Maintenance entry point |
69 | if ( !defined( 'MW_FINAL_SETUP_CALLBACK' ) ) { |
70 | |
71 | // Define a function, since we can't put a closure or object |
72 | // reference into MW_FINAL_SETUP_CALLBACK. |
73 | function wfMaintenanceSetup( SettingsBuilder $settingsBuilder ) { |
74 | global $runner; |
75 | $runner->setup( $settingsBuilder ); |
76 | } |
77 | |
78 | define( 'MW_FINAL_SETUP_CALLBACK', 'wfMaintenanceSetup' ); |
79 | } |
80 | |
81 | // Initialize MediaWiki (load settings, initialized session, |
82 | // enable MediaWikiServices) |
83 | require_once "$IP/includes/Setup.php"; |
84 | |
85 | // We only get here if the script was invoked directly. |
86 | // If it was loaded by MaintenanceRunner, MaintenanceRunner::shouldExecute() would have returned false, |
87 | // and we would have returned from this file early. |
88 | |
89 | if ( stream_isatty( STDOUT ) ) { |
90 | echo "\n"; |
91 | echo "*******************************************************************************\n"; |
92 | echo "NOTE: Do not run maintenance scripts directly, use maintenance/run.php instead!\n"; |
93 | echo " Running scripts directly has been deprecated in MediaWiki 1.40.\n"; |
94 | echo " It may not work for some (or any) scripts in the future.\n"; |
95 | echo "*******************************************************************************\n"; |
96 | echo "\n"; |
97 | } |
98 | |
99 | // Do it! |
100 | $success = $runner->run(); |
101 | |
102 | // Exit with an error status if execute() returned false |
103 | if ( !$success ) { |
104 | exit( 1 ); |
105 | } |