2015-01-27 05:34:04 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class CiteThisPageHooks {
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-06 19:29:48 +00:00
|
|
|
|
* @param SkinTemplate &$skintemplate
|
|
|
|
|
* @param array &$nav_urls
|
|
|
|
|
* @param int &$oldid
|
|
|
|
|
* @param int &$revid
|
2015-01-27 05:34:04 +00:00
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2016-01-16 12:41:27 +00:00
|
|
|
|
public static function onSkinTemplateBuildNavUrlsNav_urlsAfterPermalink(
|
|
|
|
|
&$skintemplate, &$nav_urls, &$oldid, &$revid
|
|
|
|
|
) {
|
2015-01-27 05:34:04 +00:00
|
|
|
|
// 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();
|
2016-11-04 20:08:12 +00:00
|
|
|
|
if ( self::shouldAddLink( $title ) && $revid !== 0 && !empty( $revid ) ) {
|
2016-07-13 19:44:33 +00:00
|
|
|
|
$nav_urls['citethispage'] = [
|
|
|
|
|
'text' => $skintemplate->msg( 'citethispage-link' )->text(),
|
|
|
|
|
'href' => SpecialPage::getTitleFor( 'CiteThisPage' )
|
2019-11-16 17:44:17 +00:00
|
|
|
|
->getLocalURL( [ 'page' => $title->getPrefixedDBkey(), 'id' => $revid,
|
|
|
|
|
'wpFormIdentifier' => 'titleform' ] ),
|
2016-07-13 19:44:33 +00:00
|
|
|
|
'id' => 't-cite',
|
|
|
|
|
# Used message keys: 'tooltip-citethispage', 'accesskey-citethispage'
|
|
|
|
|
'single-id' => 'citethispage',
|
2016-05-09 23:36:56 +00:00
|
|
|
|
];
|
2016-01-16 12:41:27 +00:00
|
|
|
|
}
|
2015-01-27 05:34:04 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-04 20:08:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
private static function shouldAddLink( Title $title ) {
|
|
|
|
|
global $wgCiteThisPageAdditionalNamespaces;
|
|
|
|
|
|
|
|
|
|
return $title->isContentPage() ||
|
|
|
|
|
(
|
|
|
|
|
isset( $wgCiteThisPageAdditionalNamespaces[$title->getNamespace()] ) &&
|
|
|
|
|
$wgCiteThisPageAdditionalNamespaces[$title->getNamespace()]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 05:34:04 +00:00
|
|
|
|
/**
|
2016-07-13 19:44:33 +00:00
|
|
|
|
* @param BaseTemplate $baseTemplate
|
2017-10-06 19:29:48 +00:00
|
|
|
|
* @param array &$toolbox
|
2015-01-27 05:34:04 +00:00
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2016-07-13 19:44:33 +00:00
|
|
|
|
public static function onBaseTemplateToolbox( BaseTemplate $baseTemplate, array &$toolbox ) {
|
|
|
|
|
if ( isset( $baseTemplate->data['nav_urls']['citethispage'] ) ) {
|
|
|
|
|
$toolbox['citethispage'] = $baseTemplate->data['nav_urls']['citethispage'];
|
2015-01-27 05:34:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|