some IE6 textarea tweaks
[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 $this->mOldId = $wgRequest->getInt( 'oldid' );
25 }
26 function view() {
27 header( "Content-type: ".$this->mContentType.'; charset='.$this->mCharset );
28 # allow the client to cache this for 24 hours
29 header( 'Cache-Control: s-maxage=0, max-age=86400' );
30 echo $this->getrawtext();
31 wfAbruptExit();
32 }
33
34 function getrawtext () {
35 global $wgInputEncoding, $wgLang;
36 if( !$this->mTitle ) return '';
37 $t = wfStrencode( $this->mTitle->getDBKey() );
38 $ns = $this->mTitle->getNamespace();
39 if(!empty($this->mOldId)) {
40 $sql = "SELECT old_text as text,old_timestamp as timestamp,old_user as user,old_flags as flags FROM old " .
41 "WHERE old_id={$this->mOldId}";
42 } else {
43 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
44 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
45 "WHERE cur_namespace=$ns AND cur_title='$t'";
46 }
47 $res = wfQuery( $sql, DB_READ );
48 if( $s = wfFetchObject( $res ) ) {
49 $rawtext = Article::getRevisionText( $s, "" );
50 if($wgInputEncoding != $this->mCharset)
51 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
52 return $rawtext;
53 } else {
54 return '';
55 }
56 }
57 }
58 ?>