From 3a49b629e6b9fbd76f3b492ccf0cacac616f25be Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 4 Apr 2011 01:22:08 +0000 Subject: [PATCH] Follow-up changes to r84610: * Cleaned up mImageTimeKeys format * ImageMap: Removed redundant addImage call (makeImage handes this) * ParserFunctions: added time/sha1 to addImage() call * Removed excess ampersands in hooks * Added some function doc comments --- docs/hooks.txt | 8 ++++---- includes/ImageGallery.php | 2 +- includes/OutputPage.php | 2 ++ includes/parser/Parser.php | 10 +++++----- includes/parser/ParserOutput.php | 10 +++++++--- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 3ab877f98a..15c89ad102 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -563,15 +563,15 @@ $mediaWiki: Mediawiki object &$skin: Skin object 'BeforeParserFetchFileAndTitle': before an image is rendered by Parser -&$parser: Parser object -&$nt: the image title +$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) &$descQuery: query string to add to thumbnail URL 'BeforeParserFetchTemplateAndtitle': before a template is fetched by Parser -&$parser: Parser object -&$title: title of the template +$parser: Parser object +$title: title of the template &$skip: skip this template and link it? &$id: the id of the revision being parsed diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index 925ba24d8a..f490a381ee 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -242,7 +242,7 @@ class ImageGallery # Give extensions a chance to select the file revision for us $time = $sha1 = false; wfRunHooks( 'BeforeParserFetchFileAndTitle', - array( $this->mParser, &$nt, &$time, &$sha1, &$descQuery ) ); + array( $this->mParser, $nt, &$time, &$sha1, &$descQuery ) ); # Fetch and register the file (file title may be different via hooks) list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $time, $sha1 ); } else { diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 03fc907d6b..4fb8c5f897 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1281,6 +1281,7 @@ class OutputPage { * Get the templates used on this page * * @return Array (namespace => dbKey => revId) + * @since 1.18 */ public function getTemplateIds() { return $this->mTemplateIds; @@ -1290,6 +1291,7 @@ class OutputPage { * Get the files used on this page * * @return Array (dbKey => array('time' => MW timestamp or null, 'sha1' => sha1 or '')) + * @since 1.18 */ public function getImageTimeKeys() { return $this->mImageTimeKeys; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 6200e1bea4..30675b4d94 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1903,7 +1903,7 @@ class Parser { # Give extensions a chance to select the file revision for us $time = $sha1 = $descQuery = false; wfRunHooks( 'BeforeParserFetchFileAndTitle', - array( $this, &$nt, &$time, &$sha1, &$descQuery ) ); + array( $this, $nt, &$time, &$sha1, &$descQuery ) ); # Fetch and register the file (file title may be different via hooks) list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $time, $sha1 ); # Cloak with NOPARSE to avoid replacement in replaceExternalLinks @@ -3336,7 +3336,7 @@ class Parser { # Give extensions a chance to select the revision instead $id = false; # Assume current wfRunHooks( 'BeforeParserFetchTemplateAndtitle', - array( $parser, &$title, &$skip, &$id ) ); + array( $parser, $title, &$skip, &$id ) ); if ( $skip ) { $text = false; @@ -3423,8 +3423,8 @@ class Parser { } else { // get by (name,timestamp) $file = wfFindFile( $title, array( 'time' => $time ) ); } - $time = $file ? $file->getTimestamp() : null; - $sha1 = $file ? $file->getSha1() : null; + $time = $file ? $file->getTimestamp() : false; + $sha1 = $file ? $file->getSha1() : false; # Register the file as a dependency... $this->mOutput->addImage( $title->getDBkey(), $time, $sha1 ); if ( $file && !$title->equals( $file->getTitle() ) ) { @@ -4685,7 +4685,7 @@ class Parser { # Give extensions a chance to select the file revision for us $time = $sha1 = $descQuery = false; wfRunHooks( 'BeforeParserFetchFileAndTitle', - array( $this, &$title, &$time, &$sha1, &$descQuery ) ); + array( $this, $title, &$time, &$sha1, &$descQuery ) ); # Fetch and register the file (file title may be different via hooks) list( $file, $title ) = $this->fetchFileAndTitle( $title, $time, $sha1 ); diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index a0224ac47c..21bbe47453 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -260,17 +260,21 @@ class ParserOutput extends CacheTime { } /** + * Register a file dependency for this output * @param $name string Title dbKey - * @param $timestamp string MW timestamp of file creation - * @param $sha string base 36 SHA-1 of file + * @param $timestamp string MW timestamp of file creation (or false if non-existing) + * @param $sha string base 36 SHA-1 of file (or false if non-existing) * @return void */ function addImage( $name, $timestamp = null, $sha1 = null ) { $this->mImages[$name] = 1; - $this->mImageTimeKeys[$name] = array( 'time' => $timestamp, 'sha1' => $sha1 ); + if ( $timestamp !== null && $sha1 !== null ) { + $this->mImageTimeKeys[$name] = array( 'time' => $timestamp, 'sha1' => $sha1 ); + } } /** + * Register a template dependency for this output * @param $title Title * @param $page_id * @param $rev_id -- 2.20.1