mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CiteThisPage
synced 2024-11-14 19:25:08 +00:00
Use SidebarBeforeOutput hook to add 'cite this page' sidebar link.
* Remove usage of BaseTemplateToolbox in favor of SidebarBeforeOutput hook * Also remove SkinTemplateBuildNavUrlsNav_urlsAfterPermalink hook, since SidebarBeforeOutput can provide functionalities of both. Bug: T253687 Depens-On: Ie10a59048cdf882bad811d3c8fae386d90e93867 Change-Id: Ibe989364b9e500497759e79b789667d0a3430828
This commit is contained in:
parent
f927278d05
commit
b9bdc3fc19
|
@ -20,8 +20,9 @@
|
|||
]
|
||||
},
|
||||
"Hooks": {
|
||||
"SkinTemplateBuildNavUrlsNav_urlsAfterPermalink": "CiteThisPageHooks::onSkinTemplateBuildNavUrlsNav_urlsAfterPermalink",
|
||||
"BaseTemplateToolbox": "CiteThisPageHooks::onBaseTemplateToolbox"
|
||||
"SidebarBeforeOutput": [
|
||||
"CiteThisPageHooks::onSidebarBeforeOutput"
|
||||
]
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.citeThisPage": {
|
||||
|
|
|
@ -1,35 +1,6 @@
|
|||
<?php
|
||||
|
||||
class CiteThisPageHooks {
|
||||
|
||||
/**
|
||||
* @param SkinTemplate &$skintemplate
|
||||
* @param array &$nav_urls
|
||||
* @param int &$oldid
|
||||
* @param int &$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 ( self::shouldAddLink( $title ) && $revid !== 0 && !empty( $revid ) ) {
|
||||
$nav_urls['citethispage'] = [
|
||||
'text' => $skintemplate->msg( 'citethispage-link' )->text(),
|
||||
'href' => SpecialPage::getTitleFor( 'CiteThisPage' )
|
||||
->getLocalURL( [ 'page' => $title->getPrefixedDBkey(), 'id' => $revid,
|
||||
'wpFormIdentifier' => 'titleform' ] ),
|
||||
'id' => 't-cite',
|
||||
# Used message keys: 'tooltip-citethispage', 'accesskey-citethispage'
|
||||
'single-id' => 'citethispage',
|
||||
];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -49,15 +20,43 @@ class CiteThisPageHooks {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param BaseTemplate $baseTemplate
|
||||
* @param array &$toolbox
|
||||
* @param Skin $skin
|
||||
* @param string[] &$sidebar
|
||||
* @return bool
|
||||
*/
|
||||
public static function onBaseTemplateToolbox( BaseTemplate $baseTemplate, array &$toolbox ) {
|
||||
if ( isset( $baseTemplate->data['nav_urls']['citethispage'] ) ) {
|
||||
$toolbox['citethispage'] = $baseTemplate->data['nav_urls']['citethispage'];
|
||||
public static function onSidebarBeforeOutput( Skin $skin, array &$sidebar ) {
|
||||
$out = $skin->getOutput();
|
||||
$title = $out->getTitle();
|
||||
|
||||
if ( !self::shouldAddLink( $title ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
$revid = $out->getRevisionId();
|
||||
|
||||
if ( $revid !== 0 && !empty( $revid ) ) {
|
||||
$specialPage = SpecialPage::getTitleFor( 'CiteThisPage' );
|
||||
$citeURL = $specialPage->getLocalURL( [
|
||||
'page' => $title->getPrefixedDBkey(),
|
||||
'id' => $revid,
|
||||
'wpFormIdentifier' => 'titleform'
|
||||
]
|
||||
);
|
||||
|
||||
$citeThisPageLink = [
|
||||
'id' => 't-cite',
|
||||
'href' => $citeURL,
|
||||
'text' => $skin->msg( 'citethispage-link' )->text(),
|
||||
// Message keys: 'tooltip-citethispage', 'accesskey-citethispage'
|
||||
'single-id' => 'citethispage',
|
||||
];
|
||||
|
||||
// Append link
|
||||
$sidebar['TOOLBOX']['citethispage'] = $citeThisPageLink;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue