mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CiteThisPage
synced 2024-11-23 15:16:46 +00:00
Use HookHandlers for core hooks
Bug: T271012 Change-Id: I8fb93e4989d04dfc20cfda15ae5703267b53ddf1
This commit is contained in:
parent
0206f42765
commit
1d712736ab
|
@ -20,9 +20,12 @@
|
|||
]
|
||||
},
|
||||
"Hooks": {
|
||||
"SidebarBeforeOutput": [
|
||||
"MediaWiki\\Extension\\CiteThisPage\\Hooks::onSidebarBeforeOutput"
|
||||
]
|
||||
"SidebarBeforeOutput": "CiteThisPageHookHandler"
|
||||
},
|
||||
"HookHandlers": {
|
||||
"CiteThisPageHookHandler": {
|
||||
"class": "MediaWiki\\Extension\\CiteThisPage\\Hooks"
|
||||
}
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.citeThisPage": {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue