Fix hook situation for Skin::doEditSectionLink
authorAlex Monk <krenair@wikimedia.org>
Sat, 14 Feb 2015 00:18:12 +0000 (00:18 +0000)
committerLegoktm <legoktm.wikipedia@gmail.com>
Thu, 19 Feb 2015 16:03:22 +0000 (16:03 +0000)
The old hook supplied a way to override the HTML used for the section link,
but two extensions both trying to use it was obviously not going to work.
Deprecate it in favour of a hook that goes around gathering info to build
the initial HTML, then shoves it through the old hook for back-compat.

So that WikiEditor can add in extra URL parameters as well as VE adding in it's
own link.

Bug: T88027
Change-Id: I5a7a23709805625bdefb69cd9379be0c95acd982

docs/hooks.txt
includes/skins/Skin.php

index f47890d..78ac2ff 100644 (file)
@@ -1060,6 +1060,7 @@ $article: article (object) being viewed
 $oldid: oldid (int) being viewed
 
 'DoEditSectionLink': Override the HTML generated for section edit links
+* Deprecated in favour of SkinEditSectionLinks hook *
 $skin: Skin object rendering the UI
 $title: Title object for the title being linked to (may not be the same as
   the page title, if the section is included from a template)
@@ -2423,6 +2424,23 @@ $type: 'normal' or 'history' for old/diff views
 &$forContent: overridable flag if copyright footer is shown in content language.
   This parameter is deprecated.
 
+'SkinEditSectionLinks': Modify the section edit links
+$skin: Skin object rendering the UI
+$title: Title object for the title being linked to (may not be the same as
+  the page title, if the section is included from a template)
+$section: The designation of the section being pointed to, to be included in
+  the link, like "&section=$section"
+$tooltip: The default tooltip.  Escape before using.
+  By default, this is wrapped in the 'editsectionhint' message.
+&$result: Array containing all link detail arrays. Each link detail array should contain
+  the following keys:
+  * targetTitle - Target Title object
+  * text - String for the text
+  * attribs - Array of attributes
+  * query - Array of query parameters to add to the URL
+  * options - Array of options for Linker::link
+$lang: The language code to use for the link in the wfMessage function
+
 'SkinGetPoweredBy': TODO
 &$text: additional 'powered by' icons in HTML. Note: Modern skin does not use
 the MediaWiki icon but plain text instead.
index 244a278..26ee164 100644 (file)
@@ -1584,18 +1584,40 @@ abstract class Skin extends ContextSource {
                        $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
                                ->inLanguage( $lang )->text();
                }
-               $link = Linker::link( $nt, wfMessage( 'editsection' )->inLanguage( $lang )->text(),
-                       $attribs,
-                       array( 'action' => 'edit', 'section' => $section ),
-                       array( 'noclasses', 'known' )
+
+               $links = array(
+                       'editsection' => array(
+                               'text' => wfMessage( 'editsection' )->inLanguage( $lang )->text(),
+                               'targetTitle' => $nt,
+                               'attribs' => $attribs,
+                               'query' => array( 'action' => 'edit', 'section' => $section ),
+                               'options' => array( 'noclasses', 'known' )
+                       )
+               );
+
+               Hooks::run( 'SkinEditSectionLinks', array( $this, $nt, $section, $tooltip, &$links, $lang ) );
+
+               $result = '<span class="mw-editsection"><span class="mw-editsection-bracket">[</span>';
+
+               $linksHtml = array();
+               foreach ( $links as $k => $linkDetails ) {
+                       $linksHtml[] = Linker::link(
+                               $linkDetails['targetTitle'],
+                               $linkDetails['text'],
+                               $linkDetails['attribs'],
+                               $linkDetails['query'],
+                               $linkDetails['options']
+                       );
+               }
+
+               $result .= implode(
+                       '<span class="mw-editsection-divider">'
+                               . wfMessage( 'pipe-separator' )->inLanguage( $lang )->text()
+                               . '</span>',
+                       $linksHtml
                );
 
-               # Add the brackets and the span and run the hook.
-               $result = '<span class="mw-editsection">'
-                       . '<span class="mw-editsection-bracket">[</span>'
-                       . $link
-                       . '<span class="mw-editsection-bracket">]</span>'
-                       . '</span>';
+               $result .= '<span class="mw-editsection-bracket">]</span></span>';
 
                Hooks::run( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
                return $result;