From 42ef6b6585789faa03f7c92b528a6357638b51ea Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 19 Apr 2008 21:29:19 +0000 Subject: [PATCH] Fix NS_MEDIA link handling --- includes/Linker.php | 11 ++++++----- includes/Parser.php | 9 ++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index acaaf07112..037d12c8cf 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -755,27 +755,28 @@ class Linker { } /** @deprecated use Linker::makeMediaLinkObj() */ - function makeMediaLink( $name, $unused = '', $text = '' ) { + function makeMediaLink( $name, $unused = '', $text = '', $time = false ) { $nt = Title::makeTitleSafe( NS_IMAGE, $name ); - return $this->makeMediaLinkObj( $nt, $text ); + return $this->makeMediaLinkObj( $nt, $text, $time ); } /** * Create a direct link to a given uploaded file. * * @param $title Title object. - * @param $text String: pre-sanitized HTML + * @param $text String: pre-sanitized HTML + * @param $time string: time image was created * @return string HTML * * @public * @todo Handle invalid or missing images better. */ - function makeMediaLinkObj( $title, $text = '' ) { + function makeMediaLinkObj( $title, $text = '', $time = false ) { if( is_null( $title ) ) { ### HOTFIX. Instead of breaking, return empty string. return $text; } else { - $img = wfFindFile( $title ); + $img = wfFindFile( $title, $time ); if( $img ) { $url = $img->getURL(); $class = 'internal'; diff --git a/includes/Parser.php b/includes/Parser.php index 28619e81b6..4d2bd38231 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1755,7 +1755,14 @@ class Parser # Special and Media are pseudo-namespaces; no pages actually exist in them if( $ns == NS_MEDIA ) { - $link = $sk->makeMediaLinkObj( $nt, $text ); + # Give extensions a chance to select the file revision for us + $skip = $time = false; + wfRunHooks( 'BeforeParserMakeImageLinkObj', array( &$this, &$nt, &$skip, &$time ) ); + if ( $skip ) { + $link = $sk->makeLinkObj( $nt ); + } else { + $link = $sk->makeMediaLinkObj( $nt, $text, $time ); + } # Cloak with NOPARSE to avoid replacement in replaceExternalLinks $s .= $prefix . $this->armorLinks( $link ) . $trail; $this->mOutput->addImage( $nt->getDBkey() ); -- 2.20.1