Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -53,7 +53,7 @@ |
54 | 54 | * changes in an incompatible way, so the parser cache |
55 | 55 | * can automatically discard old data. |
56 | 56 | */ |
57 | | - const VERSION = '1.6.4'; |
| 57 | + const VERSION = '1.6.5'; |
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Update this version number when the output of serialiseHalfParsedText() |
— | — | @@ -1869,7 +1869,6 @@ |
1870 | 1870 | } |
1871 | 1871 | wfProfileOut( __METHOD__."-image" ); |
1872 | 1872 | continue; |
1873 | | - |
1874 | 1873 | } |
1875 | 1874 | |
1876 | 1875 | if ( $ns == NS_CATEGORY ) { |
— | — | @@ -1914,14 +1913,11 @@ |
1915 | 1914 | wfRunHooks( 'BeforeParserMakeImageLinkObj', |
1916 | 1915 | array( &$this, &$nt, &$skip, &$time, &$descQuery, &$sha1 ) ); |
1917 | 1916 | if ( $skip ) { |
1918 | | - $this->mOutput->addImage( $nt->getDBkey() ); // register |
| 1917 | + $this->mOutput->addImage( $nt->getDBkey(), null, null ); // register |
1919 | 1918 | $link = $sk->link( $nt ); |
1920 | 1919 | } else { |
1921 | | - # Fetch and register the file |
1922 | | - $file = $this->fetchFile( $nt, $time, $sha1 ); |
1923 | | - if ( $file ) { |
1924 | | - $nt = $file->getTitle(); // file title may be different (via hooks) |
1925 | | - } |
| 1920 | + # Fetch and register the file (file title may be different via hooks) |
| 1921 | + list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $time, $sha1 ); |
1926 | 1922 | $link = $sk->makeMediaLinkFile( $nt, $file, $text ); |
1927 | 1923 | } |
1928 | 1924 | # Cloak with NOPARSE to avoid replacement in replaceExternalLinks |
— | — | @@ -3314,6 +3310,8 @@ |
3315 | 3311 | |
3316 | 3312 | /** |
3317 | 3313 | * Fetch the unparsed text of a template and register a reference to it. |
| 3314 | + * @param Title $title |
| 3315 | + * @return Array ( string or false, Title ) |
3318 | 3316 | */ |
3319 | 3317 | function fetchTemplateAndTitle( $title ) { |
3320 | 3318 | $templateCb = $this->mOptions->getTemplateCallback(); # Defaults to Parser::statelessFetchTemplate() |
— | — | @@ -3328,6 +3326,11 @@ |
3329 | 3327 | return array( $text, $finalTitle ); |
3330 | 3328 | } |
3331 | 3329 | |
| 3330 | + /** |
| 3331 | + * Fetch the unparsed text of a template and register a reference to it. |
| 3332 | + * @param Title $title |
| 3333 | + * @return mixed string or false |
| 3334 | + */ |
3332 | 3335 | function fetchTemplate( $title ) { |
3333 | 3336 | $rv = $this->fetchTemplateAndTitle( $title ); |
3334 | 3337 | return $rv[0]; |
— | — | @@ -3398,11 +3401,28 @@ |
3399 | 3402 | } |
3400 | 3403 | |
3401 | 3404 | /** |
3402 | | - * Fetch a file and register a reference to it. |
3403 | | - * @TODO: register and track file version info too |
| 3405 | + * Fetch a file and its title and register a reference to it. |
| 3406 | + * @param Title $title |
| 3407 | + * @param string $time MW timestamp |
| 3408 | + * @param string $sha1 base 36 SHA-1 |
| 3409 | + * @return mixed File or false |
3404 | 3410 | */ |
3405 | 3411 | function fetchFile( $title, $time = false, $sha1 = false ) { |
3406 | | - if ( $sha1 ) { // get by (sha1,timestamp) |
| 3412 | + $res = $this->fetchFileAndTitle( $title, $time, $sha1 ); |
| 3413 | + return $res[0]; |
| 3414 | + } |
| 3415 | + |
| 3416 | + /** |
| 3417 | + * Fetch a file and its title and register a reference to it. |
| 3418 | + * @param Title $title |
| 3419 | + * @param string $time MW timestamp |
| 3420 | + * @param string $sha1 base 36 SHA-1 |
| 3421 | + * @return Array ( File or false, Title ) |
| 3422 | + */ |
| 3423 | + function fetchFileAndTitle( $title, $time = false, $sha1 = false ) { |
| 3424 | + if ( $time === '0' ) { |
| 3425 | + $file = false; // broken thumbnail forced by hook |
| 3426 | + } elseif ( $sha1 ) { // get by (sha1,timestamp) |
3407 | 3427 | $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) ); |
3408 | 3428 | if ( $file ) { |
3409 | 3429 | $title = $file->getTitle(); // file title may not match $title |
— | — | @@ -3410,8 +3430,12 @@ |
3411 | 3431 | } else { // get by (name,timestamp) |
3412 | 3432 | $file = wfFindFile( $title, array( 'time' => $time ) ); |
3413 | 3433 | } |
3414 | | - $this->mOutput->addImage( $title->getDBkey() ); |
3415 | | - return $file; |
| 3434 | + # Register the file as a dependancy |
| 3435 | + $time = $file ? $file->getTimestamp() : null; |
| 3436 | + $sha1 = $file ? $file->getSha1() : null; |
| 3437 | + $this->mOutput->addImage( $title->getDBkey(), $time, $sha1 ); |
| 3438 | + |
| 3439 | + return array( $file, $title ); |
3416 | 3440 | } |
3417 | 3441 | |
3418 | 3442 | /** |
— | — | @@ -4670,14 +4694,11 @@ |
4671 | 4695 | wfRunHooks( 'BeforeParserMakeImageLinkObj', |
4672 | 4696 | array( &$this, &$title, &$skip, &$time, &$descQuery, &$sha1 ) ); |
4673 | 4697 | if ( $skip ) { |
4674 | | - $this->mOutput->addImage( $title->getDBkey() ); // register |
| 4698 | + $this->mOutput->addImage( $title->getDBkey(), null, null ); // register |
4675 | 4699 | return $sk->link( $title ); |
4676 | 4700 | } |
4677 | | - # Fetch and register the file |
4678 | | - $file = $this->fetchFile( $title, $time, $sha1 ); |
4679 | | - if ( $file ) { |
4680 | | - $title = $file->getTitle(); // file title may be different (via hooks) |
4681 | | - } |
| 4701 | + # Fetch and register the file (file title may be different via hooks) |
| 4702 | + list( $file, $title ) = $this->fetchFileAndTitle( $title, $time, $sha1 ); |
4682 | 4703 | # Get parameter map |
4683 | 4704 | $handler = $file ? $file->getHandler() : false; |
4684 | 4705 | |
Index: trunk/phase3/includes/parser/ParserOutput.php |
— | — | @@ -109,6 +109,7 @@ |
110 | 110 | $mTemplates = array(), # 2-D map of NS/DBK to ID for the template references. ID=zero for broken. |
111 | 111 | $mTemplateIds = array(), # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken. |
112 | 112 | $mImages = array(), # DB keys of the images used, in the array key only |
| 113 | + $mImageTimeKeys = array(), # DB keys of the images used mapped to sha1 and MW timestamp |
113 | 114 | $mExternalLinks = array(), # External link URLs, in the key only |
114 | 115 | $mInterwikiLinks = array(), # 2-D map of prefix/DBK (in keys only) for the inline interwiki links in the document. |
115 | 116 | $mNewSection = false, # Show a new section link? |
— | — | @@ -174,7 +175,9 @@ |
175 | 176 | function getEditSectionTokens() { return $this->mEditSectionTokens; } |
176 | 177 | function &getLinks() { return $this->mLinks; } |
177 | 178 | function &getTemplates() { return $this->mTemplates; } |
| 179 | + function &getTemplateIds() { return $this->mTemplateIds; } |
178 | 180 | function &getImages() { return $this->mImages; } |
| 181 | + function &getImageTimeKeys() { return $this->mImageTimeKeys; } |
179 | 182 | function &getExternalLinks() { return $this->mExternalLinks; } |
180 | 183 | function getNoGallery() { return $this->mNoGallery; } |
181 | 184 | function getHeadItems() { return $this->mHeadItems; } |
— | — | @@ -256,14 +259,21 @@ |
257 | 260 | $this->mLinks[$ns][$dbk] = $id; |
258 | 261 | } |
259 | 262 | |
260 | | - function addImage( $name ) { |
| 263 | + /** |
| 264 | + * @param $name string Title dbKey |
| 265 | + * @param $timestamp string MW timestamp of file creation |
| 266 | + * @param $sha string base 36 SHA-1 of file |
| 267 | + * @return void |
| 268 | + */ |
| 269 | + function addImage( $name, $timestamp, $sha1 ) { |
261 | 270 | $this->mImages[$name] = 1; |
| 271 | + $this->mImageTimeKeys[$name] = array( 'time' => $timestamp, 'sha1' => $sha1 ); |
262 | 272 | } |
263 | 273 | |
264 | 274 | /** |
265 | 275 | * @param $title Title |
266 | | - * @param $page_id |
267 | | - * @param $rev_id |
| 276 | + * @param $page_id |
| 277 | + * @param $rev_id |
268 | 278 | * @return void |
269 | 279 | */ |
270 | 280 | function addTemplate( $title, $page_id, $rev_id ) { |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -123,6 +123,7 @@ |
124 | 124 | var $mInlineMsg = array(); |
125 | 125 | |
126 | 126 | var $mTemplateIds = array(); |
| 127 | + var $mImageTimeKeys = array(); |
127 | 128 | |
128 | 129 | # What level of 'untrustworthiness' is allowed in CSS/JS modules loaded on this page? |
129 | 130 | # @see ResourceLoaderModule::$origin |
— | — | @@ -1308,14 +1309,19 @@ |
1309 | 1310 | $this->mNoGallery = $parserOutput->getNoGallery(); |
1310 | 1311 | $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() ); |
1311 | 1312 | $this->addModules( $parserOutput->getModules() ); |
1312 | | - // Versioning... |
1313 | | - foreach ( (array)$parserOutput->mTemplateIds as $ns => $dbks ) { |
| 1313 | + |
| 1314 | + // Template versioning... |
| 1315 | + foreach ( (array)$parserOutput->getTemplateIds() as $ns => $dbks ) { |
1314 | 1316 | if ( isset( $this->mTemplateIds[$ns] ) ) { |
1315 | 1317 | $this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns]; |
1316 | 1318 | } else { |
1317 | 1319 | $this->mTemplateIds[$ns] = $dbks; |
1318 | 1320 | } |
1319 | 1321 | } |
| 1322 | + // File versioning... |
| 1323 | + foreach ( (array)$parserOutput->getImageTimeKeys() as $dbk => $data ) { |
| 1324 | + $this->mImageTimeKeys[$dbk] = $data; |
| 1325 | + } |
1320 | 1326 | |
1321 | 1327 | // Hooks registered in the object |
1322 | 1328 | global $wgParserOutputHooks; |
Index: trunk/phase3/includes/ImageGallery.php |
— | — | @@ -257,11 +257,8 @@ |
258 | 258 | $time = $sha1 = $descQuery = false; |
259 | 259 | wfRunHooks( 'BeforeGalleryFindFile', |
260 | 260 | array( &$this, &$nt, &$time, &$descQuery, &$sha1 ) ); |
261 | | - # Get the file and register it |
262 | | - $img = $this->mParser->fetchFile( $nt, $time, $sha1 ); |
263 | | - if ( $img ) { |
264 | | - $nt = $img->getTitle(); // file title may be different (via hooks) |
265 | | - } |
| 261 | + # Fetch and register the file (file title may be different via hooks) |
| 262 | + list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $time, $sha1 ); |
266 | 263 | } else { |
267 | 264 | $img = false; |
268 | 265 | } |