diff --git a/includes/Helpers/ManageWikiExtensions.php b/includes/Helpers/ManageWikiExtensions.php index 92b43c487..037d2ad1f 100644 --- a/includes/Helpers/ManageWikiExtensions.php +++ b/includes/Helpers/ManageWikiExtensions.php @@ -3,6 +3,7 @@ namespace Miraheze\ManageWiki\Helpers; use MediaWiki\Config\Config; +use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\DBConnRef; @@ -55,9 +56,17 @@ public function __construct( string $wiki ) { ] )->s_extensions ?? '[]'; + $logger = LoggerFactory::getInstance( 'ManageWiki' ); + // To simplify clean up and to reduce the need to constantly refer back to many different variables, we now // populate extension lists with config associated with them. foreach ( json_decode( $exts, true ) as $ext ) { + if ( !isset( $this->extConfig[$ext] ) ) { + $logger->error( 'Extension/Skin {ext} not set in wgManageWikiExtensions', [ + 'ext' => $ext, + ] ); + continue; + } $this->liveExts[$ext] = $this->extConfig[$ext]; } } @@ -90,16 +99,17 @@ public function add( $extensions ) { /** * Removes an extension from the 'enabled' list * @param string|string[] $extensions Either an array or string of extensions to disable + * @param bool $forceRemove Force removing extension incase it is removed from config */ - public function remove( $extensions ) { + public function remove( $extensions, $forceRemove = false ) { // We allow remove either one extension (string) or many (array) // We will handle all processing in final stages foreach ( (array)$extensions as $ext ) { - if ( !isset( $this->liveExts[$ext] ) ) { + if ( !isset( $this->liveExts[$ext] ) && !$forceRemove ) { continue; } - $this->removedExts[$ext] = $this->liveExts[$ext]; + $this->removedExts[$ext] = $this->liveExts[$ext] ?? []; unset( $this->liveExts[$ext] ); $this->changes[$ext] = [ diff --git a/includes/Hooks.php b/includes/Hooks.php index 0044c3fec..94465faea 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -80,7 +80,7 @@ public static function onCreateWikiDataFactoryBuilder( string $wiki, IReadableDa $cacheArray['extensions'][] = $manageWikiExtensions[$ext]['var'] ?? $manageWikiExtensions[$ext]['name']; } else { - $logger->error( 'Extension {ext} not set in wgManageWikiExtensions', [ + $logger->error( 'Extension/Skin {ext} not set in wgManageWikiExtensions', [ 'ext' => $ext, ] ); } diff --git a/maintenance/toggleExtension.php b/maintenance/toggleExtension.php index 4a05586c3..1babb0359 100644 --- a/maintenance/toggleExtension.php +++ b/maintenance/toggleExtension.php @@ -24,11 +24,13 @@ public function __construct() { $this->addOption( 'all-wikis', 'Run on all wikis present in $wgLocalDatabases.' ); $this->addOption( 'confirm', 'Confirm execution. Required if using --all-wikis' ); $this->addOption( 'no-list', 'Don\'t list on which wikis this script has ran. This may speed up execution.' ); + $this->addOption( 'force-remove', 'Force removal of extension when not in config.' ); $this->requireExtension( 'ManageWiki' ); } public function execute() { + $forceRemove = $this->getOption( 'force-remove', false ); $noList = $this->getOption( 'no-list', false ); $allWikis = $this->getOption( 'all-wikis', false ); $wikis = $allWikis ? @@ -46,7 +48,7 @@ public function execute() { $mwExt = new ManageWikiExtensions( $wiki ); $extensionList = $mwExt->list(); if ( $disable && in_array( $ext, $extensionList ) ) { - $mwExt->remove( $ext ); + $mwExt->remove( $ext, $forceRemove ); $mwExt->commit(); if ( !$noList ) { $this->output( "Removed $ext from $wiki" );