Maintenance scripts: replace most globals with Config
Bug: T72673 Change-Id: Idc46e88756b1aa20f5dccbe7ab3e661b2b102964
This commit is contained in:
parent
aa1e699779
commit
cd99df60ed
10 changed files with 44 additions and 37 deletions
|
|
@ -25,6 +25,7 @@
|
|||
* @ingroup Maintenance
|
||||
*/
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
|
@ -44,15 +45,13 @@ class CleanupUploadStash extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
global $wgUploadStashMaxAge;
|
||||
|
||||
$repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
|
||||
$tempRepo = $repo->getTempRepo();
|
||||
|
||||
$dbr = $repo->getReplicaDB();
|
||||
|
||||
// how far back should this look for files to delete?
|
||||
$cutoff = time() - $wgUploadStashMaxAge;
|
||||
$cutoff = time() - (int)$this->getConfig()->get( MainConfigNames::UploadStashMaxAge );
|
||||
|
||||
$this->output( "Getting list of files to clean up...\n" );
|
||||
$res = $dbr->select(
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
* @ingroup Maintenance
|
||||
*/
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
/**
|
||||
|
|
@ -36,7 +38,6 @@ class ClearInterwikiCache extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
global $wgLocalDatabases;
|
||||
$dbr = $this->getDB( DB_REPLICA );
|
||||
$cache = ObjectCache::getLocalClusterInstance();
|
||||
$res = $dbr->select( 'interwiki', [ 'iw_prefix' ], '', __METHOD__ );
|
||||
|
|
@ -45,7 +46,7 @@ class ClearInterwikiCache extends Maintenance {
|
|||
$prefixes[] = $row->iw_prefix;
|
||||
}
|
||||
|
||||
foreach ( $wgLocalDatabases as $wikiId ) {
|
||||
foreach ( $this->getConfig()->get( MainConfigNames::LocalDatabases ) as $wikiId ) {
|
||||
$this->output( "$wikiId..." );
|
||||
foreach ( $prefixes as $prefix ) {
|
||||
$cache->delete( "$wikiId:interwiki:$prefix" );
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
* @ingroup Maintenance
|
||||
*/
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
/**
|
||||
|
|
@ -37,15 +39,14 @@ class DeleteSelfExternals extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
global $wgServer;
|
||||
|
||||
// Extract the host and scheme from $wgServer
|
||||
$bits = wfParseUrl( $wgServer );
|
||||
$server = $this->getConfig()->get( MainConfigNames::Server );
|
||||
$bits = wfParseUrl( $server );
|
||||
if ( !$bits ) {
|
||||
$this->fatalError( 'Could not parse $wgServer' );
|
||||
}
|
||||
|
||||
$this->output( "Deleting self externals from $wgServer\n" );
|
||||
$this->output( "Deleting self externals from $server\n" );
|
||||
$db = $this->getDB( DB_PRIMARY );
|
||||
|
||||
// If it's protocol-relative, we need to do both http and https.
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
*/
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use Wikimedia\Purtle\RdfWriter;
|
||||
use Wikimedia\Purtle\RdfWriterFactory;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
|
@ -116,8 +118,7 @@ class DumpCategoriesAsRdf extends Maintenance {
|
|||
* @param int $timestamp
|
||||
*/
|
||||
public function addDumpHeader( $timestamp ) {
|
||||
global $wgRightsUrl;
|
||||
$licenseUrl = $wgRightsUrl;
|
||||
$licenseUrl = $this->getConfig()->get( MainConfigNames::RightsUrl );
|
||||
if ( substr( $licenseUrl, 0, 2 ) == '//' ) {
|
||||
$licenseUrl = 'https:' . $licenseUrl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
* @see http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
|
||||
*/
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
use Wikimedia\Rdbms\IResultWrapper;
|
||||
|
|
@ -207,7 +208,7 @@ class GenerateSitemap extends Maintenance {
|
|||
}
|
||||
|
||||
private function setNamespacePriorities() {
|
||||
global $wgSitemapNamespacesPriorities;
|
||||
$sitemapNamespacesPriorities = $this->getConfig()->get( MainConfigNames::SitemapNamespacesPriorities );
|
||||
|
||||
// Custom main namespaces
|
||||
$this->priorities[self::GS_MAIN] = '0.5';
|
||||
|
|
@ -232,11 +233,11 @@ class GenerateSitemap extends Maintenance {
|
|||
$this->priorities[NS_CATEGORY_TALK] = '0.1';
|
||||
|
||||
// Custom priorities
|
||||
if ( $wgSitemapNamespacesPriorities !== false ) {
|
||||
if ( $sitemapNamespacesPriorities !== false ) {
|
||||
/**
|
||||
* @var array $wgSitemapNamespacesPriorities
|
||||
* @var array $sitemapNamespacesPriorities
|
||||
*/
|
||||
foreach ( $wgSitemapNamespacesPriorities as $namespace => $priority ) {
|
||||
foreach ( $sitemapNamespacesPriorities as $namespace => $priority ) {
|
||||
$float = floatval( $priority );
|
||||
if ( $float > 1.0 ) {
|
||||
$priority = '1.0';
|
||||
|
|
@ -253,9 +254,9 @@ class GenerateSitemap extends Maintenance {
|
|||
*/
|
||||
private function generateNamespaces() {
|
||||
// Only generate for specific namespaces if $wgSitemapNamespaces is an array.
|
||||
global $wgSitemapNamespaces;
|
||||
if ( is_array( $wgSitemapNamespaces ) ) {
|
||||
$this->namespaces = $wgSitemapNamespaces;
|
||||
$sitemapNamespaces = $this->getConfig()->get( MainConfigNames::SitemapNamespaces );
|
||||
if ( is_array( $sitemapNamespaces ) ) {
|
||||
$this->namespaces = $sitemapNamespaces;
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
class ImportImages extends Maintenance {
|
||||
|
|
@ -125,8 +126,6 @@ class ImportImages extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
global $wgFileExtensions, $wgRestrictionLevels;
|
||||
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$permissionManager = $services->getPermissionManager();
|
||||
|
||||
|
|
@ -148,7 +147,7 @@ class ImportImages extends Maintenance {
|
|||
# Prepare the list of allowed extensions
|
||||
$extensions = $this->hasOption( 'extensions' )
|
||||
? explode( ',', strtolower( $this->getOption( 'extensions' ) ) )
|
||||
: $wgFileExtensions;
|
||||
: $this->getConfig()->get( MainConfigNames::FileExtensions );
|
||||
|
||||
# Search the path provided for candidates for import
|
||||
$files = $this->findFiles( $dir, $extensions, $this->hasOption( 'search-recursively' ) );
|
||||
|
|
@ -364,8 +363,9 @@ class ImportImages extends Maintenance {
|
|||
$doProtect = false;
|
||||
|
||||
$protectLevel = $this->getOption( 'protect' );
|
||||
$restrictionLevels = $this->getConfig()->get( MainConfigNames::RestrictionLevels );
|
||||
|
||||
if ( $protectLevel && in_array( $protectLevel, $wgRestrictionLevels ) ) {
|
||||
if ( $protectLevel && in_array( $protectLevel, $restrictionLevels ) ) {
|
||||
$doProtect = true;
|
||||
}
|
||||
if ( $this->hasOption( 'unprotect' ) ) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
* @ingroup Maintenance
|
||||
*/
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
/**
|
||||
|
|
@ -45,14 +47,15 @@ class McTest extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
global $wgObjectCaches, $wgMainCacheType;
|
||||
$config = $this->getConfig();
|
||||
$objectCaches = $config->get( MainConfigNames::ObjectCaches );
|
||||
|
||||
$cacheType = $this->getOption( 'cache', $wgMainCacheType );
|
||||
$cacheType = $this->getOption( 'cache', $config->get( MainConfigNames::MainCacheType ) );
|
||||
$iterations = $this->getOption( 'i', 100 );
|
||||
$classOverride = $this->getOption( 'class' );
|
||||
$server = $this->getArg( 0 );
|
||||
|
||||
if ( !isset( $wgObjectCaches[$cacheType] ) ) {
|
||||
if ( !isset( $objectCaches[$cacheType] ) ) {
|
||||
$this->fatalError( "No configured '$cacheType' cache" );
|
||||
}
|
||||
|
||||
|
|
@ -62,14 +65,14 @@ class McTest extends Maintenance {
|
|||
}
|
||||
$class = $classOverride;
|
||||
} else {
|
||||
$class = $wgObjectCaches[$cacheType]['class'];
|
||||
$class = $objectCaches[$cacheType]['class'];
|
||||
}
|
||||
|
||||
if ( $server !== null ) {
|
||||
$servers = [ $server ];
|
||||
} else {
|
||||
// Note that some caches, like apcu, do not have a server list
|
||||
$servers = $wgObjectCaches[$cacheType]['servers'] ?? [ null ];
|
||||
$servers = $objectCaches[$cacheType]['servers'] ?? [ null ];
|
||||
}
|
||||
|
||||
// Use longest server string for output alignment
|
||||
|
|
@ -79,7 +82,7 @@ class McTest extends Maintenance {
|
|||
/** @var BagOStuff[] $cacheByServer */
|
||||
$cacheByServer = [];
|
||||
foreach ( $servers as $server ) {
|
||||
$conf = $wgObjectCaches[$cacheType];
|
||||
$conf = $objectCaches[$cacheType];
|
||||
if ( $server !== null ) {
|
||||
$conf['servers'] = [ $server ];
|
||||
$host = $server;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Timestamp\ConvertibleTimestamp;
|
||||
|
||||
|
|
@ -68,14 +69,14 @@ class PurgeParserCache extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
global $wgParserCacheExpireTime;
|
||||
|
||||
$inputDate = $this->getOption( 'expiredate' );
|
||||
$inputAge = $this->getOption( 'age' );
|
||||
|
||||
if ( $inputDate !== null ) {
|
||||
$timestamp = strtotime( $inputDate );
|
||||
} elseif ( $inputAge !== null ) {
|
||||
$timestamp = time() + $wgParserCacheExpireTime - intval( $inputAge );
|
||||
$expireTime = (int)$this->getConfig()->get( MainConfigNames::ParserCacheExpireTime );
|
||||
$timestamp = time() + $expireTime - intval( $inputAge );
|
||||
} else {
|
||||
$this->fatalError( "Must specify either --expiredate or --age" );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,8 +93,6 @@ class RebuildLocalisationCache extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
global $wgLocalisationCacheConf, $wgCacheDirectory;
|
||||
|
||||
$force = $this->hasOption( 'force' );
|
||||
$threads = $this->getOption( 'threads', 1 );
|
||||
if ( $threads < 1 || $threads != intval( $threads ) ) {
|
||||
|
|
@ -110,7 +108,7 @@ class RebuildLocalisationCache extends Maintenance {
|
|||
$threads = 1;
|
||||
}
|
||||
|
||||
$conf = $wgLocalisationCacheConf;
|
||||
$conf = $this->getConfig()->get( MainConfigNames::LocalisationCacheConf );
|
||||
// Allow fallbacks to create CDB files
|
||||
$conf['manualRecache'] = false;
|
||||
$conf['forceRecache'] = $force || !empty( $conf['forceRecache'] );
|
||||
|
|
@ -130,7 +128,7 @@ class RebuildLocalisationCache extends Maintenance {
|
|||
$conf,
|
||||
$services->getMainConfig()
|
||||
),
|
||||
LocalisationCache::getStoreFromConf( $conf, $wgCacheDirectory ),
|
||||
LocalisationCache::getStoreFromConf( $conf, $this->getConfig()->get( MainConfigNames::CacheDirectory ) ),
|
||||
LoggerFactory::getInstance( 'localisation' ),
|
||||
$this->hasOption( 'skip-message-purge' ) ? [] :
|
||||
[ static function () use ( $services ) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
* @ingroup Maintenance
|
||||
*/
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
/**
|
||||
|
|
@ -42,7 +44,7 @@ class RenameDbPrefix extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
global $wgDBname;
|
||||
$dbName = $this->getConfig()->get( MainConfigNames::DBname );
|
||||
|
||||
// Allow for no old prefix
|
||||
if ( $this->getOption( 'old', 0 ) === '0' ) {
|
||||
|
|
@ -68,7 +70,7 @@ class RenameDbPrefix extends Maintenance {
|
|||
$this->output( "Same prefix. Nothing to rename!\n", true );
|
||||
}
|
||||
|
||||
$this->output( "Renaming DB prefix for tables of $wgDBname from '$old' to '$new'\n" );
|
||||
$this->output( "Renaming DB prefix for tables of $dbName from '$old' to '$new'\n" );
|
||||
$count = 0;
|
||||
|
||||
$dbw = $this->getDB( DB_PRIMARY );
|
||||
|
|
|
|||
Loading…
Reference in a new issue