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