8 var $mText, # The output text
9 $mLanguageLinks, # List of the full text of language links, in the order they appear
10 $mCategories, # Map of category names to sort keys
11 $mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
12 $mTitleText, # title text of the chosen language variant
13 $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
14 $mVersion = Parser
::VERSION
, # Compatibility check
15 $mLinks = array(), # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
16 $mTemplates = array(), # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
17 $mTemplateIds = array(), # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
18 $mImages = array(), # DB keys of the images used, in the array key only
19 $mExternalLinks = array(), # External link URLs, in the key only
20 $mNewSection = false, # Show a new section link?
21 $mHideNewSection = false, # Hide the new section link?
22 $mNoGallery = false, # No gallery on category page? (__NOGALLERY__)
23 $mHeadItems = array(), # Items to put in the <head> section
24 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
25 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
26 $mSections = array(), # Table of contents
27 $mProperties = array(), # Name/value pairs to be cached in the DB
28 $mTOCHTML = ''; # HTML of the TOC
29 private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
31 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
32 $containsOldMagic = false, $titletext = '' )
35 $this->mLanguageLinks
= $languageLinks;
36 $this->mCategories
= $categoryLinks;
37 $this->mContainsOldMagic
= $containsOldMagic;
38 $this->mTitleText
= $titletext;
41 function getText() { return $this->mText
; }
42 function &getLanguageLinks() { return $this->mLanguageLinks
; }
43 function getCategoryLinks() { return array_keys( $this->mCategories
); }
44 function &getCategories() { return $this->mCategories
; }
45 function getCacheTime() { return $this->mCacheTime
; }
46 function getTitleText() { return $this->mTitleText
; }
47 function getSections() { return $this->mSections
; }
48 function &getLinks() { return $this->mLinks
; }
49 function &getTemplates() { return $this->mTemplates
; }
50 function &getImages() { return $this->mImages
; }
51 function &getExternalLinks() { return $this->mExternalLinks
; }
52 function getNoGallery() { return $this->mNoGallery
; }
53 function getSubtitle() { return $this->mSubtitle
; }
54 function getOutputHooks() { return (array)$this->mOutputHooks
; }
55 function getWarnings() { return array_keys( $this->mWarnings
); }
56 function getIndexPolicy() { return $this->mIndexPolicy
; }
57 function getTOCHTML() { return $this->mTOCHTML
; }
59 function containsOldMagic() { return $this->mContainsOldMagic
; }
60 function setText( $text ) { return wfSetVar( $this->mText
, $text ); }
61 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks
, $ll ); }
62 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories
, $cl ); }
63 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic
, $com ); }
64 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime
, $t ); }
65 function setTitleText( $t ) { return wfSetVar( $this->mTitleText
, $t ); }
66 function setSections( $toc ) { return wfSetVar( $this->mSections
, $toc ); }
67 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy
, $policy ); }
68 function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML
, $tochtml ); }
70 function addCategory( $c, $sort ) { $this->mCategories
[$c] = $sort; }
71 function addLanguageLink( $t ) { $this->mLanguageLinks
[] = $t; }
72 function addWarning( $s ) { $this->mWarnings
[$s] = 1; }
74 function addOutputHook( $hook, $data = false ) {
75 $this->mOutputHooks
[] = array( $hook, $data );
78 function setNewSection( $value ) {
79 $this->mNewSection
= (bool)$value;
81 function hideNewSection ( $value ) {
82 $this->mHideNewSection
= (bool)$value;
84 function getHideNewSection () {
85 return (bool)$this->mHideNewSection
;
87 function getNewSection() {
88 return (bool)$this->mNewSection
;
91 function addExternalLink( $url ) {
92 # We don't register links pointing to our own server, unless... :-)
93 global $wgServer, $wgRegisterInternalExternals;
94 if( $wgRegisterInternalExternals or stripos($url,$wgServer.'/')!==0)
95 $this->mExternalLinks
[$url] = 1;
98 function addLink( $title, $id = null ) {
99 if ( $title->isExternal() ) {
100 // Don't record interwikis in pagelinks
103 $ns = $title->getNamespace();
104 $dbk = $title->getDBkey();
105 if ( $ns == NS_MEDIA
) {
106 // Normalize this pseudo-alias if it makes it down here...
108 } elseif( $ns == NS_SPECIAL
) {
109 // We don't record Special: links currently
110 // It might actually be wise to, but we'd need to do some normalization.
112 } elseif( $dbk === '' ) {
113 // Don't record self links - [[#Foo]]
116 if ( !isset( $this->mLinks
[$ns] ) ) {
117 $this->mLinks
[$ns] = array();
119 if ( is_null( $id ) ) {
120 $id = $title->getArticleID();
122 $this->mLinks
[$ns][$dbk] = $id;
125 function addImage( $name ) {
126 $this->mImages
[$name] = 1;
129 function addTemplate( $title, $page_id, $rev_id ) {
130 $ns = $title->getNamespace();
131 $dbk = $title->getDBkey();
132 if ( !isset( $this->mTemplates
[$ns] ) ) {
133 $this->mTemplates
[$ns] = array();
135 $this->mTemplates
[$ns][$dbk] = $page_id;
136 if ( !isset( $this->mTemplateIds
[$ns] ) ) {
137 $this->mTemplateIds
[$ns] = array();
139 $this->mTemplateIds
[$ns][$dbk] = $rev_id; // For versioning
143 * Return true if this cached output object predates the global or
144 * per-article cache invalidation timestamps, or if it comes from
145 * an incompatible older version.
147 * @param string $touched the affected article's last touched timestamp
151 function expired( $touched ) {
152 global $wgCacheEpoch;
153 return $this->getCacheTime() == -1 ||
// parser says it's uncacheable
154 $this->getCacheTime() < $touched ||
155 $this->getCacheTime() <= $wgCacheEpoch ||
156 !isset( $this->mVersion
) ||
157 version_compare( $this->mVersion
, Parser
::VERSION
, "lt" );
161 * Add some text to the <head>.
162 * If $tag is set, the section with that tag will only be included once
165 function addHeadItem( $section, $tag = false ) {
166 if ( $tag !== false ) {
167 $this->mHeadItems
[$tag] = $section;
169 $this->mHeadItems
[] = $section;
174 * Override the title to be used for display
175 * -- this is assumed to have been validated
176 * (check equal normalisation, etc.)
178 * @param string $text Desired title text
180 public function setDisplayTitle( $text ) {
181 $this->setTitleText( $text );
185 * Get the title to be used for display
189 public function getDisplayTitle() {
190 $t = $this->getTitleText( $text );
197 * Fairly generic flag setter thingy.
199 public function setFlag( $flag ) {
200 $this->mFlags
[$flag] = true;
203 public function getFlag( $flag ) {
204 return isset( $this->mFlags
[$flag] );
208 * Set a property to be cached in the DB
210 public function setProperty( $name, $value ) {
211 $this->mProperties
[$name] = $value;
214 public function getProperty( $name ){
215 return isset( $this->mProperties
[$name] ) ?
$this->mProperties
[$name] : false;
218 public function getProperties() {
219 if ( !isset( $this->mProperties
) ) {
220 $this->mProperties
= array();
222 return $this->mProperties
;