Another fix.
[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
23 function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
24 $containsOldMagic = false, $titletext = '' )
25 {
26 $this->mText = $text;
27 $this->mLanguageLinks = $languageLinks;
28 $this->mCategories = $categoryLinks;
29 $this->mContainsOldMagic = $containsOldMagic;
30 $this->mCacheTime = '';
31 $this->mVersion = Parser::VERSION;
32 $this->mTitleText = $titletext;
33 $this->mLinks = array();
34 $this->mTemplates = array();
35 $this->mImages = array();
36 $this->mExternalLinks = array();
37 $this->mHTMLtitle = "" ;
38 $this->mSubtitle = "" ;
39 $this->mNewSection = false;
40 $this->mNoGallery = false;
41 }
42
43 function getText() { return $this->mText; }
44 function &getLanguageLinks() { return $this->mLanguageLinks; }
45 function getCategoryLinks() { return array_keys( $this->mCategories ); }
46 function &getCategories() { return $this->mCategories; }
47 function getCacheTime() { return $this->mCacheTime; }
48 function getTitleText() { return $this->mTitleText; }
49 function &getLinks() { return $this->mLinks; }
50 function &getTemplates() { return $this->mTemplates; }
51 function &getImages() { return $this->mImages; }
52 function &getExternalLinks() { return $this->mExternalLinks; }
53 function getNoGallery() { return $this->mNoGallery; }
54 function getSubtitle() { return $this->mSubtitle; }
55
56 function containsOldMagic() { return $this->mContainsOldMagic; }
57 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
58 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
59 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); }
60 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
61 function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); }
62 function setTitleText( $t ) { return wfSetVar($this->mTitleText, $t); }
63 function setSubtitle( $st ) { return wfSetVar( $this->mSubtitle, $st ); }
64
65 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
66 function addImage( $name ) { $this->mImages[$name] = 1; }
67 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
68 function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
69
70 function setNewSection( $value ) {
71 $this->mNewSection = (bool)$value;
72 }
73 function getNewSection() {
74 return (bool)$this->mNewSection;
75 }
76
77 function addLink( $title, $id = null ) {
78 $ns = $title->getNamespace();
79 $dbk = $title->getDBkey();
80 if ( !isset( $this->mLinks[$ns] ) ) {
81 $this->mLinks[$ns] = array();
82 }
83 if ( is_null( $id ) ) {
84 $id = $title->getArticleID();
85 }
86 $this->mLinks[$ns][$dbk] = $id;
87 }
88
89 function addTemplate( $title, $id ) {
90 $ns = $title->getNamespace();
91 $dbk = $title->getDBkey();
92 if ( !isset( $this->mTemplates[$ns] ) ) {
93 $this->mTemplates[$ns] = array();
94 }
95 $this->mTemplates[$ns][$dbk] = $id;
96 }
97
98 /**
99 * Return true if this cached output object predates the global or
100 * per-article cache invalidation timestamps, or if it comes from
101 * an incompatible older version.
102 *
103 * @param string $touched the affected article's last touched timestamp
104 * @return bool
105 * @public
106 */
107 function expired( $touched ) {
108 global $wgCacheEpoch;
109 return $this->getCacheTime() == -1 || // parser says it's uncacheable
110 $this->getCacheTime() < $touched ||
111 $this->getCacheTime() <= $wgCacheEpoch ||
112 !isset( $this->mVersion ) ||
113 version_compare( $this->mVersion, Parser::VERSION, "lt" );
114 }
115 }
116
117 ?>