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