From: Robert Vogel Date: Tue, 25 Mar 2014 10:56:41 +0000 (+0100) Subject: includes/Linker.php: Added hook for "Media:" links X-Git-Tag: 1.31.0-rc.0~16172^2 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=020fc0b649e4a69e94b11179772e79bafdda2da7;p=lhc%2Fweb%2Fwiklou.git includes/Linker.php: Added hook for "Media:" links The static method 'Linker::makeMediaLinkFile' produced a HTML string without usage of MediaWiki 'Html' class. It also lacked a hook to allow modifications of the output HTML. I altered the implementation and added a hook that provides a signature and behaviour similar to the existing 'LinkerMakeExternalLink' and 'LinkBegin'/'LinkEnd' hooks. It provides all available context information and allows modification of single attributes or the output HTML as a whole. I have updated the 'docs/hooks.txt' file to provide proper documentation. Change-Id: I6d7769298a4ca6cbbf807fcebb91fb0d2222f8d8 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index ff1d6a18f5..3044fff9a2 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1547,6 +1547,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 diff --git a/includes/Linker.php b/includes/Linker.php index 094a304b23..67db78aa63 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -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 "{$html}"; + + $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 ); } /**