diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/CiteThisPage/CiteThisPage.hooks.php |
first commit
Diffstat (limited to 'www/wiki/extensions/CiteThisPage/CiteThisPage.hooks.php')
-rw-r--r-- | www/wiki/extensions/CiteThisPage/CiteThisPage.hooks.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/www/wiki/extensions/CiteThisPage/CiteThisPage.hooks.php b/www/wiki/extensions/CiteThisPage/CiteThisPage.hooks.php new file mode 100644 index 00000000..7f7572f7 --- /dev/null +++ b/www/wiki/extensions/CiteThisPage/CiteThisPage.hooks.php @@ -0,0 +1,62 @@ +<?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 ( 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 ] ), + '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 + * 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()] + ); + } + + /** + * @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; + } +} |