In QueryPage: fixing a misleading comment. value needn't be numeric.
[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, $wgSquidMaxage;
12 $allowedCTypes = array('text/x-wiki', 'text/javascript', 'text/css', 'application/x-zope-edit');
13 $this->mArticle =& $article;
14 $this->mTitle =& $article->mTitle;
15
16 $ctype = $wgRequest->getText( 'ctype' );
17 $charset = $wgRequest->getText( 'charset' );
18 $smaxage = $wgRequest->getText( 'smaxage' );
19 $maxage = $wgRequest->getText( 'maxage' );
20 $this->mOldId = $wgRequest->getInt( 'oldid' );
21 # special case for 'generated' raw things: user css/js
22 $gen = $wgRequest->getText( 'gen' );
23 if($gen == 'css') {
24 $this->mGen = $gen;
25 if($smaxage == '') $smaxage = $wgSquidMaxage;
26 if($ctype == '') $ctype = 'text/css';
27 } else if ($gen == 'js') {
28 $this->mGen = $gen;
29 if($smaxage == '') $smaxage = $wgSquidMaxage;
30 if($ctype == '') $ctype = 'text/javascript';
31 } else {
32 $this->mGen = false;
33 }
34 $this->mCharset = !empty($charset) ? $charset : $wgInputEncoding;
35 $this->mSmaxage = ($smaxage != '') ? $smaxage : 0;
36 $this->mMaxage = ($maxage != '') ? $maxage : 86400;
37 if(empty($ctype) or !in_array($ctype, $allowedCTypes)) {
38 $this->mContentType = 'text/x-wiki';
39 } else {
40 $this->mContentType = $ctype;
41 }
42 }
43 function view() {
44 global $wgUser, $wgOut;
45 header( "Content-type: ".$this->mContentType.'; charset='.$this->mCharset );
46 # allow the client to cache this for 24 hours
47 header( 'Cache-Control: s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage );
48 if($this->mGen) {
49 $sk = $wgUser->getSkin();
50 $sk->initPage($wgOut);
51 if($this->mGen == 'css') {
52 echo $sk->getUserStylesheet();
53 } else if($this->mGen == 'js') {
54 echo $sk->getUserJs();
55 }
56 } else {
57 echo $this->getrawtext();
58 }
59 $wgOut->disable();
60 }
61
62 function getrawtext () {
63 global $wgInputEncoding, $wgLang;
64 $fname = 'RawPage::getrawtext';
65
66 if( !$this->mTitle ) return '';
67 $dbr =& wfGetDB( DB_SLAVE );
68 extract( $dbr->tableNames( 'cur', 'old' ) );
69
70 $t = $dbr->strencode( $this->mTitle->getDBKey() );
71 $ns = $this->mTitle->getNamespace();
72 # special case
73 if($ns == NS_MEDIAWIKI) {
74 $rawtext = wfMsg($t);
75 if($wgInputEncoding != $this->mCharset)
76 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
77 return $rawtext;
78 }
79 # else get it from the DB
80 if(!empty($this->mOldId)) {
81 $sql = "SELECT old_text AS text,old_timestamp AS timestamp,".
82 "old_user AS user,old_flags AS flags FROM $old " .
83 "WHERE old_id={$this->mOldId}";
84 } else {
85 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
86 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM $cur " .
87 "WHERE cur_namespace=$ns AND cur_title='$t'";
88 }
89 $res = $dbr->query( $sql, $fname );
90 if( $s = $dbr->fetchObject( $res ) ) {
91 $rawtext = Article::getRevisionText( $s, "" );
92 if($wgInputEncoding != $this->mCharset)
93 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
94 header( 'Last-modified: '.gmdate( "D, j M Y H:i:s", wfTimestamp2Unix( $s->timestamp )).' GMT' );
95 return $rawtext;
96 } else {
97 return '';
98 }
99 }
100 }
101 ?>