http://www.mediawiki.org/wiki/Special:Code/MediaWiki/84610

Revision: 84610
Author:   aaron
Date:     2011-03-23 17:35:40 +0000 (Wed, 23 Mar 2011)
Log Message:
-----------
* Put parser output file version tracking to core
* Added some ParserOutput accessors
* A few cleanups to fetchFile()

Modified Paths:
--------------
    trunk/phase3/includes/ImageGallery.php
    trunk/phase3/includes/OutputPage.php
    trunk/phase3/includes/parser/Parser.php
    trunk/phase3/includes/parser/ParserOutput.php

Modified: trunk/phase3/includes/ImageGallery.php
===================================================================
--- trunk/phase3/includes/ImageGallery.php      2011-03-23 17:29:22 UTC (rev 
84609)
+++ trunk/phase3/includes/ImageGallery.php      2011-03-23 17:35:40 UTC (rev 
84610)
@@ -257,11 +257,8 @@
                                $time = $sha1 = $descQuery = false;
                                wfRunHooks( 'BeforeGalleryFindFile',
                                        array( &$this, &$nt, &$time, 
&$descQuery, &$sha1 ) );
-                               # Get the file and register it
-                               $img = $this->mParser->fetchFile( $nt, $time, 
$sha1 );
-                               if ( $img ) {
-                                       $nt = $img->getTitle(); // file title 
may be different (via hooks)
-                               }
+                               # Fetch and register the file (file title may 
be different via hooks)
+                               list( $img, $nt ) = 
$this->mParser->fetchFileAndTitle( $nt, $time, $sha1 );
                        } else {
                                $img = false;
                        }

Modified: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php        2011-03-23 17:29:22 UTC (rev 
84609)
+++ trunk/phase3/includes/OutputPage.php        2011-03-23 17:35:40 UTC (rev 
84610)
@@ -123,6 +123,7 @@
        var $mInlineMsg = array();
 
        var $mTemplateIds = array();
+       var $mImageTimeKeys = array();
 
        # What level of 'untrustworthiness' is allowed in CSS/JS modules loaded 
on this page?
        # @see ResourceLoaderModule::$origin
@@ -1308,14 +1309,19 @@
                $this->mNoGallery = $parserOutput->getNoGallery();
                $this->mHeadItems = array_merge( $this->mHeadItems, 
$parserOutput->getHeadItems() );
                $this->addModules( $parserOutput->getModules() );
-               // Versioning...
-               foreach ( (array)$parserOutput->mTemplateIds as $ns => $dbks ) {
+
+               // Template versioning...
+               foreach ( (array)$parserOutput->getTemplateIds() as $ns => 
$dbks ) {
                        if ( isset( $this->mTemplateIds[$ns] ) ) {
                                $this->mTemplateIds[$ns] = $dbks + 
$this->mTemplateIds[$ns];
                        } else {
                                $this->mTemplateIds[$ns] = $dbks;
                        }
                }
+               // File versioning...
+               foreach ( (array)$parserOutput->getImageTimeKeys() as $dbk => 
$data ) {
+                       $this->mImageTimeKeys[$dbk] = $data;
+               }
 
                // Hooks registered in the object
                global $wgParserOutputHooks;

Modified: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php     2011-03-23 17:29:22 UTC (rev 
84609)
+++ trunk/phase3/includes/parser/Parser.php     2011-03-23 17:35:40 UTC (rev 
84610)
@@ -53,7 +53,7 @@
         * changes in an incompatible way, so the parser cache
         * can automatically discard old data.
         */
-       const VERSION = '1.6.4';
+       const VERSION = '1.6.5';
 
        /**
         * Update this version number when the output of 
serialiseHalfParsedText()
@@ -1869,7 +1869,6 @@
                                        }
                                        wfProfileOut( __METHOD__."-image" );
                                        continue;
-
                                }
 
                                if ( $ns == NS_CATEGORY ) {
@@ -1914,14 +1913,11 @@
                                wfRunHooks( 'BeforeParserMakeImageLinkObj',
                                        array( &$this, &$nt, &$skip, &$time, 
&$descQuery, &$sha1 ) );
                                if ( $skip ) {
-                                       $this->mOutput->addImage( 
$nt->getDBkey() ); // register
+                                       $this->mOutput->addImage( 
$nt->getDBkey(), null, null ); // register
                                        $link = $sk->link( $nt );
                                } else {
-                                       # Fetch and register the file
-                                       $file = $this->fetchFile( $nt, $time, 
$sha1 );
-                                       if ( $file ) {
-                                               $nt = $file->getTitle(); // 
file title may be different (via hooks)
-                                       }
+                                       # Fetch and register the file (file 
title may be different via hooks)
+                                       list( $file, $nt ) = 
$this->fetchFileAndTitle( $nt, $time, $sha1 );
                                        $link = $sk->makeMediaLinkFile( $nt, 
$file, $text );
                                }
                                # Cloak with NOPARSE to avoid replacement in 
replaceExternalLinks
@@ -3314,6 +3310,8 @@
 
        /**
         * Fetch the unparsed text of a template and register a reference to it.
+        * @param Title $title
+        * @return Array ( string or false, Title )
         */
        function fetchTemplateAndTitle( $title ) {
                $templateCb = $this->mOptions->getTemplateCallback(); # 
Defaults to Parser::statelessFetchTemplate()
@@ -3328,6 +3326,11 @@
                return array( $text, $finalTitle );
        }
 
+       /**
+        * Fetch the unparsed text of a template and register a reference to it.
+        * @param Title $title
+        * @return mixed string or false
+        */
        function fetchTemplate( $title ) {
                $rv = $this->fetchTemplateAndTitle( $title );
                return $rv[0];
@@ -3398,11 +3401,28 @@
        }
 
        /**
-        * Fetch a file and register a reference to it.
-        * @TODO: register and track file version info too
+        * Fetch a file and its title and register a reference to it.
+        * @param Title $title
+        * @param string $time MW timestamp
+        * @param string $sha1 base 36 SHA-1
+        * @return mixed File or false
         */
        function fetchFile( $title, $time = false, $sha1 = false ) {
-               if ( $sha1 ) { // get by (sha1,timestamp)
+               $res = $this->fetchFileAndTitle( $title, $time, $sha1 );
+               return $res[0];
+       }
+
+       /**
+        * Fetch a file and its title and register a reference to it.
+        * @param Title $title
+        * @param string $time MW timestamp
+        * @param string $sha1 base 36 SHA-1
+        * @return Array ( File or false, Title )
+        */
+       function fetchFileAndTitle( $title, $time = false, $sha1 = false ) {
+               if ( $time === '0' ) {
+                       $file = false; // broken thumbnail forced by hook
+               } elseif ( $sha1 ) { // get by (sha1,timestamp)
                        $file = RepoGroup::singleton()->findFileFromKey( $sha1, 
array( 'time' => $time ) );
                        if ( $file ) {
                                $title = $file->getTitle(); // file title may 
not match $title
@@ -3410,8 +3430,12 @@
                } else { // get by (name,timestamp)
                        $file = wfFindFile( $title, array( 'time' => $time ) );
                }
-               $this->mOutput->addImage( $title->getDBkey() );
-               return $file;
+               # Register the file as a dependancy
+               $time = $file ? $file->getTimestamp() : null;
+               $sha1 = $file ? $file->getSha1() : null;
+               $this->mOutput->addImage( $title->getDBkey(), $time, $sha1 );
+
+               return array( $file, $title );  
        }
 
        /**
@@ -4670,14 +4694,11 @@
                wfRunHooks( 'BeforeParserMakeImageLinkObj',
                        array( &$this, &$title, &$skip, &$time, &$descQuery, 
&$sha1 ) );
                if ( $skip ) {
-                       $this->mOutput->addImage( $title->getDBkey() ); // 
register
+                       $this->mOutput->addImage( $title->getDBkey(), null, 
null ); // register
                        return $sk->link( $title );
                }
-               # Fetch and register the file
-               $file = $this->fetchFile( $title, $time, $sha1 );
-               if ( $file ) {
-                       $title = $file->getTitle(); // file title may be 
different (via hooks)
-               }
+               # Fetch and register the file (file title may be different via 
hooks)
+               list( $file, $title ) = $this->fetchFileAndTitle( $title, 
$time, $sha1 );
                # Get parameter map
                $handler = $file ? $file->getHandler() : false;
 

Modified: trunk/phase3/includes/parser/ParserOutput.php
===================================================================
--- trunk/phase3/includes/parser/ParserOutput.php       2011-03-23 17:29:22 UTC 
(rev 84609)
+++ trunk/phase3/includes/parser/ParserOutput.php       2011-03-23 17:35:40 UTC 
(rev 84610)
@@ -109,6 +109,7 @@
                $mTemplates = array(),        # 2-D map of NS/DBK to ID for the 
template references. ID=zero for broken.
                $mTemplateIds = array(),      # 2-D map of NS/DBK to rev ID for 
the template references. ID=zero for broken.
                $mImages = array(),           # DB keys of the images used, in 
the array key only
+               $mImageTimeKeys = array(),        # DB keys of the images used 
mapped to sha1 and MW timestamp
                $mExternalLinks = array(),    # External link URLs, in the key 
only
                $mInterwikiLinks = array(),   # 2-D map of prefix/DBK (in keys 
only) for the inline interwiki links in the document.
                $mNewSection = false,         # Show a new section link?
@@ -174,7 +175,9 @@
        function getEditSectionTokens()      { return 
$this->mEditSectionTokens; }
        function &getLinks()                 { return $this->mLinks; }
        function &getTemplates()             { return $this->mTemplates; }
+       function &getTemplateIds()           { return $this->mTemplateIds; }
        function &getImages()                { return $this->mImages; }
+       function &getImageTimeKeys()         { return $this->mImageTimeKeys; }
        function &getExternalLinks()         { return $this->mExternalLinks; }
        function getNoGallery()              { return $this->mNoGallery; }
        function getHeadItems()              { return $this->mHeadItems; }
@@ -256,14 +259,21 @@
                $this->mLinks[$ns][$dbk] = $id;
        }
 
-       function addImage( $name ) {
+       /**
+        * @param $name string Title dbKey
+        * @param $timestamp string MW timestamp of file creation
+        * @param $sha string base 36 SHA-1 of file
+        * @return void
+        */
+       function addImage( $name, $timestamp, $sha1 ) {
                $this->mImages[$name] = 1;
+               $this->mImageTimeKeys[$name] = array( 'time' => $timestamp, 
'sha1' => $sha1 );
        }
 
        /**
         * @param $title Title
-        * @param  $page_id
-        * @param  $rev_id
+        * @param $page_id
+        * @param $rev_id
         * @return void
         */
        function addTemplate( $title, $page_id, $rev_id ) {


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to