var $mImages, $mShowBytes, $mShowFilename;
var $mCaption = false;
var $mSkin = false;
+ var $mRevisionId = 0;
/**
* Is the gallery on a wiki page (i.e. not a special page)
foreach ( $this->mImages as $pair ) {
$nt = $pair[0];
$text = $pair[1];
+
+ # Give extensions a chance to select the file revision for us
+ $time = false;
+ wfRunHooks( 'BeforeGalleryFindFile', array( &$this, &$nt, &$time ) );
- $img = wfFindFile( $nt );
+ $img = wfFindFile( $nt, $time );
if( $nt->getNamespace() != NS_IMAGE || !$img ) {
# We're dealing with a non-image, spit out the name and be done with it.
} else {
$this->doIncrementalUpdate();
}
+ wfRunHooks( 'TitleLinkUpdatesAfterCompletion', array( &$this->mTitle ) );
}
function doIncrementalUpdate() {
$this->mETag = false;
$this->mRevisionId = null;
$this->mNewSectionLink = false;
+ $this->mTemplateIds = array();
+ $this->mImageTimestamps = array();
}
public function redirect( $url, $responsecode = '302' ) {
}
$this->mNoGallery = $parserOutput->getNoGallery();
$this->mHeadItems = array_merge( $this->mHeadItems, (array)$parserOutput->mHeadItems );
+ // Versioning...
+ $this->mTemplateIds += (array)$parserOutput->mTemplateIds;
+ $this->mImageTimestamps += (array)$parserOutput->mImageTimestamps;
+
wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
}
* Expand templates and variables in the text, producing valid, static wikitext.
* Also removes comments.
*/
- function preprocess( $text, $title, $options ) {
+ function preprocess( $text, $title, $options, $revid = null ) {
wfProfileIn( __METHOD__ );
$this->clearState();
$this->setOutputType( OT_PREPROCESS );
$this->mOptions = $options;
$this->mTitle = $title;
+ if( $revid !== null ) {
+ $this->mRevisionId = $revid;
+ }
wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
$text = $this->strip( $text, $this->mStripState );
wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
* Fetch the unparsed text of a template and register a reference to it.
*/
function fetchTemplateAndtitle( $title ) {
- $text = false;
+ $text = $skip = false;
$finalTitle = $title;
// Loop to fetch the article, with up to 1 redirect
for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
- $rev = Revision::newFromTitle( $title );
- $this->mOutput->addTemplate( $title, $title->getArticleID() );
- if ( $rev ) {
+ # Give extensions a chance to select the revision instead
+ $id = false; // Assume current
+ wfRunHooks( 'BeforeParserFetchTemplateAndtitle', array( &$this, &$title, &$skip, &$id ) );
+
+ if( $skip ) {
+ $text = false;
+ $this->mOutput->addTemplate( $title, $title->getArticleID(), 0 );
+ break;
+ }
+ $rev = $id ? Revision::newFromId( $id ) : Revision::newFromTitle( $title );
+ $rev_id = $rev ? $rev->getId() : 0;
+
+ $this->mOutput->addTemplate( $title, $title->getArticleID(), $rev_id );
+
+ if( $rev ) {
$text = $rev->getText();
} elseif( $title->getNamespace() == NS_MEDIAWIKI ) {
global $wgLang;
}
// process categories, check if a category exists in some variant
- foreach( $categories as $category){
+ foreach( $categories as $category ){
$variants = $wgContLang->convertLinkToAllVariants($category);
foreach($variants as $variant){
if($variant != $category){
$ig->setShowFilename( false );
$ig->setParsing();
$ig->useSkin( $this->mOptions->getSkin() );
+ $ig->mRevisionId = $this->mRevisionId;
if( isset( $params['caption'] ) ) {
$caption = $params['caption'];
if( isset( $params['heights'] ) ) {
$ig->setHeights( $params['heights'] );
}
+
+ wfRunHooks( 'BeforeParserrenderImageGallery', array( &$this, &$ig ) );
$lines = explode( "\n", $text );
foreach ( $lines as $line ) {
$alt = $this->mStripState->unstripBoth( $alt );
$alt = Sanitizer::stripAllTags( $alt );
+ # Give extensions a chance to select the file revision for us
+ $skip = $time = false;
+ wfRunHooks( 'BeforeParserMakeImageLinkObj', array( &$this, &$nt, &$skip, &$time ) );
+
# Linker does the rest
- return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $params, $framed, $thumb, $manual_thumb, $valign );
+ if( $skip ) {
+ $link = $sk->makeLinkObj( $nt );
+ } else {
+ $link = $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $params, $framed, $thumb, $manual_thumb, $valign, $time );
+ }
+
+ return $link;
}
/**
$mTitleText, # title text of the chosen language variant
$mLinks, # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
$mTemplates, # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
+ $mTemplateIds, # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
$mImages, # DB keys of the images used, in the array key only
+ $mImageTimestamps, # Map of DBK to rev ID for the template references. ID=zero for broken.
$mExternalLinks, # External link URLs, in the key only
$mHTMLtitle, # Display HTML title
$mSubtitle, # Additional subtitle
$this->mNewSection = false;
$this->mNoGallery = false;
$this->mHeadItems = array();
+ $this->mTemplateIds = array();
+ $this->mImageTimestamps = array();
}
function getText() { return $this->mText; }
- function &getLanguageLinks() { return $this->mLanguageLinks; }
+ function &getLanguageLinks() { return $this->mLanguageLinks; }
function getCategoryLinks() { return array_keys( $this->mCategories ); }
function &getCategories() { return $this->mCategories; }
function getCacheTime() { return $this->mCacheTime; }
function setSubtitle( $st ) { return wfSetVar( $this->mSubtitle, $st ); }
function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
- function addImage( $name ) { $this->mImages[$name] = 1; }
function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
}
$this->mLinks[$ns][$dbk] = $id;
}
+
+ function addImage( $name, $timestamp=NULL ) {
+ if( isset($this->mImages[$name]) )
+ return; // No repeated pointless DB calls!
+ $this->mImages[$name] = 1;
+ if( is_null($timestamp) ) {
+ wfProfileIn( __METHOD__ );
+ $dbr = wfGetDB(DB_SLAVE);
+ $timestamp = $dbr->selectField('image', 'img_timestamp',
+ array('img_name' => $name),
+ __METHOD__ );
+ }
+ $timestamp = $timestamp ? $timestamp : 0;
+ $this->mImageTimestamps[$name] = $timestamp; // For versioning
+ }
- function addTemplate( $title, $id ) {
+ function addTemplate( $title, $page_id, $rev_id ) {
$ns = $title->getNamespace();
$dbk = $title->getDBkey();
if ( !isset( $this->mTemplates[$ns] ) ) {
$this->mTemplates[$ns] = array();
}
- $this->mTemplates[$ns][$dbk] = $id;
+ $this->mTemplates[$ns][$dbk] = $page_id;
+ if ( !isset( $this->mTemplateIds[$ns] ) ) {
+ $this->mTemplateIds[$ns] = array();
+ }
+ $this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
}
/**