Until now, we relied on setting MW_NO_SETUP which was a) hacky, b) irreversable, and c) likely to be forgotten if you didn't use one of the wrappers like runChild().
Instead, move the freaky magic to doMaintenance and have *it* check if it's in a specific call stack that indicates this is being run from the file scope and should be executed. Rename DO_MAINTENANCE to RUN_MAINTENANCE_IF_MAIN so it's nice and clear what magic happens behind the require_once().
}
$maintClass = "DemoMaint";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
==END==
public function doUpdates( $purge = true ) {
global $wgVersion;
- if ( !defined( 'MW_NO_SETUP' ) ) {
- define( 'MW_NO_SETUP', true );
- }
-
$this->runUpdates( $this->getCoreUpdateList(), false );
$this->runUpdates( $this->getOldGlobalUpdates(), false );
$this->runUpdates( $this->getExtensionUpdates(), true );
*/
// Define this so scripts can easily find doMaintenance.php
-define( 'DO_MAINTENANCE', dirname( __FILE__ ) . '/doMaintenance.php' );
+define( 'RUN_MAINTENANCE_IF_MAIN', dirname( __FILE__ ) . '/doMaintenance.php' );
+define( 'DO_MAINTENANCE', RUN_MAINTENANCE_IF_MAIN ); // original name, harmless
+
$maintClass = false;
// Make sure we're on PHP5 or better
register_shutdown_function( array( $this, 'outputChanneled' ), false );
}
+ /**
+ * Should we execute the maintenance script, or just allow it to be included
+ * as a standalone class? It checks that the call stack only includes this
+ * function and a require (meaning was called from the file scope)
+ *
+ * @return Boolean
+ */
+ public static function shouldExecute() {
+ $bt = debug_backtrace();
+ if( count( $bt ) !== 2 ) {
+ return false;
+ }
+ return $bt[1]['function'] == 'require_once' &&
+ $bt[0]['class'] == 'Maintenance' &&
+ $bt[0]['function'] == 'shouldExecute';
+ }
+
/**
* Do the actual work. All child classes will need to implement this
*/
* @return Maintenance child
*/
public function runChild( $maintClass, $classFile = null ) {
- // If we haven't already specified, kill setup procedures
- // for child scripts, we've already got a sane environment
- self::disableSetup();
-
// Make sure the class is loaded first
if ( !class_exists( $maintClass ) ) {
if ( $classFile ) {
return $child;
}
- /**
- * Disable Setup.php mostly
- */
- protected static function disableSetup() {
- if ( !defined( 'MW_NO_SETUP' ) ) {
- define( 'MW_NO_SETUP', true );
- }
- }
-
/**
* Do some sanity checking and basic setup
*/
*/
protected static function getCoreScripts() {
if ( !self::$mCoreScripts ) {
- self::disableSetup();
$paths = array(
dirname( __FILE__ ),
dirname( __FILE__ ) . '/gearman',
}
$maintClass = "AddWiki";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "AttachLatest";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'bench_HTTP_HTTPS';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'bench_strtr_str_replace';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'bench_wfIsWindows';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "BenchmarkPurge";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "ChangePassword";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CheckAutoLoader";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CheckBadRedirects";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CheckImages";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CheckSyntax";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CheckUsernames";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CapsCleanup";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "ImageCleanup";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CleanupRemovedModules";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CleanupSpam";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "TitleCleanup";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "WatchlistCleanup";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "ClearInterwikiCache";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "clear_stats";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'CommandLineInc';
-require( DO_MAINTENANCE );
+require( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CompareParsers";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "ConvertLinks";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "ConvertUserOptions";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CreateAndPromote";
-require_once( DO_MAINTENANCE );
\ No newline at end of file
+require_once( RUN_MAINTENANCE_IF_MAIN );
\ No newline at end of file
}
$maintClass = "DeleteArchivedFiles";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DeleteArchivedRevisions";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DeleteBatch";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DeleteDefaultMessages";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DeleteImageCache";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DeleteOldRevisions";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DeleteOrphanedRevisions";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DeleteRevision";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DeleteSelfExternals";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
* @ingroup Maintenance
*/
-if ( !defined( 'DO_MAINTENANCE' ) ) {
+if ( !defined( 'RUN_MAINTENANCE_IF_MAIN' ) ) {
echo "This file must be included after Maintenance.php\n";
exit( 1 );
}
+// Wasn't included from the file scope, halt execution (probably wanted the class)
+if( !Maintenance::shouldExecute() ) {
+ return;
+}
+
if ( !$maintClass || !class_exists( $maintClass ) ) {
echo "\$maintClass is not set or is set to a non-existent class.\n";
exit( 1 );
}
-if ( defined( 'MW_NO_SETUP' ) ) {
- return;
-}
-
// Get an object to start us off
$maintenance = new $maintClass();
}
$maintClass = "DumpInterwiki";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DumpLinks";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DumpSisterSites";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "UploadDumper";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "EditCLI";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "FetchText";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "FindHooks";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "FixSlaveDesync";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "FixTimestamps";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "FixUserRegistration";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "GenerateSitemap";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "GetLagTimes";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "GetSlaveServer";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "GetTextMaint";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "HttpSessionDownload";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'ImportUseModWikipedia';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "InitEditCount";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "InitStats";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
$maintClass = "CommandLineInstaller";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DatabaseLag";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "AllTrans";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "CountMessages";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DateFormats";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "Digit2Html";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DumpMessages";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'GenerateNormalizerData';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "Lang2Po";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "LangMemUsage";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "mcTest";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
}
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
foreach ( $mmfl['setupFiles'] as $fileName ) {
if ( strval( $fileName ) === '' ) {
}
$maintClass = "MigrateUserGroup";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'MinifyScript';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "MoveBatch";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "NamespaceConflictChecker";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "nextJobDb";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "NukeNS";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "NukePage";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "Orphans";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "PatchSql";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "PopulateCategory";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "PopulateLogSearch";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "PopulateLogUsertext";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "PopulateParentId";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "PopulateRevisionLength";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "PopulateSha1";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "Protect";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "PurgeList";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "PurgeOldText";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "ReassignEdits";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RebuildFileCache";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'ImageBuilder';
-require( DO_MAINTENANCE );
+require( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RebuildInterwiki";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RebuildLocalisationCache";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RebuildAll";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RebuildMessages";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RebuildRecentchanges";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RebuildTextIndex";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RefreshImageCount";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'RefreshLinks';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RemoveUnusedAccounts";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RenameDbPrefix";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RenameWiki";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DumpRenderer";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'RollbackEdits';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
$maintClass = "BatchedQueryRunner";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "RunJobs";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "ShowJobs";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "ShowStats";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "MwSql";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "SqliteMaintenance";
-require_once( DO_MAINTENANCE );
\ No newline at end of file
+require_once( RUN_MAINTENANCE_IF_MAIN );
\ No newline at end of file
}
$maintClass = "CacheStats";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "DumpRev";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'FixBug20757';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "OrphanStats";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'StorageTypeStats';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "Undelete";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'UpdateMediaWiki';
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "UpdateArticleCount";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "UpdateCollation";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "UpdateDoubleWidthSearch";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "UpdateRestrictions";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "UpdateSearchIndex";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "UpdateSpecialPages";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = 'FiveUpgrade';
-require( DO_MAINTENANCE );
+require( RUN_MAINTENANCE_IF_MAIN );
}
$maintClass = "WaitForSlave";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );
$maintClass = "SeleniumTester";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );