From 9d572d1844380c0db268b456f297bd7675eb609f Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 6 Sep 2011 18:11:53 +0000 Subject: [PATCH] Cleanup to r84610 per CR: changed BeforeParserMakeImageLinkObj hook to use a RepoGroup style param array that also excepts a 'broken' parameter. This new parameter replaces the odd "use timestamp '0' to make a broken thumbnail' convention. No other callers are using this hook other than FR, so the old time/sha1 params where removed. --- docs/hooks.txt | 5 +++-- includes/ImageGallery.php | 6 +++--- includes/parser/Parser.php | 37 ++++++++++++++++++++----------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 98779501fa..c2a5f6dca6 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -596,10 +596,11 @@ $mediaWiki: Mediawiki object 'BeforeParserFetchFileAndTitle': before an image is rendered by Parser $parser: Parser object $nt: the image title -&$time: the image timestamp (use '0' to force a broken thumbnail) -&$sha1: image base 36 sha1 (used to specify the file, $nt will be ignored if this is set) +&$options: array of options to RepoGroup::findFile &$descQuery: query string to add to thumbnail URL +If 'broken' is a key in $options then the file will appear as a broken thumbnail. + 'BeforeParserFetchTemplateAndtitle': before a template is fetched by Parser $parser: Parser object $title: title of the template diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index 8d3b6d6dac..a40a685223 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -249,11 +249,11 @@ class ImageGallery { # Get the file... if ( $this->mParser instanceof Parser ) { # Give extensions a chance to select the file revision for us - $time = $sha1 = false; + $options = array(); wfRunHooks( 'BeforeParserFetchFileAndTitle', - array( $this->mParser, $nt, &$time, &$sha1, &$descQuery ) ); + array( $this->mParser, $nt, &$options, &$descQuery ) ); # Fetch and register the file (file title may be different via hooks) - list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $time, $sha1 ); + list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options ); } else { $img = wfFindFile( $nt ); } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 6ff1e447f7..2e8a07dc73 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -2067,11 +2067,12 @@ class Parser { if ( $ns == NS_MEDIA ) { wfProfileIn( __METHOD__."-media" ); # Give extensions a chance to select the file revision for us - $time = $sha1 = $descQuery = false; + $options = array(); + $descQuery = false; wfRunHooks( 'BeforeParserFetchFileAndTitle', - array( $this, $nt, &$time, &$sha1, &$descQuery ) ); + array( $this, $nt, &$options, &$descQuery ) ); # Fetch and register the file (file title may be different via hooks) - list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $time, $sha1 ); + list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $options ); # Cloak with NOPARSE to avoid replacement in replaceExternalLinks $s .= $prefix . $this->armorLinks( Linker::makeMediaLinkFile( $nt, $file, $text ) ) . $trail; @@ -3641,30 +3642,30 @@ class Parser { /** * Fetch a file and its title and register a reference to it. + * If 'broken' is a key in $options then the file will appear as a broken thumbnail. * @param Title $title - * @param string $time MW timestamp - * @param string $sha1 base 36 SHA-1 + * @param Array $options Array of options to RepoGroup::findFile * @return File|false */ - function fetchFile( $title, $time = false, $sha1 = false ) { - $res = $this->fetchFileAndTitle( $title, $time, $sha1 ); + function fetchFile( $title, $options = array() ) { + $res = $this->fetchFileAndTitle( $title, $options ); return $res[0]; } /** * Fetch a file and its title and register a reference to it. + * If 'broken' is a key in $options then the file will appear as a broken thumbnail. * @param Title $title - * @param string $time MW timestamp - * @param string $sha1 base 36 SHA-1 + * @param Array $options Array of options to RepoGroup::findFile * @return Array ( File or false, Title of file ) */ - function fetchFileAndTitle( $title, $time = false, $sha1 = false ) { - if ( $time === '0' ) { + function fetchFileAndTitle( $title, $options = array() ) { + if ( isset( $options['broken'] ) ) { $file = false; // broken thumbnail forced by hook - } elseif ( $sha1 ) { // get by (sha1,timestamp) - $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) ); + } elseif ( isset( $options['sha1'] ) ) { // get by (sha1,timestamp) + $file = RepoGroup::singleton()->findFileFromKey( $options['sha1'], $options ); } else { // get by (name,timestamp) - $file = wfFindFile( $title, array( 'time' => $time ) ); + $file = wfFindFile( $title, $options ); } $time = $file ? $file->getTimestamp() : false; $sha1 = $file ? $file->getSha1() : false; @@ -5010,11 +5011,12 @@ class Parser { $parts = StringUtils::explode( "|", $options ); # Give extensions a chance to select the file revision for us - $time = $sha1 = $descQuery = false; + $options = array(); + $descQuery = false; wfRunHooks( 'BeforeParserFetchFileAndTitle', - array( $this, $title, &$time, &$sha1, &$descQuery ) ); + array( $this, $title, &$options, &$descQuery ) ); # Fetch and register the file (file title may be different via hooks) - list( $file, $title ) = $this->fetchFileAndTitle( $title, $time, $sha1 ); + list( $file, $title ) = $this->fetchFileAndTitle( $title, $options ); # Get parameter map $handler = $file ? $file->getHandler() : false; @@ -5174,6 +5176,7 @@ class Parser { wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) ); # Linker does the rest + $time = isset( $options['time'] ) ? $options['time'] : false; $ret = Linker::makeImageLink2( $title, $file, $params['frame'], $params['handler'], $time, $descQuery, $this->mOptions->getThumbSize() ); -- 2.20.1