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