Use HookHandlers for core hooks

Bug: T271012
Change-Id: I8fb93e4989d04dfc20cfda15ae5703267b53ddf1
This commit is contained in:
Umherirrender 2021-04-08 20:01:31 +02:00 committed by Jforrester
parent 0206f42765
commit 1d712736ab
2 changed files with 16 additions and 16 deletions

View file

@ -20,9 +20,12 @@
]
},
"Hooks": {
"SidebarBeforeOutput": [
"MediaWiki\\Extension\\CiteThisPage\\Hooks::onSidebarBeforeOutput"
]
"SidebarBeforeOutput": "CiteThisPageHookHandler"
},
"HookHandlers": {
"CiteThisPageHookHandler": {
"class": "MediaWiki\\Extension\\CiteThisPage\\Hooks"
}
},
"ResourceModules": {
"ext.citeThisPage": {

View file

@ -2,39 +2,36 @@
namespace MediaWiki\Extension\CiteThisPage;
use Skin;
use Config;
use SpecialPage;
use Title;
class Hooks {
class Hooks implements \MediaWiki\Hook\SidebarBeforeOutputHook {
/**
* Checks, if the "cite this page" link should be added. By default the link is added to all
* pages in the main namespace, and additionally to pages, which are in one of the namespaces
* named in $wgCiteThisPageAddiotionalNamespaces.
*
* @param Title $title
* @param Config $config
* @return bool
*/
private static function shouldAddLink( Title $title ) {
global $wgCiteThisPageAdditionalNamespaces;
private static function shouldAddLink( Title $title, Config $config ) {
$additionalNamespaces = $config->get( 'CiteThisPageAdditionalNamespaces' );
return $title->isContentPage() ||
(
isset( $wgCiteThisPageAdditionalNamespaces[$title->getNamespace()] ) &&
$wgCiteThisPageAdditionalNamespaces[$title->getNamespace()]
isset( $additionalNamespaces[$title->getNamespace()] ) &&
$additionalNamespaces[$title->getNamespace()]
);
}
/**
* @param Skin $skin
* @param string[] &$sidebar
* @return void
*/
public static function onSidebarBeforeOutput( Skin $skin, array &$sidebar ): void {
/** @inheritDoc */
public function onSidebarBeforeOutput( $skin, &$sidebar ): void {
$out = $skin->getOutput();
$title = $out->getTitle();
if ( !self::shouldAddLink( $title ) ) {
if ( !self::shouldAddLink( $title, $out->getConfig() ) ) {
return;
}