Merge "includes/Linker.php: Added hook for "Media:" links"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 17 Apr 2014 19:39:37 +0000 (19:39 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 17 Apr 2014 19:39:37 +0000 (19:39 +0000)
docs/hooks.txt
includes/Linker.php

index 2e87604..302494f 100644 (file)
@@ -1568,6 +1568,14 @@ before the return.
 &$attribs: the attributes to be applied.
 $linkType: The external link type
 
+'LinkerMakeMediaLinkFile': At the end of Linker::makeMediaLinkFile() just
+before the return.
+$title: the Title object that the link is pointing to
+$file: the File object or false if broken link
+&$html: the link text
+&$attribs: the attributes to be applied
+&$ret: the value to return if your hook returns false
+
 'LinksUpdate': At the beginning of LinksUpdate::doUpdate() just before the
 actual update.
 &$linksUpdate: the LinksUpdate object
index 534ad4d..c9a184c 100644 (file)
@@ -998,12 +998,26 @@ class Linker {
                        $url = self::getUploadUrl( $title );
                        $class = 'new';
                }
-               $alt = htmlspecialchars( $title->getText(), ENT_QUOTES );
+
+               $alt = $title->getText();
                if ( $html == '' ) {
                        $html = $alt;
                }
-               $u = htmlspecialchars( $url );
-               return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$html}</a>";
+
+               $ret = '';
+               $attribs = array(
+                       'href' => $url,
+                       'class' => $class,
+                       'title' => $alt
+               );
+
+               if ( !wfRunHooks( 'LinkerMakeMediaLinkFile',
+                       array( $title, $file, &$html, &$attribs, &$ret ) ) ) {
+                       wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link with url {$url} and text {$html} to {$ret}\n", true );
+                       return $ret;
+               }
+
+               return Html::rawElement( 'a', $attribs, $html );
        }
 
        /**