use wfMsg() for MediaWiki NS
[lhc/web/wiklou.git] / includes / RawPage.php
1 <?php
2 # Copyright (C) 2004 Gabriel Wicke <gw@wikidev.net>
3 # http://www.aulinx.de/
4 # Based on PageHistory and SpecialExport
5 #
6 # License: GPL (http://www.gnu.org/copyleft/gpl.html)
7
8 class RawPage {
9
10 function RawPage( $article ) {
11 global $wgRequest, $wgInputEncoding;
12 $allowedCTypes = array('text/x-wiki', 'text/javascript', 'text/css', 'application/x-zope-edit');
13 $this->mArticle =& $article;
14 $this->mTitle =& $article->mTitle;
15 $ctype = $wgRequest->getText( 'ctype' );
16 if(empty($ctype) or !in_array($ctype, $allowedCTypes)) {
17 $this->mContentType = 'text/x-wiki';
18 } else {
19 $this->mContentType = $ctype;
20 }
21
22 $charset = $wgRequest->getText( 'charset' );
23 $this->mCharset = !empty($charset) ? $charset : $wgInputEncoding;
24 $smaxage = $wgRequest->getText( 'smaxage' );
25 $this->mSmaxage = !empty($smaxage) ? $smaxage : 0;
26 $this->mOldId = $wgRequest->getInt( 'oldid' );
27 }
28 function view() {
29 header( "Content-type: ".$this->mContentType.'; charset='.$this->mCharset );
30 # allow the client to cache this for 24 hours
31 header( 'Cache-Control: s-maxage='.$this->mSmaxage.', max-age=86400' );
32 echo $this->getrawtext();
33 wfAbruptExit();
34 }
35
36 function getrawtext () {
37 global $wgInputEncoding, $wgLang;
38 if( !$this->mTitle ) return '';
39 $t = wfStrencode( $this->mTitle->getDBKey() );
40 $ns = $this->mTitle->getNamespace();
41 # special case
42 if($ns == NS_MEDIAWIKI) {
43 $rawtext = wfMsg($t);
44 if($wgInputEncoding != $this->mCharset)
45 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
46 return $rawtext;
47 }
48 # else get it from the DB
49 if(!empty($this->mOldId)) {
50 $sql = "SELECT old_text as text,old_timestamp as timestamp,old_user as user,old_flags as flags FROM old " .
51 "WHERE old_id={$this->mOldId}";
52 } else {
53 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
54 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
55 "WHERE cur_namespace=$ns AND cur_title='$t'";
56 }
57 $res = wfQuery( $sql, DB_READ );
58 if( $s = wfFetchObject( $res ) ) {
59 $rawtext = Article::getRevisionText( $s, "" );
60 if($wgInputEncoding != $this->mCharset)
61 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
62 return $rawtext;
63 } else {
64 return '';
65 }
66 }
67 }
68 ?>