r22600 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22599‎ | r22600 | r22601 >
Date:16:01, 31 May 2007
Author:aaron
Status:old
Tags:
Comment:
*Add BeforeGalleryFindFile, TitleLinkUpdatesAfterCompletion, BeforeParserFetchTemplateAndtitle, BeforeParserMakeImageLinkObj, BeforeParserrenderImageGallery; make parser outputs and output page record images -> timestamps used and templates -> revision ids
Modified paths:
  • /trunk/phase3/includes/ImageGallery.php (modified) (history)
  • /trunk/phase3/includes/LinksUpdate.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/ParserOutput.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ParserOutput.php
@@ -14,7 +14,9 @@
1515 $mTitleText, # title text of the chosen language variant
1616 $mLinks, # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
1717 $mTemplates, # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
 18+ $mTemplateIds, # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
1819 $mImages, # DB keys of the images used, in the array key only
 20+ $mImageTimestamps, # Map of DBK to rev ID for the template references. ID=zero for broken.
1921 $mExternalLinks, # External link URLs, in the key only
2022 $mHTMLtitle, # Display HTML title
2123 $mSubtitle, # Additional subtitle
@@ -41,10 +43,12 @@
4244 $this->mNewSection = false;
4345 $this->mNoGallery = false;
4446 $this->mHeadItems = array();
 47+ $this->mTemplateIds = array();
 48+ $this->mImageTimestamps = array();
4549 }
4650
4751 function getText() { return $this->mText; }
48 - function &getLanguageLinks() { return $this->mLanguageLinks; }
 52+ function &getLanguageLinks() { return $this->mLanguageLinks; }
4953 function getCategoryLinks() { return array_keys( $this->mCategories ); }
5054 function &getCategories() { return $this->mCategories; }
5155 function getCacheTime() { return $this->mCacheTime; }
@@ -66,7 +70,6 @@
6771 function setSubtitle( $st ) { return wfSetVar( $this->mSubtitle, $st ); }
6872
6973 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
70 - function addImage( $name ) { $this->mImages[$name] = 1; }
7174 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
7275 function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
7376
@@ -88,14 +91,33 @@
8992 }
9093 $this->mLinks[$ns][$dbk] = $id;
9194 }
 95+
 96+ function addImage( $name, $timestamp=NULL ) {
 97+ if( isset($this->mImages[$name]) )
 98+ return; // No repeated pointless DB calls!
 99+ $this->mImages[$name] = 1;
 100+ if( is_null($timestamp) ) {
 101+ wfProfileIn( __METHOD__ );
 102+ $dbr = wfGetDB(DB_SLAVE);
 103+ $timestamp = $dbr->selectField('image', 'img_timestamp',
 104+ array('img_name' => $name),
 105+ __METHOD__ );
 106+ }
 107+ $timestamp = $timestamp ? $timestamp : 0;
 108+ $this->mImageTimestamps[$name] = $timestamp; // For versioning
 109+ }
92110
93 - function addTemplate( $title, $id ) {
 111+ function addTemplate( $title, $page_id, $rev_id ) {
94112 $ns = $title->getNamespace();
95113 $dbk = $title->getDBkey();
96114 if ( !isset( $this->mTemplates[$ns] ) ) {
97115 $this->mTemplates[$ns] = array();
98116 }
99 - $this->mTemplates[$ns][$dbk] = $id;
 117+ $this->mTemplates[$ns][$dbk] = $page_id;
 118+ if ( !isset( $this->mTemplateIds[$ns] ) ) {
 119+ $this->mTemplateIds[$ns] = array();
 120+ }
 121+ $this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
100122 }
101123
102124 /**
Index: trunk/phase3/includes/Parser.php
@@ -400,12 +400,15 @@
401401 * Expand templates and variables in the text, producing valid, static wikitext.
402402 * Also removes comments.
403403 */
404 - function preprocess( $text, $title, $options ) {
 404+ function preprocess( $text, $title, $options, $revid = null ) {
405405 wfProfileIn( __METHOD__ );
406406 $this->clearState();
407407 $this->setOutputType( OT_PREPROCESS );
408408 $this->mOptions = $options;
409409 $this->mTitle = $title;
 410+ if( $revid !== null ) {
 411+ $this->mRevisionId = $revid;
 412+ }
410413 wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
411414 $text = $this->strip( $text, $this->mStripState );
412415 wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
@@ -3264,13 +3267,25 @@
32653268 * Fetch the unparsed text of a template and register a reference to it.
32663269 */
32673270 function fetchTemplateAndtitle( $title ) {
3268 - $text = false;
 3271+ $text = $skip = false;
32693272 $finalTitle = $title;
32703273 // Loop to fetch the article, with up to 1 redirect
32713274 for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
3272 - $rev = Revision::newFromTitle( $title );
3273 - $this->mOutput->addTemplate( $title, $title->getArticleID() );
3274 - if ( $rev ) {
 3275+ # Give extensions a chance to select the revision instead
 3276+ $id = false; // Assume current
 3277+ wfRunHooks( 'BeforeParserFetchTemplateAndtitle', array( &$this, &$title, &$skip, &$id ) );
 3278+
 3279+ if( $skip ) {
 3280+ $text = false;
 3281+ $this->mOutput->addTemplate( $title, $title->getArticleID(), 0 );
 3282+ break;
 3283+ }
 3284+ $rev = $id ? Revision::newFromId( $id ) : Revision::newFromTitle( $title );
 3285+ $rev_id = $rev ? $rev->getId() : 0;
 3286+
 3287+ $this->mOutput->addTemplate( $title, $title->getArticleID(), $rev_id );
 3288+
 3289+ if( $rev ) {
32753290 $text = $rev->getText();
32763291 } elseif( $title->getNamespace() == NS_MEDIAWIKI ) {
32773292 global $wgLang;
@@ -4124,7 +4139,7 @@
41254140 }
41264141
41274142 // process categories, check if a category exists in some variant
4128 - foreach( $categories as $category){
 4143+ foreach( $categories as $category ){
41294144 $variants = $wgContLang->convertLinkToAllVariants($category);
41304145 foreach($variants as $variant){
41314146 if($variant != $category){
@@ -4346,6 +4361,7 @@
43474362 $ig->setShowFilename( false );
43484363 $ig->setParsing();
43494364 $ig->useSkin( $this->mOptions->getSkin() );
 4365+ $ig->mRevisionId = $this->mRevisionId;
43504366
43514367 if( isset( $params['caption'] ) ) {
43524368 $caption = $params['caption'];
@@ -4362,6 +4378,8 @@
43634379 if( isset( $params['heights'] ) ) {
43644380 $ig->setHeights( $params['heights'] );
43654381 }
 4382+
 4383+ wfRunHooks( 'BeforeParserrenderImageGallery', array( &$this, &$ig ) );
43664384
43674385 $lines = explode( "\n", $text );
43684386 foreach ( $lines as $line ) {
@@ -4510,8 +4528,18 @@
45114529 $alt = $this->mStripState->unstripBoth( $alt );
45124530 $alt = Sanitizer::stripAllTags( $alt );
45134531
 4532+ # Give extensions a chance to select the file revision for us
 4533+ $skip = $time = false;
 4534+ wfRunHooks( 'BeforeParserMakeImageLinkObj', array( &$this, &$nt, &$skip, &$time ) );
 4535+
45144536 # Linker does the rest
4515 - return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $params, $framed, $thumb, $manual_thumb, $valign );
 4537+ if( $skip ) {
 4538+ $link = $sk->makeLinkObj( $nt );
 4539+ } else {
 4540+ $link = $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $params, $framed, $thumb, $manual_thumb, $valign, $time );
 4541+ }
 4542+
 4543+ return $link;
45164544 }
45174545
45184546 /**
Index: trunk/phase3/includes/OutputPage.php
@@ -54,6 +54,8 @@
5555 $this->mETag = false;
5656 $this->mRevisionId = null;
5757 $this->mNewSectionLink = false;
 58+ $this->mTemplateIds = array();
 59+ $this->mImageTimestamps = array();
5860 }
5961
6062 public function redirect( $url, $responsecode = '302' ) {
@@ -384,6 +386,10 @@
385387 }
386388 $this->mNoGallery = $parserOutput->getNoGallery();
387389 $this->mHeadItems = array_merge( $this->mHeadItems, (array)$parserOutput->mHeadItems );
 390+ // Versioning...
 391+ $this->mTemplateIds += (array)$parserOutput->mTemplateIds;
 392+ $this->mImageTimestamps += (array)$parserOutput->mImageTimestamps;
 393+
388394 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
389395 }
390396
Index: trunk/phase3/includes/LinksUpdate.php
@@ -76,6 +76,7 @@
7777 } else {
7878 $this->doIncrementalUpdate();
7979 }
 80+ wfRunHooks( 'TitleLinkUpdatesAfterCompletion', array( &$this->mTitle ) );
8081 }
8182
8283 function doIncrementalUpdate() {
Index: trunk/phase3/includes/ImageGallery.php
@@ -17,6 +17,7 @@
1818 var $mImages, $mShowBytes, $mShowFilename;
1919 var $mCaption = false;
2020 var $mSkin = false;
 21+ var $mRevisionId = 0;
2122
2223 /**
2324 * Is the gallery on a wiki page (i.e. not a special page)
@@ -201,8 +202,12 @@
202203 foreach ( $this->mImages as $pair ) {
203204 $nt = $pair[0];
204205 $text = $pair[1];
 206+
 207+ # Give extensions a chance to select the file revision for us
 208+ $time = false;
 209+ wfRunHooks( 'BeforeGalleryFindFile', array( &$this, &$nt, &$time ) );
205210
206 - $img = wfFindFile( $nt );
 211+ $img = wfFindFile( $nt, $time );
207212
208213 if( $nt->getNamespace() != NS_IMAGE || !$img ) {
209214 # We're dealing with a non-image, spit out the name and be done with it.

Follow-up revisions

RevisionCommit summaryAuthorDate
r22619Merged revisions 22587-22618 via svnmerge from...david04:13, 1 June 2007