2007-01-20 12:50:56 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* @todo document
|
2007-04-20 08:55:14 +00:00
|
|
|
* @addtogroup Parser
|
2007-01-20 12:50:56 +00:00
|
|
|
*/
|
|
|
|
|
class ParserOutput
|
|
|
|
|
{
|
|
|
|
|
var $mText, # The output text
|
|
|
|
|
$mLanguageLinks, # List of the full text of language links, in the order they appear
|
|
|
|
|
$mCategories, # Map of category names to sort keys
|
|
|
|
|
$mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
|
|
|
|
|
$mCacheTime, # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
|
|
|
|
|
$mVersion, # Compatibility check
|
|
|
|
|
$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.
|
2007-05-31 16:01:26 +00:00
|
|
|
$mTemplateIds, # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
|
2007-01-20 12:50:56 +00:00
|
|
|
$mImages, # DB keys of the images used, in the array key only
|
|
|
|
|
$mExternalLinks, # External link URLs, in the key only
|
2007-04-03 21:58:18 +00:00
|
|
|
$mNewSection, # Show a new section link?
|
|
|
|
|
$mNoGallery, # No gallery on category page? (__NOGALLERY__)
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$mHeadItems, # Items to put in the <head> section
|
2007-12-10 06:02:29 +00:00
|
|
|
$mOutputHooks, # Hook tags as per $wgParserOutputHooks
|
2007-12-27 20:14:07 +00:00
|
|
|
$mWarnings, # Warning text to be returned to the user. Wikitext formatted.
|
2008-02-20 08:53:12 +00:00
|
|
|
$mSections, # Table of contents
|
|
|
|
|
$mProperties; # Name/value pairs to be cached in the DB
|
|
|
|
|
|
2007-06-25 15:51:09 +00:00
|
|
|
/**
|
|
|
|
|
* Overridden title for display
|
|
|
|
|
*/
|
|
|
|
|
private $displayTitle = false;
|
2007-01-20 12:50:56 +00:00
|
|
|
|
|
|
|
|
function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
|
|
|
|
|
$containsOldMagic = false, $titletext = '' )
|
|
|
|
|
{
|
|
|
|
|
$this->mText = $text;
|
|
|
|
|
$this->mLanguageLinks = $languageLinks;
|
|
|
|
|
$this->mCategories = $categoryLinks;
|
|
|
|
|
$this->mContainsOldMagic = $containsOldMagic;
|
|
|
|
|
$this->mCacheTime = '';
|
2007-01-20 21:22:31 +00:00
|
|
|
$this->mVersion = Parser::VERSION;
|
2007-01-20 12:50:56 +00:00
|
|
|
$this->mTitleText = $titletext;
|
2007-12-28 08:41:45 +00:00
|
|
|
$this->mSections = array();
|
2007-01-20 12:50:56 +00:00
|
|
|
$this->mLinks = array();
|
|
|
|
|
$this->mTemplates = array();
|
|
|
|
|
$this->mImages = array();
|
|
|
|
|
$this->mExternalLinks = array();
|
|
|
|
|
$this->mNewSection = false;
|
|
|
|
|
$this->mNoGallery = false;
|
2007-04-03 21:58:18 +00:00
|
|
|
$this->mHeadItems = array();
|
2007-05-31 16:01:26 +00:00
|
|
|
$this->mTemplateIds = array();
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$this->mOutputHooks = array();
|
2007-12-10 06:02:29 +00:00
|
|
|
$this->mWarnings = array();
|
2008-02-20 08:53:12 +00:00
|
|
|
$this->mProperties = array();
|
2007-01-20 12:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getText() { return $this->mText; }
|
2007-05-31 16:01:26 +00:00
|
|
|
function &getLanguageLinks() { return $this->mLanguageLinks; }
|
2007-01-20 12:50:56 +00:00
|
|
|
function getCategoryLinks() { return array_keys( $this->mCategories ); }
|
|
|
|
|
function &getCategories() { return $this->mCategories; }
|
|
|
|
|
function getCacheTime() { return $this->mCacheTime; }
|
|
|
|
|
function getTitleText() { return $this->mTitleText; }
|
2007-12-27 20:14:07 +00:00
|
|
|
function getSections() { return $this->mSections; }
|
2007-01-20 12:50:56 +00:00
|
|
|
function &getLinks() { return $this->mLinks; }
|
|
|
|
|
function &getTemplates() { return $this->mTemplates; }
|
|
|
|
|
function &getImages() { return $this->mImages; }
|
|
|
|
|
function &getExternalLinks() { return $this->mExternalLinks; }
|
|
|
|
|
function getNoGallery() { return $this->mNoGallery; }
|
|
|
|
|
function getSubtitle() { return $this->mSubtitle; }
|
2007-08-15 20:46:51 +00:00
|
|
|
function getOutputHooks() { return (array)$this->mOutputHooks; }
|
2007-12-10 06:02:29 +00:00
|
|
|
function getWarnings() { return isset( $this->mWarnings ) ? $this->mWarnings : array(); }
|
2007-01-20 12:50:56 +00:00
|
|
|
|
|
|
|
|
function containsOldMagic() { return $this->mContainsOldMagic; }
|
|
|
|
|
function setText( $text ) { return wfSetVar( $this->mText, $text ); }
|
|
|
|
|
function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
|
|
|
|
|
function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
|
|
|
|
|
function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
|
|
|
|
|
function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
|
2007-12-27 20:14:07 +00:00
|
|
|
function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); }
|
|
|
|
|
function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); }
|
2007-01-20 12:50:56 +00:00
|
|
|
|
|
|
|
|
function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
|
|
|
|
|
function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
|
|
|
|
|
function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
|
2007-12-10 06:02:29 +00:00
|
|
|
function addWarning( $s ) { $this->mWarnings[] = $s; }
|
2007-01-20 12:50:56 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
function addOutputHook( $hook, $data = false ) {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
$this->mOutputHooks[] = array( $hook, $data );
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-20 12:50:56 +00:00
|
|
|
function setNewSection( $value ) {
|
|
|
|
|
$this->mNewSection = (bool)$value;
|
|
|
|
|
}
|
|
|
|
|
function getNewSection() {
|
|
|
|
|
return (bool)$this->mNewSection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addLink( $title, $id = null ) {
|
|
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$dbk = $title->getDBkey();
|
|
|
|
|
if ( !isset( $this->mLinks[$ns] ) ) {
|
|
|
|
|
$this->mLinks[$ns] = array();
|
|
|
|
|
}
|
|
|
|
|
if ( is_null( $id ) ) {
|
|
|
|
|
$id = $title->getArticleID();
|
|
|
|
|
}
|
|
|
|
|
$this->mLinks[$ns][$dbk] = $id;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-06-20 07:10:06 +00:00
|
|
|
function addImage( $name ) {
|
2007-05-31 16:01:26 +00:00
|
|
|
$this->mImages[$name] = 1;
|
|
|
|
|
}
|
2007-01-20 12:50:56 +00:00
|
|
|
|
2007-05-31 16:01:26 +00:00
|
|
|
function addTemplate( $title, $page_id, $rev_id ) {
|
2007-01-20 12:50:56 +00:00
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$dbk = $title->getDBkey();
|
|
|
|
|
if ( !isset( $this->mTemplates[$ns] ) ) {
|
|
|
|
|
$this->mTemplates[$ns] = array();
|
|
|
|
|
}
|
2007-05-31 16:01:26 +00:00
|
|
|
$this->mTemplates[$ns][$dbk] = $page_id;
|
|
|
|
|
if ( !isset( $this->mTemplateIds[$ns] ) ) {
|
|
|
|
|
$this->mTemplateIds[$ns] = array();
|
|
|
|
|
}
|
|
|
|
|
$this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
|
2007-01-20 12:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return true if this cached output object predates the global or
|
|
|
|
|
* per-article cache invalidation timestamps, or if it comes from
|
|
|
|
|
* an incompatible older version.
|
|
|
|
|
*
|
|
|
|
|
* @param string $touched the affected article's last touched timestamp
|
|
|
|
|
* @return bool
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
function expired( $touched ) {
|
|
|
|
|
global $wgCacheEpoch;
|
|
|
|
|
return $this->getCacheTime() == -1 || // parser says it's uncacheable
|
|
|
|
|
$this->getCacheTime() < $touched ||
|
|
|
|
|
$this->getCacheTime() <= $wgCacheEpoch ||
|
|
|
|
|
!isset( $this->mVersion ) ||
|
2007-01-20 21:22:31 +00:00
|
|
|
version_compare( $this->mVersion, Parser::VERSION, "lt" );
|
2007-01-20 12:50:56 +00:00
|
|
|
}
|
2007-04-03 21:58:18 +00:00
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Add some text to the <head>.
|
|
|
|
|
* If $tag is set, the section with that tag will only be included once
|
2007-04-03 21:58:18 +00:00
|
|
|
* in a given page.
|
|
|
|
|
*/
|
|
|
|
|
function addHeadItem( $section, $tag = false ) {
|
|
|
|
|
if ( $tag !== false ) {
|
|
|
|
|
$this->mHeadItems[$tag] = $section;
|
|
|
|
|
} else {
|
|
|
|
|
$this->mHeadItems[] = $section;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-06-25 15:51:09 +00:00
|
|
|
/**
|
|
|
|
|
* Override the title to be used for display
|
|
|
|
|
* -- this is assumed to have been validated
|
|
|
|
|
* (check equal normalisation, etc.)
|
|
|
|
|
*
|
|
|
|
|
* @param string $text Desired title text
|
|
|
|
|
*/
|
|
|
|
|
public function setDisplayTitle( $text ) {
|
|
|
|
|
$this->displayTitle = $text;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-06-25 15:51:09 +00:00
|
|
|
/**
|
|
|
|
|
* Get the title to be used for display
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getDisplayTitle() {
|
|
|
|
|
return $this->displayTitle;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-15 02:54:28 +00:00
|
|
|
/**
|
|
|
|
|
* Fairly generic flag setter thingy.
|
|
|
|
|
*/
|
|
|
|
|
public function setFlag( $flag ) {
|
|
|
|
|
$this->mFlags[$flag] = true;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-11-15 02:54:28 +00:00
|
|
|
public function getFlag( $flag ) {
|
|
|
|
|
return isset( $this->mFlags[$flag] );
|
|
|
|
|
}
|
2008-02-20 08:53:12 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a property to be cached in the DB
|
|
|
|
|
*/
|
|
|
|
|
public function setProperty( $name, $value ) {
|
|
|
|
|
$this->mProperties[$name] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
public function getProperty( $name ){
|
2008-02-20 08:53:12 +00:00
|
|
|
return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getProperties() {
|
|
|
|
|
if ( !isset( $this->mProperties ) ) {
|
|
|
|
|
$this->mProperties = array();
|
|
|
|
|
}
|
|
|
|
|
return $this->mProperties;
|
|
|
|
|
}
|
2007-01-20 12:50:56 +00:00
|
|
|
}
|