HistoryAction: Implement HistoryPageToolLinks hook for adding more links
authortinajohnson.1234 <tinajohnson.1234@gmail.com>
Tue, 25 Mar 2014 16:01:51 +0000 (21:31 +0530)
committerMatěj Suchánek <matejsuchanek97@gmail.com>
Thu, 19 Jul 2018 09:43:43 +0000 (11:43 +0200)
This allows AbuseFilter to add an extra link in the tool links section of
the subtitle on a history page

Co-authored-by: Matěj Suchánek
Bug: T28934
Change-Id: I2e0e9e92d3fc303135b0eb9acf06b5fd120178a5

RELEASE-NOTES-1.32
docs/hooks.txt
includes/actions/HistoryAction.php

index 5435213..90396ea 100644 (file)
@@ -56,6 +56,8 @@ production.
 * Added new 'OutputPageAfterGetHeadLinksArray' hook, allowing extensions to
   modify the return value of OutputPage#getHeadLinksArray in order to add,
   remove or otherwise alter the elements to be output in the page <head>.
+* (T28934) The 'HistoryPageToolLinks' hook allows extensions to append
+  additional links to the subtitle of a history page.
 
 === External library changes in 1.32 ===
 * …
index 40777da..251bea6 100644 (file)
@@ -1823,6 +1823,11 @@ $rev: Revision object
 $prevRev: Revision object, next in line in page history, or null
 $user: Current user object
 
+'HistoryPageToolLinks': Add one or more links to revision history page subtitle.
+$context: IContextSource (object)
+$linkRenderer: LinkRenderer instance
+&$links: Array of HTML strings
+
 'HTMLFileCache::useFileCache': Override whether a page should be cached in file
 cache.
 $context: An IContextSource object with information about the request being
index 20637fc..1a15fc0 100644 (file)
@@ -62,12 +62,25 @@ class HistoryAction extends FormlessAction {
 
        protected function getDescription() {
                // Creation of a subtitle link pointing to [[Special:Log]]
-               return MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
+               $subtitle = $linkRenderer->makeKnownLink(
                        SpecialPage::getTitleFor( 'Log' ),
                        $this->msg( 'viewpagelogs' )->text(),
                        [],
                        [ 'page' => $this->getTitle()->getPrefixedText() ]
                );
+
+               $links = [];
+               // Allow extensions to add more links
+               Hooks::run( 'HistoryPageToolLinks', [ $this->getContext(), $linkRenderer, &$links ] );
+               if ( $links ) {
+                       $subtitle .= ''
+                               . $this->msg( 'word-separator' )->escaped()
+                               . $this->msg( 'parentheses' )
+                                       ->rawParams( $this->getLanguage()->pipeList( $links ) )
+                                       ->escaped();
+               }
+               return $subtitle;
        }
 
        /**