Pass $title to 'GetLinkColours' hook
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 30 Jul 2018 15:25:25 +0000 (17:25 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Tue, 31 Jul 2018 03:00:00 +0000 (05:00 +0200)
I think it's reasonable for link "colours" to depend on the page on
which they are shown. It seems similar to how self-links are handled.
The $colours variable is not cached, so title-specific link colours
will not "leak" to other titles.

Used in ProofreadPage in Ic910c2c33a6f1f8a70d9a122fbd2128428f29bd5.

Bug: T199288
Change-Id: I7378102a3e06544e9e695b255982c9bb0cfbf3a2

RELEASE-NOTES-1.32
docs/hooks.txt
includes/parser/LinkHolderArray.php

index 9c6609b..193ede8 100644 (file)
@@ -66,6 +66,8 @@ production.
   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.
+* The 'GetLinkColours' hook now receives an additional $title parameter,
+  the Title object of the page being parsed, on which the links will be shown.
 
 === External library changes in 1.32 ===
 * …
index 251bea6..219c51f 100644 (file)
@@ -1730,6 +1730,7 @@ $query: query options passed to Title::getInternalURL()
 $linkcolour_ids: array of prefixed DB keys of the pages linked to,
   indexed by page_id.
 &$colours: (output) array of CSS classes, indexed by prefixed DB keys
+$title: Title object of the page being parsed, on which the links will be shown
 
 'GetLocalURL': Modify local URLs as output into page links. Note that if you are
 working with internal urls (non-interwiki) then it may be preferable to work
index 7e150e9..66fd723 100644 (file)
@@ -360,7 +360,7 @@ class LinkHolderArray {
                }
                if ( count( $linkcolour_ids ) ) {
                        // pass an array of page_ids to an extension
-                       Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours ] );
+                       Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours, $this->parent->getTitle() ] );
                }
 
                # Do a second query for different language variants of links and categories
@@ -589,7 +589,7 @@ class LinkHolderArray {
                                        }
                                }
                        }
-                       Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours ] );
+                       Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours, $this->parent->getTitle() ] );
 
                        // rebuild the categories in original order (if there are replacements)
                        if ( count( $varCategories ) > 0 ) {