New 'OutputPageAfterGetHeadLinksArray' hook, allowing extensions to modify the return...
authorJack Phoenix <ashley@uncyclomedia.co>
Sat, 14 Jul 2018 22:54:40 +0000 (01:54 +0300)
committerJack Phoenix <ashley@uncyclomedia.co>
Sat, 14 Jul 2018 23:08:16 +0000 (02:08 +0300)
Code from wikiHow codebase, where this hook is used by the following extensions:
* AlternateDomain -- used to remove certain links altogether and change the contents of other elements (e.g. <meta description="..." />)
* hooks (PageHooks) -- used to hide certain links for anons on noindexed pages to avoid leaking article info to Googlebot
* QADomain -- used to remove certain elements and correct <meta keywords="..." /> tags not to mention "wikiHow" if that string is present
* search (LSearch) -- used to remove canonical URL on Special:LSearch for SEO

Change-Id: I4a9ceb343bb5c0b4eb79e4589d36c3790938f8a9

RELEASE-NOTES-1.32
docs/hooks.txt
includes/OutputPage.php

index 5110e51..da317de 100644 (file)
@@ -53,6 +53,9 @@ production.
   pages.
 * The array of hidden options ($opts) passed to the 'SpecialSearchPowerBox' hook
   is now passed by reference, allowing extensions to modify or even unset it.
+* 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>.
 
 === External library changes in 1.32 ===
 * …
index c7874c3..fff5b24 100644 (file)
@@ -2439,6 +2439,12 @@ users and/or IP addresses too.
 &$otherBlockLink: An array with links to other block logs
 $ip: The requested IP address or username
 
+'OutputPageAfterGetHeadLinksArray': Called in OutputPage#getHeadLinksArray right
+before returning the result.
+&$tags: array containing all <head> links generated so far. The array format is
+"link name or number => 'link HTML'".
+$out: the OutputPage object
+
 'OutputPageBeforeHTML': A page has been processed by the parser and the
 resulting HTML is about to be displayed.
 &$parserOutput: the parserOutput (object) that corresponds to the page
index 34de7c6..5965cbe 100644 (file)
@@ -3530,6 +3530,13 @@ class OutputPage extends ContextSource {
                        ] );
                }
 
+               // Allow extensions to add, remove and/or otherwise manipulate these links
+               // If you want only to *add* <head> links, please use the addHeadItem()
+               // (or addHeadItems() for multiple items) method instead.
+               // This hook is provided as a last resort for extensions to modify these
+               // links before the output is sent to client.
+               Hooks::run( 'OutputPageAfterGetHeadLinksArray', [ &$tags, $this ] );
+
                return $tags;
        }