* Remove useless, unvalidated charset option on raw page
[lhc/web/wiklou.git] / includes / RawPage.php
1 <?php
2 /**
3 * Copyright (C) 2004 Gabriel Wicke <gw@wikidev.net>
4 * http://www.aulinx.de/
5 * Based on PageHistory and SpecialExport
6 *
7 * License: GPL (http://www.gnu.org/copyleft/gpl.html)
8 *
9 * @author Gabriel Wicke <gw@wikidev.net>
10 * @package MediaWiki
11 */
12
13 /**
14 * @todo document
15 * @package MediaWiki
16 */
17 class RawPage {
18
19 function RawPage( $article ) {
20 global $wgRequest, $wgInputEncoding, $wgSquidMaxage;
21 $allowedCTypes = array('text/x-wiki', 'text/javascript', 'text/css', 'application/x-zope-edit');
22 $this->mArticle =& $article;
23 $this->mTitle =& $article->mTitle;
24
25 $ctype = $wgRequest->getText( 'ctype' );
26 $smaxage = $wgRequest->getInt( 'smaxage', $wgSquidMaxage );
27 $maxage = $wgRequest->getInt( 'maxage', $wgSquidMaxage );
28 $this->mOldId = $wgRequest->getInt( 'oldid' );
29 # special case for 'generated' raw things: user css/js
30 $gen = $wgRequest->getText( 'gen' );
31 if($gen == 'css') {
32 $this->mGen = $gen;
33 if($smaxage == '') $smaxage = $wgSquidMaxage;
34 if($ctype == '') $ctype = 'text/css';
35 } else if ($gen == 'js') {
36 $this->mGen = $gen;
37 if($smaxage == '') $smaxage = $wgSquidMaxage;
38 if($ctype == '') $ctype = 'text/javascript';
39 } else {
40 $this->mGen = false;
41 }
42 $this->mCharset = $wgInputEncoding;
43 $this->mSmaxage = $smaxage;
44 $this->mMaxage = $maxage;
45 if(empty($ctype) or !in_array($ctype, $allowedCTypes)) {
46 $this->mContentType = 'text/x-wiki';
47 } else {
48 $this->mContentType = $ctype;
49 }
50 }
51
52 function view() {
53 global $wgUser, $wgOut;
54 header( "Content-type: ".$this->mContentType.'; charset='.$this->mCharset );
55 # allow the client to cache this for 24 hours
56 header( 'Cache-Control: s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage );
57 if($this->mGen) {
58 $sk = $wgUser->getSkin();
59 $sk->initPage($wgOut);
60 if($this->mGen == 'css') {
61 echo $sk->getUserStylesheet();
62 } else if($this->mGen == 'js') {
63 echo $sk->getUserJs();
64 }
65 } else {
66 echo $this->getrawtext();
67 }
68 $wgOut->disable();
69 }
70
71 function getrawtext () {
72 global $wgInputEncoding, $wgContLang;
73 $fname = 'RawPage::getrawtext';
74
75 if( !$this->mTitle ) return '';
76 $dbr =& wfGetDB( DB_SLAVE );
77 extract( $dbr->tableNames( 'cur', 'old' ) );
78
79 $t = $dbr->strencode( $this->mTitle->getDBKey() );
80 $ns = $this->mTitle->getNamespace();
81 # special case
82 if($ns == NS_MEDIAWIKI) {
83 $rawtext = wfMsg($t);
84 return $rawtext;
85 }
86 # else get it from the DB
87 if(!empty($this->mOldId)) {
88 $sql = "SELECT old_text AS text,old_timestamp AS timestamp,".
89 "old_user AS user,old_flags AS flags FROM $old " .
90 "WHERE old_id={$this->mOldId}";
91 } else {
92 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
93 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM $cur " .
94 "WHERE cur_namespace=$ns AND cur_title='$t'";
95 }
96 $res = $dbr->query( $sql, $fname );
97 if( $s = $dbr->fetchObject( $res ) ) {
98 $rawtext = Article::getRevisionText( $s, "" );
99 header( 'Last-modified: '.gmdate( "D, j M Y H:i:s", wfTimestamp2Unix( $s->timestamp )).' GMT' );
100 return $rawtext;
101 } else {
102 return '';
103 }
104 }
105 }
106 ?>