00001 <?php
00006 class ParserOutput
00007 {
00008 var $mText, # The output text
00009 $mLanguageLinks, # List of the full text of language links, in the order they appear
00010 $mCategories, # Map of category names to sort keys
00011 $mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
00012 $mTitleText, # title text of the chosen language variant
00013 $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
00014 $mVersion = Parser::VERSION, # Compatibility check
00015 $mLinks = array(), # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
00016 $mTemplates = array(), # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
00017 $mTemplateIds = array(), # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
00018 $mImages = array(), # DB keys of the images used, in the array key only
00019 $mExternalLinks = array(), # External link URLs, in the key only
00020 $mNewSection = false, # Show a new section link?
00021 $mHideNewSection = false, # Hide the new section link?
00022 $mNoGallery = false, # No gallery on category page? (__NOGALLERY__)
00023 $mHeadItems = array(), # Items to put in the <head> section
00024 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
00025 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
00026 $mSections = array(), # Table of contents
00027 $mProperties = array(); # Name/value pairs to be cached in the DB
00028 private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
00029
00033 private $displayTitle = false;
00034
00035 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
00036 $containsOldMagic = false, $titletext = '' )
00037 {
00038 $this->mText = $text;
00039 $this->mLanguageLinks = $languageLinks;
00040 $this->mCategories = $categoryLinks;
00041 $this->mContainsOldMagic = $containsOldMagic;
00042 $this->mTitleText = $titletext;
00043 }
00044
00045 function getText() { return $this->mText; }
00046 function &getLanguageLinks() { return $this->mLanguageLinks; }
00047 function getCategoryLinks() { return array_keys( $this->mCategories ); }
00048 function &getCategories() { return $this->mCategories; }
00049 function getCacheTime() { return $this->mCacheTime; }
00050 function getTitleText() { return $this->mTitleText; }
00051 function getSections() { return $this->mSections; }
00052 function &getLinks() { return $this->mLinks; }
00053 function &getTemplates() { return $this->mTemplates; }
00054 function &getImages() { return $this->mImages; }
00055 function &getExternalLinks() { return $this->mExternalLinks; }
00056 function getNoGallery() { return $this->mNoGallery; }
00057 function getSubtitle() { return $this->mSubtitle; }
00058 function getOutputHooks() { return (array)$this->mOutputHooks; }
00059 function getWarnings() { return array_keys( $this->mWarnings ); }
00060 function getIndexPolicy() { return $this->mIndexPolicy; }
00061
00062 function containsOldMagic() { return $this->mContainsOldMagic; }
00063 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
00064 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
00065 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
00066 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
00067 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
00068 function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); }
00069 function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); }
00070 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); }
00071
00072 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
00073 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
00074 function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
00075 function addWarning( $s ) { $this->mWarnings[$s] = 1; }
00076
00077 function addOutputHook( $hook, $data = false ) {
00078 $this->mOutputHooks[] = array( $hook, $data );
00079 }
00080
00081 function setNewSection( $value ) {
00082 $this->mNewSection = (bool)$value;
00083 }
00084 function hideNewSection ( $value ) {
00085 $this->mHideNewSection = (bool)$value;
00086 }
00087 function getHideNewSection () {
00088 return (bool)$this->mHideNewSection;
00089 }
00090 function getNewSection() {
00091 return (bool)$this->mNewSection;
00092 }
00093
00094 function addLink( $title, $id = null ) {
00095 $ns = $title->getNamespace();
00096 $dbk = $title->getDBkey();
00097 if ( $ns == NS_MEDIA ) {
00098
00099 $ns = NS_FILE;
00100 } elseif( $ns == NS_SPECIAL ) {
00101
00102
00103 return;
00104 } elseif( $dbk === '' ) {
00105
00106 return;
00107 }
00108 if ( !isset( $this->mLinks[$ns] ) ) {
00109 $this->mLinks[$ns] = array();
00110 }
00111 if ( is_null( $id ) ) {
00112 $id = $title->getArticleID();
00113 }
00114 $this->mLinks[$ns][$dbk] = $id;
00115 }
00116
00117 function addImage( $name ) {
00118 $this->mImages[$name] = 1;
00119 }
00120
00121 function addTemplate( $title, $page_id, $rev_id ) {
00122 $ns = $title->getNamespace();
00123 $dbk = $title->getDBkey();
00124 if ( !isset( $this->mTemplates[$ns] ) ) {
00125 $this->mTemplates[$ns] = array();
00126 }
00127 $this->mTemplates[$ns][$dbk] = $page_id;
00128 if ( !isset( $this->mTemplateIds[$ns] ) ) {
00129 $this->mTemplateIds[$ns] = array();
00130 }
00131 $this->mTemplateIds[$ns][$dbk] = $rev_id;
00132 }
00133
00143 function expired( $touched ) {
00144 global $wgCacheEpoch;
00145 return $this->getCacheTime() == -1 ||
00146 $this->getCacheTime() < $touched ||
00147 $this->getCacheTime() <= $wgCacheEpoch ||
00148 !isset( $this->mVersion ) ||
00149 version_compare( $this->mVersion, Parser::VERSION, "lt" );
00150 }
00151
00157 function addHeadItem( $section, $tag = false ) {
00158 if ( $tag !== false ) {
00159 $this->mHeadItems[$tag] = $section;
00160 } else {
00161 $this->mHeadItems[] = $section;
00162 }
00163 }
00164
00172 public function setDisplayTitle( $text ) {
00173 $this->displayTitle = $text;
00174 }
00175
00181 public function getDisplayTitle() {
00182 return $this->displayTitle;
00183 }
00184
00188 public function setFlag( $flag ) {
00189 $this->mFlags[$flag] = true;
00190 }
00191
00192 public function getFlag( $flag ) {
00193 return isset( $this->mFlags[$flag] );
00194 }
00195
00199 public function setProperty( $name, $value ) {
00200 $this->mProperties[$name] = $value;
00201 }
00202
00203 public function getProperty( $name ){
00204 return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false;
00205 }
00206
00207 public function getProperties() {
00208 if ( !isset( $this->mProperties ) ) {
00209 $this->mProperties = array();
00210 }
00211 return $this->mProperties;
00212 }
00213 }