parser to the rescue to secure the content this returns- no js in html please
[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/plain', 'text/javascript', 'text/css');
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/plain';
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 $parser=new Parser();
31 $raw = $this->getrawtext();
32 echo $parser->removeHTMLtags( $raw );
33 wfAbruptExit();
34 }
35
36
37
38 function getrawtext () {
39 global $wgInputEncoding, $wgLang;
40 if( !$this->mTitle ) return '';
41 $t = wfStrencode( $this->mTitle->getDBKey() );
42 $ns = $this->mTitle->getNamespace();
43 if(!empty($this->mOldId)) {
44 $sql = "SELECT old_text as text,old_timestamp as timestamp,old_user as user,old_flags as flags FROM old " .
45 "WHERE old_id={$this->mOldId}";
46 } else {
47 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
48 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
49 "WHERE cur_namespace=$ns AND cur_title='$t'";
50 }
51 $res = wfQuery( $sql, DB_READ );
52 if( $s = wfFetchObject( $res ) ) {
53 $rawtext = Article::getRevisionText( $s, "" );
54 if($wgInputEncoding != $this->mCharset)
55 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
56 return $rawtext;
57 } else {
58 return '';
59 }
60 }
61 }
62 ?>