* New message: talkpagelinktext
[lhc/web/wiklou.git] / includes / ParserOutput.php
1 <?php
2 /**
3 * @todo document
4 */
5 class ParserOutput
6 {
7 var $mText, # The output text
8 $mLanguageLinks, # List of the full text of language links, in the order they appear
9 $mCategories, # Map of category names to sort keys
10 $mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
11 $mCacheTime, # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
12 $mVersion, # Compatibility check
13 $mTitleText, # title text of the chosen language variant
14 $mLinks, # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
15 $mTemplates, # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
16 $mImages, # DB keys of the images used, in the array key only
17 $mExternalLinks, # External link URLs, in the key only
18 $mHTMLtitle, # Display HTML title
19 $mSubtitle, # Additional subtitle
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
24 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
25 $containsOldMagic = false, $titletext = '' )
26 {
27 $this->mText = $text;
28 $this->mLanguageLinks = $languageLinks;
29 $this->mCategories = $categoryLinks;
30 $this->mContainsOldMagic = $containsOldMagic;
31 $this->mCacheTime = '';
32 $this->mVersion = Parser::VERSION;
33 $this->mTitleText = $titletext;
34 $this->mLinks = array();
35 $this->mTemplates = array();
36 $this->mImages = array();
37 $this->mExternalLinks = array();
38 $this->mHTMLtitle = "" ;
39 $this->mSubtitle = "" ;
40 $this->mNewSection = false;
41 $this->mNoGallery = false;
42 $this->mHeadItems = array();
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 &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
58 function containsOldMagic() { return $this->mContainsOldMagic; }
59 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
60 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
61 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
62 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
63 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
64 function setTitleText( $t ) { return wfSetVar($this->mTitleText, $t); }
65 function setSubtitle( $st ) { return wfSetVar( $this->mSubtitle, $st ); }
66
67 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
68 function addImage( $name ) { $this->mImages[$name] = 1; }
69 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
70 function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
71
72 function setNewSection( $value ) {
73 $this->mNewSection = (bool)$value;
74 }
75 function getNewSection() {
76 return (bool)$this->mNewSection;
77 }
78
79 function addLink( $title, $id = null ) {
80 $ns = $title->getNamespace();
81 $dbk = $title->getDBkey();
82 if ( !isset( $this->mLinks[$ns] ) ) {
83 $this->mLinks[$ns] = array();
84 }
85 if ( is_null( $id ) ) {
86 $id = $title->getArticleID();
87 }
88 $this->mLinks[$ns][$dbk] = $id;
89 }
90
91 function addTemplate( $title, $id ) {
92 $ns = $title->getNamespace();
93 $dbk = $title->getDBkey();
94 if ( !isset( $this->mTemplates[$ns] ) ) {
95 $this->mTemplates[$ns] = array();
96 }
97 $this->mTemplates[$ns][$dbk] = $id;
98 }
99
100 /**
101 * Return true if this cached output object predates the global or
102 * per-article cache invalidation timestamps, or if it comes from
103 * an incompatible older version.
104 *
105 * @param string $touched the affected article's last touched timestamp
106 * @return bool
107 * @public
108 */
109 function expired( $touched ) {
110 global $wgCacheEpoch;
111 return $this->getCacheTime() == -1 || // parser says it's uncacheable
112 $this->getCacheTime() < $touched ||
113 $this->getCacheTime() <= $wgCacheEpoch ||
114 !isset( $this->mVersion ) ||
115 version_compare( $this->mVersion, Parser::VERSION, "lt" );
116 }
117
118 /**
119 * Add some text to the <head>.
120 * If $tag is set, the section with that tag will only be included once
121 * in a given page.
122 */
123 function addHeadItem( $section, $tag = false ) {
124 if ( $tag !== false ) {
125 $this->mHeadItems[$tag] = $section;
126 } else {
127 $this->mHeadItems[] = $section;
128 }
129 }
130 }
131
132 ?>