2 # Copyright (C) 2004 Gabriel Wicke <gw@wikidev.net>
3 # http://www.aulinx.de/
4 # Based on PageHistory and SpecialExport
6 # License: GPL (http://www.gnu.org/copyleft/gpl.html)
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';
19 $this->mContentType
= $ctype;
22 $charset = $wgRequest->getText( 'charset' );
23 $this->mCharset
= !empty($charset) ?
$charset : $wgInputEncoding;
24 $this->mOldId
= $wgRequest->getInt( 'oldid' );
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();
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}";
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'";
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 );