2009-08-02 19:35:17 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* We want to make this whole thing as seamless as possible to the
|
|
|
|
|
* end-user. Unfortunately, we can't do _all_ of the work in the class
|
2010-06-30 04:25:23 +00:00
|
|
|
* because A) included files are not in global scope, but in the scope
|
2009-08-02 19:35:17 +00:00
|
|
|
* of their caller, and B) MediaWiki has way too many globals. So instead
|
|
|
|
|
* we'll kinda fake it, and do the requires() inline. <3 PHP
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2022-04-15 21:10:43 +00:00
|
|
|
|
|
|
|
|
use MediaWiki\Maintenance\MaintenanceRunner;
|
2022-01-26 17:46:06 +00:00
|
|
|
use MediaWiki\Settings\SettingsBuilder;
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2022-04-15 21:10:43 +00:00
|
|
|
// No AutoLoader yet
|
|
|
|
|
require_once __DIR__ . '/includes/MaintenanceRunner.php';
|
2022-04-09 20:31:25 +00:00
|
|
|
require_once __DIR__ . '/includes/MaintenanceParameters.php';
|
2022-04-15 21:10:43 +00:00
|
|
|
|
2011-01-13 22:58:55 +00:00
|
|
|
if ( !defined( 'RUN_MAINTENANCE_IF_MAIN' ) ) {
|
2009-09-04 06:51:38 +00:00
|
|
|
echo "This file must be included after Maintenance.php\n";
|
|
|
|
|
exit( 1 );
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 18:35:44 +00:00
|
|
|
// Wasn't included from the file scope, halt execution (probably wanted the class).
|
|
|
|
|
// This typically happens when a maintenance script is executed using run.php.
|
2020-06-15 10:46:22 +00:00
|
|
|
// @phan-suppress-next-line PhanSuspiciousValueComparisonInGlobalScope
|
2022-04-15 22:20:41 +00:00
|
|
|
if ( !MaintenanceRunner::shouldExecute() && $maintClass != CommandLineInc::class ) {
|
2011-01-13 22:58:55 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-15 10:46:22 +00:00
|
|
|
// @phan-suppress-next-line PhanImpossibleConditionInGlobalScope
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( !$maintClass || !class_exists( $maintClass ) ) {
|
2010-01-25 03:46:31 +00:00
|
|
|
echo "\$maintClass is not set or is set to a non-existent class.\n";
|
2009-09-04 06:51:38 +00:00
|
|
|
exit( 1 );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-12 20:29:32 +00:00
|
|
|
// Define the MediaWiki entrypoint
|
|
|
|
|
define( 'MEDIAWIKI', true );
|
|
|
|
|
|
2022-04-27 19:33:22 +00:00
|
|
|
$IP = wfDetectInstallPath();
|
2023-01-19 07:56:30 +00:00
|
|
|
require_once "$IP/includes/AutoLoader.php";
|
2020-04-12 20:29:32 +00:00
|
|
|
|
2022-04-15 21:10:43 +00:00
|
|
|
$runner = new MaintenanceRunner();
|
2022-07-31 10:39:13 +00:00
|
|
|
$runner->initForClass( $maintClass, $GLOBALS['argv'] );
|
2010-11-27 15:35:57 +00:00
|
|
|
|
|
|
|
|
// We used to call this variable $self, but it was moved
|
|
|
|
|
// to $maintenance->mSelf. Keep that here for b/c
|
2022-04-15 21:10:43 +00:00
|
|
|
$self = $runner->getName();
|
2010-11-27 15:35:57 +00:00
|
|
|
|
2022-04-15 21:10:43 +00:00
|
|
|
$runner->defineSettings();
|
2010-06-27 21:48:51 +00:00
|
|
|
|
2017-09-19 19:24:19 +00:00
|
|
|
// Custom setup for Maintenance entry point
|
2022-07-31 10:39:13 +00:00
|
|
|
if ( !defined( 'MW_FINAL_SETUP_CALLBACK' ) ) {
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2022-04-15 21:10:43 +00:00
|
|
|
// Define a function, since we can't put a closure or object
|
2022-07-31 10:39:13 +00:00
|
|
|
// reference into MW_FINAL_SETUP_CALLBACK.
|
2022-01-26 17:46:06 +00:00
|
|
|
function wfMaintenanceSetup( SettingsBuilder $settingsBuilder ) {
|
2022-04-15 21:10:43 +00:00
|
|
|
global $runner;
|
2022-07-31 10:39:13 +00:00
|
|
|
$runner->setup( $settingsBuilder );
|
2013-04-18 18:48:44 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2022-07-31 10:39:13 +00:00
|
|
|
define( 'MW_FINAL_SETUP_CALLBACK', 'wfMaintenanceSetup' );
|
2012-06-26 16:58:37 +00:00
|
|
|
}
|
2014-08-07 20:57:14 +00:00
|
|
|
|
2022-04-15 21:10:43 +00:00
|
|
|
// Initialize MediaWiki (load settings, initialized session,
|
|
|
|
|
// enable MediaWikiServices)
|
2013-08-08 03:18:34 +00:00
|
|
|
require_once "$IP/includes/Setup.php";
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2023-01-03 18:35:44 +00:00
|
|
|
// We only get here if the script was invoked directly.
|
|
|
|
|
// If it was loaded by MaintenanceRunner, MaintenanceRunner::shouldExecute() would have returned false,
|
|
|
|
|
// and we would have returned from this file early.
|
|
|
|
|
|
2023-01-09 07:34:20 +00:00
|
|
|
if ( stream_isatty( STDOUT ) ) {
|
|
|
|
|
echo "\n";
|
|
|
|
|
echo "*******************************************************************************\n";
|
|
|
|
|
echo "NOTE: Do not run maintenance scripts directly, use maintenance/run.php instead!\n";
|
|
|
|
|
echo " Running scripts directly has been deprecated in MediaWiki 1.40.\n";
|
|
|
|
|
echo " It may not work for some (or any) scripts in the future.\n";
|
|
|
|
|
echo "*******************************************************************************\n";
|
|
|
|
|
echo "\n";
|
|
|
|
|
}
|
2023-01-03 18:35:44 +00:00
|
|
|
|
|
|
|
|
// Do it!
|
2022-04-15 21:10:43 +00:00
|
|
|
$success = $runner->run();
|
2022-04-08 17:15:43 +00:00
|
|
|
|
2022-04-15 21:10:43 +00:00
|
|
|
// Exit with an error status if execute() returned false
|
|
|
|
|
if ( !$success ) {
|
2022-04-08 17:15:43 +00:00
|
|
|
exit( 1 );
|
2018-12-09 21:22:17 +00:00
|
|
|
}
|