Use HookHandlers for AdminLinks hooks

Bug: T271025
Change-Id: Ie4fac4a457eecd64bd5f66628f86cbee9ab9c84f
This commit is contained in:
Umherirrender 2023-08-15 17:18:02 +02:00
parent 2f7bfbed73
commit 203564d43d
4 changed files with 41 additions and 30 deletions

View file

@ -0,0 +1,5 @@
<?php
interface AdminLinksHook {
public function onAdminLinks( ALTree &$admin_links_tree );
}

View file

@ -70,9 +70,7 @@
"MediaWiki\\Extension\\ReplaceText\\": "src/" "MediaWiki\\Extension\\ReplaceText\\": "src/"
}, },
"Hooks": { "Hooks": {
"AdminLinks": [ "AdminLinks": "adminlinks",
"MediaWiki\\Extension\\ReplaceText\\Hooks::addToAdminLinks"
],
"SpecialMovepageAfterMove": "main", "SpecialMovepageAfterMove": "main",
"UserGetReservedNames": "main" "UserGetReservedNames": "main"
}, },
@ -83,6 +81,9 @@
"MainConfig", "MainConfig",
"SpecialPageFactory" "SpecialPageFactory"
] ]
},
"adminlinks": {
"class": "MediaWiki\\Extension\\ReplaceText\\AdminLinksHooks"
} }
}, },
"config": { "config": {

32
src/AdminLinksHooks.php Normal file
View file

@ -0,0 +1,32 @@
<?php
namespace MediaWiki\Extension\ReplaceText;
use AdminLinksHook;
use ALItem;
use ALRow;
use ALTree;
class AdminLinksHooks implements AdminLinksHook {
/**
* Implements AdminLinks hook from Extension:Admin_Links.
*
* @param ALTree &$adminLinksTree
*/
public function onAdminLinks( ALTree &$adminLinksTree ) {
$generalSection = $adminLinksTree->getSection( wfMessage( 'adminlinks_general' )->text() );
if ( !$generalSection ) {
return;
}
$extensionsRow = $generalSection->getRow( 'extensions' );
if ( $extensionsRow === null ) {
$extensionsRow = new ALRow( 'extensions' );
$generalSection->addRow( $extensionsRow );
}
$extensionsRow->addItem( ALItem::newFromSpecialPage( 'ReplaceText' ) );
}
}

View file

@ -21,9 +21,6 @@
*/ */
namespace MediaWiki\Extension\ReplaceText; namespace MediaWiki\Extension\ReplaceText;
use ALItem;
use ALRow;
use ALTree;
use Config; use Config;
use MediaWiki\Hook\SpecialMovepageAfterMoveHook; use MediaWiki\Hook\SpecialMovepageAfterMoveHook;
use MediaWiki\SpecialPage\SpecialPageFactory; use MediaWiki\SpecialPage\SpecialPageFactory;
@ -54,30 +51,6 @@ class Hooks implements
$this->specialPageFactory = $specialPageFactory; $this->specialPageFactory = $specialPageFactory;
} }
/**
* Implements AdminLinks hook from Extension:Admin_Links.
*
* @param ALTree &$adminLinksTree
* @return bool
*/
public static function addToAdminLinks( ALTree &$adminLinksTree ) {
$generalSection = $adminLinksTree->getSection( wfMessage( 'adminlinks_general' )->text() );
if ( !$generalSection ) {
return true;
}
$extensionsRow = $generalSection->getRow( 'extensions' );
if ( $extensionsRow === null ) {
$extensionsRow = new ALRow( 'extensions' );
$generalSection->addRow( $extensionsRow );
}
$extensionsRow->addItem( ALItem::newFromSpecialPage( 'ReplaceText' ) );
return true;
}
/** /**
* Implements SpecialMovepageAfterMove hook. * Implements SpecialMovepageAfterMove hook.
* *