Inject Config and replace global variables

Change-Id: I824ed32728ab4ce8e532734890ac51a4a4527d8a
This commit is contained in:
Fomafix 2022-10-23 09:14:34 +00:00
parent ad9de84501
commit 82cc22a9f2
4 changed files with 16 additions and 11 deletions

View file

@ -3,7 +3,6 @@
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPrivate" />
<exclude name="MediaWiki.Commenting.PropertyDocumentation.MissingDocumentationPrivate" />
<exclude name="MediaWiki.Usage.ExtendClassUsage.FunctionConfigUsage" />
<exclude name="MediaWiki.Usage.ExtendClassUsage.FunctionVarUsage" />
<exclude name="Squiz.Scope.MethodScope.Missing" />
</rule>

View file

@ -77,6 +77,7 @@
"main": {
"class": "MediaWiki\\Extension\\ReplaceText\\Hooks",
"services": [
"MainConfig",
"SpecialPageFactory"
]
}

View file

@ -24,6 +24,7 @@ namespace MediaWiki\Extension\ReplaceText;
use ALItem;
use ALRow;
use ALTree;
use Config;
use MediaWiki\Hook\SpecialMovepageAfterMoveHook;
use MediaWiki\SpecialPage\SpecialPageFactory;
use MediaWiki\User\Hook\UserGetReservedNamesHook;
@ -35,15 +36,21 @@ class Hooks implements
UserGetReservedNamesHook
{
/** @var Config */
private $config;
/** @var SpecialPageFactory */
private $specialPageFactory;
/**
* @param Config $config
* @param SpecialPageFactory $specialPageFactory
*/
public function __construct(
Config $config,
SpecialPageFactory $specialPageFactory
) {
$this->config = $config;
$this->specialPageFactory = $specialPageFactory;
}
@ -94,9 +101,9 @@ class Hooks implements
* @param array &$names
*/
public function onUserGetReservedNames( &$names ) {
global $wgReplaceTextUser;
if ( $wgReplaceTextUser !== null ) {
$names[] = $wgReplaceTextUser;
$replaceTextUser = $this->config->get( 'ReplaceTextUser' );
if ( $replaceTextUser !== null ) {
$names[] = $replaceTextUser;
}
}
}

View file

@ -115,18 +115,16 @@ class SpecialReplaceText extends SpecialPage {
* @param null|string $query
*/
function execute( $query ) {
global $wgCompressRevisions, $wgExternalStores;
if ( !$this->getUser()->isAllowed( 'replacetext' ) ) {
throw new PermissionsError( 'replacetext' );
}
// Replace Text can't be run with certain settings, due to the
// changes they make to the DB storage setup.
if ( $wgCompressRevisions ) {
if ( $this->getConfig()->get( 'CompressRevisions' ) ) {
throw new ErrorPageError( 'replacetext_cfg_error', 'replacetext_no_compress' );
}
if ( !empty( $wgExternalStores ) ) {
if ( !empty( $this->getConfig()->get( 'ExternalStores' ) ) ) {
throw new ErrorPageError( 'replacetext_cfg_error', 'replacetext_no_external_stores' );
}
@ -301,11 +299,11 @@ class SpecialReplaceText extends SpecialPage {
* @return array jobs
*/
function createJobsForTextReplacements() {
global $wgReplaceTextUser;
$replaceTextUser = $this->getConfig()->get( 'ReplaceTextUser' );
$replacement_params = [];
if ( $wgReplaceTextUser != null ) {
$user = $this->userFactory->newFromName( $wgReplaceTextUser );
if ( $replaceTextUser !== null ) {
$user = $this->userFactory->newFromName( $replaceTextUser );
} else {
$user = $this->getUser();
}