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, $wgSquidMaxage;
12 $allowedCTypes = array('text/x-wiki', 'text/javascript', 'text/css', 'application/x-zope-edit');
13 $this->mArticle
=& $article;
14 $this->mTitle
=& $article->mTitle
;
16 $ctype = $wgRequest->getText( 'ctype' );
17 $charset = $wgRequest->getText( 'charset' );
18 $smaxage = $wgRequest->getText( 'smaxage' );
19 $maxage = $wgRequest->getText( 'maxage' );
20 $this->mOldId
= $wgRequest->getInt( 'oldid' );
21 # special case for 'generated' raw things: user css/js
22 $gen = $wgRequest->getText( 'gen' );
25 if($smaxage == '') $smaxage = $wgSquidMaxage;
26 if($ctype == '') $ctype = 'text/css';
27 } else if ($gen == 'js') {
29 if($smaxage == '') $smaxage = $wgSquidMaxage;
30 if($ctype == '') $ctype = 'text/javascript';
34 $this->mCharset
= !empty($charset) ?
$charset : $wgInputEncoding;
35 $this->mSmaxage
= ($smaxage != '') ?
$smaxage : 0;
36 $this->mMaxage
= ($maxage != '') ?
$maxage : 86400;
37 if(empty($ctype) or !in_array($ctype, $allowedCTypes)) {
38 $this->mContentType
= 'text/x-wiki';
40 $this->mContentType
= $ctype;
44 global $wgUser, $wgOut;
45 header( "Content-type: ".$this->mContentType
.'; charset='.$this->mCharset
);
46 # allow the client to cache this for 24 hours
47 header( 'Cache-Control: s-maxage='.$this->mSmaxage
.', max-age='.$this->mMaxage
);
49 $sk = $wgUser->getSkin();
50 $sk->initPage($wgOut);
51 if($this->mGen
== 'css') {
52 echo $sk->getUserStylesheet();
53 } else if($this->mGen
== 'js') {
54 echo $sk->getUserJs();
57 echo $this->getrawtext();
62 function getrawtext () {
63 global $wgInputEncoding, $wgLang;
64 $fname = 'RawPage::getrawtext';
66 if( !$this->mTitle
) return '';
67 $dbr =& wfGetDB( DB_SLAVE
);
68 extract( $dbr->tableNames( 'cur', 'old' ) );
70 $t = $dbr->strencode( $this->mTitle
->getDBKey() );
71 $ns = $this->mTitle
->getNamespace();
73 if($ns == NS_MEDIAWIKI
) {
75 if($wgInputEncoding != $this->mCharset
)
76 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset
, $rawtext );
79 # else get it from the DB
80 if(!empty($this->mOldId
)) {
81 $sql = "SELECT old_text AS text,old_timestamp AS timestamp,".
82 "old_user AS user,old_flags AS flags FROM $old " .
83 "WHERE old_id={$this->mOldId}";
85 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
86 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM $cur " .
87 "WHERE cur_namespace=$ns AND cur_title='$t'";
89 $res = $dbr->query( $sql, $fname );
90 if( $s = $dbr->fetchObject( $res ) ) {
91 $rawtext = Article
::getRevisionText( $s, "" );
92 if($wgInputEncoding != $this->mCharset
)
93 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset
, $rawtext );
94 header( 'Last-modified: '.gmdate( "D, j M Y H:i:s", wfTimestamp2Unix( $s->timestamp
)).' GMT' );