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/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';
19 $this->mContentType
= $ctype;
22 $charset = $wgRequest->getText( 'charset' );
23 $this->mCharset
= !empty($charset) ?
$charset : $wgInputEncoding;
24 $smaxage = $wgRequest->getText( 'smaxage' );
25 $this->mSmaxage
= !empty($smaxage) ?
$smaxage : 0;
26 $this->mOldId
= $wgRequest->getInt( 'oldid' );
29 header( "Content-type: ".$this->mContentType
.'; charset='.$this->mCharset
);
30 # allow the client to cache this for 24 hours
31 header( 'Cache-Control: s-maxage='.$this->mSmaxage
.', max-age=86400' );
32 echo $this->getrawtext();
36 function getrawtext () {
37 global $wgInputEncoding, $wgLang;
38 if( !$this->mTitle
) return '';
39 $t = wfStrencode( $this->mTitle
->getDBKey() );
40 $ns = $this->mTitle
->getNamespace();
42 if($ns == NS_MEDIAWIKI
) {
44 if($wgInputEncoding != $this->mCharset
)
45 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset
, $rawtext );
48 # else get it from the DB
49 if(!empty($this->mOldId
)) {
50 $sql = "SELECT old_text as text,old_timestamp as timestamp,old_user as user,old_flags as flags FROM old " .
51 "WHERE old_id={$this->mOldId}";
53 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
54 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
55 "WHERE cur_namespace=$ns AND cur_title='$t'";
57 $res = wfQuery( $sql, DB_READ
);
58 if( $s = wfFetchObject( $res ) ) {
59 $rawtext = Article
::getRevisionText( $s, "" );
60 if($wgInputEncoding != $this->mCharset
)
61 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset
, $rawtext );