Index: trunk/phase3/includes/RawPage.php |
— | — | @@ -19,6 +19,9 @@ |
20 | 20 | */ |
21 | 21 | class RawPage { |
22 | 22 | var $mArticle, $mTitle, $mRequest; |
| 23 | + var $mOldId, $mGen, $mCharset; |
| 24 | + var $mSmaxage, $mMaxage; |
| 25 | + var $mContentType, $mExpandTemplates; |
23 | 26 | |
24 | 27 | function RawPage( &$article, $request = false ) { |
25 | 28 | global $wgRequest, $wgInputEncoding, $wgSquidMaxage, $wgJsMimeType; |
— | — | @@ -36,9 +39,11 @@ |
37 | 40 | $ctype = $this->mRequest->getText( 'ctype' ); |
38 | 41 | $smaxage = $this->mRequest->getInt( 'smaxage', $wgSquidMaxage ); |
39 | 42 | $maxage = $this->mRequest->getInt( 'maxage', $wgSquidMaxage ); |
| 43 | + $this->mExpandTemplates = $this->mRequest->getText( 'templates' ) === 'expand'; |
40 | 44 | $this->mOldId = $this->mRequest->getInt( 'oldid' ); |
41 | 45 | # special case for 'generated' raw things: user css/js |
42 | 46 | $gen = $this->mRequest->getText( 'gen' ); |
| 47 | + |
43 | 48 | if($gen == 'css') { |
44 | 49 | $this->mGen = $gen; |
45 | 50 | if($smaxage == '') $smaxage = $wgSquidMaxage; |
— | — | @@ -53,7 +58,7 @@ |
54 | 59 | $this->mCharset = $wgInputEncoding; |
55 | 60 | $this->mSmaxage = $smaxage; |
56 | 61 | $this->mMaxage = $maxage; |
57 | | - if(empty($ctype) or !in_array($ctype, $allowedCTypes)) { |
| 62 | + if ( $ctype == '' or ! in_array( $ctype, $allowedCTypes ) ) { |
58 | 63 | $this->mContentType = 'text/x-wiki'; |
59 | 64 | } else { |
60 | 65 | $this->mContentType = $ctype; |
— | — | @@ -118,21 +123,27 @@ |
119 | 124 | } |
120 | 125 | } |
121 | 126 | |
122 | | - function getArticleText () { |
| 127 | + function getArticleText() { |
| 128 | + global $wgParser; |
| 129 | + |
123 | 130 | if( $this->mTitle ) { |
124 | | - # Special case for MediaWiki: messages; we can hit the message cache. |
125 | | - if( $this->mTitle->getNamespace() == NS_MEDIAWIKI) { |
126 | | - $rawtext = wfMsgForContent( $this->mTitle->getDbkey() ); |
127 | | - return $rawtext; |
| 131 | + $text = ''; |
| 132 | + |
| 133 | + // If it's a MediaWiki message we can just hit the message cache |
| 134 | + if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) |
| 135 | + $text = wfMsgForContentNoTrans( $this->mTitle->getDbkey() ); |
| 136 | + else { |
| 137 | + // Get it from the DB |
| 138 | + $rev = Revision::newFromTitle( $this->mTitle, $this->mOldId ); |
| 139 | + if ( $rev ) { |
| 140 | + $lastmod = wfTimestamp( TS_RFC2822, $rev->getTimestamp() ); |
| 141 | + header( "Last-modified: $lastmod" ); |
| 142 | + $text = $rev->isDeleted() ? '' : $rev->getText(); |
| 143 | + } else |
| 144 | + $text = ''; |
128 | 145 | } |
129 | | - |
130 | | - # else get it from the DB |
131 | | - $rev = Revision::newFromTitle( $this->mTitle, $this->mOldId ); |
132 | | - if( $rev ) { |
133 | | - $lastmod = wfTimestamp( TS_RFC2822, $rev->getTimestamp() ); |
134 | | - header( 'Last-modified: ' . $lastmod ); |
135 | | - return $rev->getText(); |
136 | | - } |
| 146 | + |
| 147 | + return $this->parseArticleText( $text ); |
137 | 148 | } |
138 | 149 | |
139 | 150 | # Bad title or page does not exist |
— | — | @@ -145,5 +156,22 @@ |
146 | 157 | } |
147 | 158 | return ''; |
148 | 159 | } |
| 160 | + |
| 161 | + function parseArticleText( $text ) { |
| 162 | + if ( $text === '' ) |
| 163 | + return ''; |
| 164 | + else |
| 165 | + if ( $this->mExpandTemplates ) { |
| 166 | + global $wgTitle; |
| 167 | + |
| 168 | + $parser = new Parser(); |
| 169 | + $parser->Options( new ParserOptions() ); // We don't want this to be user-specific |
| 170 | + $parser->Title( $wgTitle ); |
| 171 | + $parser->OutputType( OT_HTML ); |
| 172 | + |
| 173 | + return $parser->replaceVariables( $text ); |
| 174 | + } else |
| 175 | + return $text; |
| 176 | + } |
149 | 177 | } |
150 | 178 | ?> |