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 $mTOCHTML = ''; # HTML of the TOC
00029 private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
00030
00031 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
00032 $containsOldMagic = false, $titletext = '' )
00033 {
00034 $this->mText = $text;
00035 $this->mLanguageLinks = $languageLinks;
00036 $this->mCategories = $categoryLinks;
00037 $this->mContainsOldMagic = $containsOldMagic;
00038 $this->mTitleText = $titletext;
00039 }
00040
00041 function getText() { return $this->mText; }
00042 function &getLanguageLinks() { return $this->mLanguageLinks; }
00043 function getCategoryLinks() { return array_keys( $this->mCategories ); }
00044 function &getCategories() { return $this->mCategories; }
00045 function getCacheTime() { return $this->mCacheTime; }
00046 function getTitleText() { return $this->mTitleText; }
00047 function getSections() { return $this->mSections; }
00048 function &getLinks() { return $this->mLinks; }
00049 function &getTemplates() { return $this->mTemplates; }
00050 function &getImages() { return $this->mImages; }
00051 function &getExternalLinks() { return $this->mExternalLinks; }
00052 function getNoGallery() { return $this->mNoGallery; }
00053 function getHeadItems() { return $this->mHeadItems; }
00054 function getSubtitle() { return $this->mSubtitle; }
00055 function getOutputHooks() { return (array)$this->mOutputHooks; }
00056 function getWarnings() { return array_keys( $this->mWarnings ); }
00057 function getIndexPolicy() { return $this->mIndexPolicy; }
00058 function getTOCHTML() { return $this->mTOCHTML; }
00059
00060 function containsOldMagic() { return $this->mContainsOldMagic; }
00061 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
00062 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
00063 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
00064 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
00065 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
00066 function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); }
00067 function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); }
00068 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); }
00069 function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML, $tochtml ); }
00070
00071 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
00072 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
00073 function addWarning( $s ) { $this->mWarnings[$s] = 1; }
00074
00075 function addOutputHook( $hook, $data = false ) {
00076 $this->mOutputHooks[] = array( $hook, $data );
00077 }
00078
00079 function setNewSection( $value ) {
00080 $this->mNewSection = (bool)$value;
00081 }
00082 function hideNewSection ( $value ) {
00083 $this->mHideNewSection = (bool)$value;
00084 }
00085 function getHideNewSection () {
00086 return (bool)$this->mHideNewSection;
00087 }
00088 function getNewSection() {
00089 return (bool)$this->mNewSection;
00090 }
00091
00092 function addExternalLink( $url ) {
00093 # We don't register links pointing to our own server, unless... :-)
00094 global $wgServer, $wgRegisterInternalExternals;
00095 if( $wgRegisterInternalExternals or stripos($url,$wgServer.'/')!==0)
00096 $this->mExternalLinks[$url] = 1;
00097 }
00098
00099 function addLink( $title, $id = null ) {
00100 if ( $title->isExternal() ) {
00101
00102 return;
00103 }
00104 $ns = $title->getNamespace();
00105 $dbk = $title->getDBkey();
00106 if ( $ns == NS_MEDIA ) {
00107
00108 $ns = NS_FILE;
00109 } elseif( $ns == NS_SPECIAL ) {
00110
00111
00112 return;
00113 } elseif( $dbk === '' ) {
00114
00115 return;
00116 }
00117 if ( !isset( $this->mLinks[$ns] ) ) {
00118 $this->mLinks[$ns] = array();
00119 }
00120 if ( is_null( $id ) ) {
00121 $id = $title->getArticleID();
00122 }
00123 $this->mLinks[$ns][$dbk] = $id;
00124 }
00125
00126 function addImage( $name ) {
00127 $this->mImages[$name] = 1;
00128 }
00129
00130 function addTemplate( $title, $page_id, $rev_id ) {
00131 $ns = $title->getNamespace();
00132 $dbk = $title->getDBkey();
00133 if ( !isset( $this->mTemplates[$ns] ) ) {
00134 $this->mTemplates[$ns] = array();
00135 }
00136 $this->mTemplates[$ns][$dbk] = $page_id;
00137 if ( !isset( $this->mTemplateIds[$ns] ) ) {
00138 $this->mTemplateIds[$ns] = array();
00139 }
00140 $this->mTemplateIds[$ns][$dbk] = $rev_id;
00141 }
00142
00152 function expired( $touched ) {
00153 global $wgCacheEpoch;
00154 return $this->getCacheTime() == -1 ||
00155 $this->getCacheTime() < $touched ||
00156 $this->getCacheTime() <= $wgCacheEpoch ||
00157 !isset( $this->mVersion ) ||
00158 version_compare( $this->mVersion, Parser::VERSION, "lt" );
00159 }
00160
00166 function addHeadItem( $section, $tag = false ) {
00167 if ( $tag !== false ) {
00168 $this->mHeadItems[$tag] = $section;
00169 } else {
00170 $this->mHeadItems[] = $section;
00171 }
00172 }
00173
00181 public function setDisplayTitle( $text ) {
00182 $this->setTitleText( $text );
00183 }
00184
00190 public function getDisplayTitle() {
00191 $t = $this->getTitleText( );
00192 if( $t === '' ) {
00193 return false;
00194 }
00195 return $t;
00196 }
00197
00201 public function setFlag( $flag ) {
00202 $this->mFlags[$flag] = true;
00203 }
00204
00205 public function getFlag( $flag ) {
00206 return isset( $this->mFlags[$flag] );
00207 }
00208
00212 public function setProperty( $name, $value ) {
00213 $this->mProperties[$name] = $value;
00214 }
00215
00216 public function getProperty( $name ){
00217 return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false;
00218 }
00219
00220 public function getProperties() {
00221 if ( !isset( $this->mProperties ) ) {
00222 $this->mProperties = array();
00223 }
00224 return $this->mProperties;
00225 }
00226 }