mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CiteThisPage
synced 2024-11-15 19:49:46 +00:00
12623a5acd
The SkinTemplateToolboxEnd hook is nasty and requires echo-ing raw HTML. It also has the problem that if there are any other extensions using that hook, the CiteThisPage link will easily end up in the wrong place and under the wrong heading. This is trivial to fix though by using the BaseTemplateToolbox hook, which is designed for actually adding links to the toolbox! Bug: T140290 Change-Id: I9557130c40e17edc12a225a3b7b1cdec028f93d0
45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
||
|
||
class CiteThisPageHooks {
|
||
|
||
/**
|
||
* @param SkinTemplate $skintemplate
|
||
* @param $nav_urls
|
||
* @param $oldid
|
||
* @param $revid
|
||
* @return bool
|
||
*/
|
||
public static function onSkinTemplateBuildNavUrlsNav_urlsAfterPermalink(
|
||
&$skintemplate, &$nav_urls, &$oldid, &$revid
|
||
) {
|
||
// check whether we’re in the right namespace, the $revid has the correct type and is not empty
|
||
// (which would mean that the current page doesn’t exist)
|
||
$title = $skintemplate->getTitle();
|
||
if ( $title->isContentPage() && $revid !== 0 && !empty( $revid ) ) {
|
||
$nav_urls['citethispage'] = [
|
||
'text' => $skintemplate->msg( 'citethispage-link' )->text(),
|
||
'href' => SpecialPage::getTitleFor( 'CiteThisPage' )
|
||
->getLocalURL( [ 'page' => $title->getPrefixedDBkey(), 'id' => $revid ] ),
|
||
'id' => 't-cite',
|
||
# Used message keys: 'tooltip-citethispage', 'accesskey-citethispage'
|
||
'single-id' => 'citethispage',
|
||
];
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* @param BaseTemplate $baseTemplate
|
||
* @param array $toolbox
|
||
* @return bool
|
||
*/
|
||
public static function onBaseTemplateToolbox( BaseTemplate $baseTemplate, array &$toolbox ) {
|
||
if ( isset( $baseTemplate->data['nav_urls']['citethispage'] ) ) {
|
||
$toolbox['citethispage'] = $baseTemplate->data['nav_urls']['citethispage'];
|
||
}
|
||
|
||
return true;
|
||
}
|
||
}
|