mediawiki-extensions-CiteTh.../CiteThisPage.hooks.php
Kunal Mehta 12623a5acd Use BaseTemplateToolbox hook so link appears in the right place
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
2016-07-13 15:27:14 -07:00

45 lines
1.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 were in the right namespace, the $revid has the correct type and is not empty
// (which would mean that the current page doesnt 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;
}
}