2015-01-27 05:34:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CiteThisPageHooks {
|
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
|
|
|
/**
|
2020-05-28 07:41:05 +00:00
|
|
|
* @param Skin $skin
|
|
|
|
* @param string[] &$sidebar
|
2020-06-17 00:06:30 +00:00
|
|
|
* @return void
|
2015-01-27 05:34:04 +00:00
|
|
|
*/
|
2020-06-17 00:06:30 +00:00
|
|
|
public static function onSidebarBeforeOutput( Skin $skin, array &$sidebar ): void {
|
2020-05-28 07:41:05 +00:00
|
|
|
$out = $skin->getOutput();
|
|
|
|
$title = $out->getTitle();
|
|
|
|
|
|
|
|
if ( !self::shouldAddLink( $title ) ) {
|
2020-06-17 00:06:30 +00:00
|
|
|
return;
|
2020-05-28 07:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$revid = $out->getRevisionId();
|
|
|
|
|
2020-06-17 00:06:30 +00:00
|
|
|
if ( $revid === 0 || empty( $revid ) ) {
|
|
|
|
return;
|
2015-01-27 05:34:04 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 00:06:30 +00:00
|
|
|
$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;
|
2015-01-27 05:34:04 +00:00
|
|
|
}
|
|
|
|
}
|