Move some member variable initialization to the declarations and out of constructors...
[lhc/web/wiklou.git] / includes / parser / ParserOutput.php
1 <?php
2 /**
3 * @todo document
4 * @ingroup Parser
5 */
6 class ParserOutput
7 {
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 $mNoGallery = false, # No gallery on category page? (__NOGALLERY__)
22 $mHeadItems = array(), # Items to put in the <head> section
23 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
24 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
25 $mSections = array(), # Table of contents
26 $mProperties = array(); # Name/value pairs to be cached in the DB
27 private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
28
29 /**
30 * Overridden title for display
31 */
32 private $displayTitle = false;
33
34 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
35 $containsOldMagic = false, $titletext = '' )
36 {
37 $this->mText = $text;
38 $this->mLanguageLinks = $languageLinks;
39 $this->mCategories = $categoryLinks;
40 $this->mContainsOldMagic = $containsOldMagic;
41 $this->mTitleText = $titletext;
42 }
43
44 function getText() { return $this->mText; }
45 function &getLanguageLinks() { return $this->mLanguageLinks; }
46 function getCategoryLinks() { return array_keys( $this->mCategories ); }
47 function &getCategories() { return $this->mCategories; }
48 function getCacheTime() { return $this->mCacheTime; }
49 function getTitleText() { return $this->mTitleText; }
50 function getSections() { return $this->mSections; }
51 function &getLinks() { return $this->mLinks; }
52 function &getTemplates() { return $this->mTemplates; }
53 function &getImages() { return $this->mImages; }
54 function &getExternalLinks() { return $this->mExternalLinks; }
55 function getNoGallery() { return $this->mNoGallery; }
56 function getSubtitle() { return $this->mSubtitle; }
57 function getOutputHooks() { return (array)$this->mOutputHooks; }
58 function getWarnings() { return array_keys( $this->mWarnings ); }
59 function getIndexPolicy() { return $this->mIndexPolicy; }
60
61 function containsOldMagic() { return $this->mContainsOldMagic; }
62 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
63 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
64 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
65 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
66 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
67 function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); }
68 function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); }
69 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); }
70
71 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
72 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
73 function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
74 function addWarning( $s ) { $this->mWarnings[$s] = 1; }
75
76 function addOutputHook( $hook, $data = false ) {
77 $this->mOutputHooks[] = array( $hook, $data );
78 }
79
80 function setNewSection( $value ) {
81 $this->mNewSection = (bool)$value;
82 }
83 function getNewSection() {
84 return (bool)$this->mNewSection;
85 }
86
87 function addLink( $title, $id = null ) {
88 $ns = $title->getNamespace();
89 $dbk = $title->getDBkey();
90 if ( !isset( $this->mLinks[$ns] ) ) {
91 $this->mLinks[$ns] = array();
92 }
93 if ( is_null( $id ) ) {
94 $id = $title->getArticleID();
95 }
96 $this->mLinks[$ns][$dbk] = $id;
97 }
98
99 function addImage( $name ) {
100 $this->mImages[$name] = 1;
101 }
102
103 function addTemplate( $title, $page_id, $rev_id ) {
104 $ns = $title->getNamespace();
105 $dbk = $title->getDBkey();
106 if ( !isset( $this->mTemplates[$ns] ) ) {
107 $this->mTemplates[$ns] = array();
108 }
109 $this->mTemplates[$ns][$dbk] = $page_id;
110 if ( !isset( $this->mTemplateIds[$ns] ) ) {
111 $this->mTemplateIds[$ns] = array();
112 }
113 $this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
114 }
115
116 /**
117 * Return true if this cached output object predates the global or
118 * per-article cache invalidation timestamps, or if it comes from
119 * an incompatible older version.
120 *
121 * @param string $touched the affected article's last touched timestamp
122 * @return bool
123 * @public
124 */
125 function expired( $touched ) {
126 global $wgCacheEpoch;
127 return $this->getCacheTime() == -1 || // parser says it's uncacheable
128 $this->getCacheTime() < $touched ||
129 $this->getCacheTime() <= $wgCacheEpoch ||
130 !isset( $this->mVersion ) ||
131 version_compare( $this->mVersion, Parser::VERSION, "lt" );
132 }
133
134 /**
135 * Add some text to the <head>.
136 * If $tag is set, the section with that tag will only be included once
137 * in a given page.
138 */
139 function addHeadItem( $section, $tag = false ) {
140 if ( $tag !== false ) {
141 $this->mHeadItems[$tag] = $section;
142 } else {
143 $this->mHeadItems[] = $section;
144 }
145 }
146
147 /**
148 * Override the title to be used for display
149 * -- this is assumed to have been validated
150 * (check equal normalisation, etc.)
151 *
152 * @param string $text Desired title text
153 */
154 public function setDisplayTitle( $text ) {
155 $this->displayTitle = $text;
156 }
157
158 /**
159 * Get the title to be used for display
160 *
161 * @return string
162 */
163 public function getDisplayTitle() {
164 return $this->displayTitle;
165 }
166
167 /**
168 * Fairly generic flag setter thingy.
169 */
170 public function setFlag( $flag ) {
171 $this->mFlags[$flag] = true;
172 }
173
174 public function getFlag( $flag ) {
175 return isset( $this->mFlags[$flag] );
176 }
177
178 /**
179 * Set a property to be cached in the DB
180 */
181 public function setProperty( $name, $value ) {
182 $this->mProperties[$name] = $value;
183 }
184
185 public function getProperty( $name ){
186 return isset( $this->mProperties[$name] ) ? $this->mProperties[$name] : false;
187 }
188
189 public function getProperties() {
190 if ( !isset( $this->mProperties ) ) {
191 $this->mProperties = array();
192 }
193 return $this->mProperties;
194 }
195 }