3 * Copyright (C) 2004 Gabriel Wicke <gw@wikidev.net>
4 * http://www.aulinx.de/
5 * Based on PageHistory and SpecialExport
7 * License: GPL (http://www.gnu.org/copyleft/gpl.html)
9 * @author Gabriel Wicke <gw@wikidev.net>
19 function RawPage( $article ) {
20 global $wgRequest, $wgInputEncoding, $wgSquidMaxage;
21 $allowedCTypes = array('text/x-wiki', 'text/javascript', 'text/css', 'application/x-zope-edit');
22 $this->mArticle
=& $article;
23 $this->mTitle
=& $article->mTitle
;
25 $ctype = $wgRequest->getText( 'ctype' );
26 $charset = $wgRequest->getText( 'charset' );
27 $smaxage = $wgRequest->getText( 'smaxage' );
28 $maxage = $wgRequest->getText( 'maxage' );
29 $this->mOldId
= $wgRequest->getInt( 'oldid' );
30 # special case for 'generated' raw things: user css/js
31 $gen = $wgRequest->getText( 'gen' );
34 if($smaxage == '') $smaxage = $wgSquidMaxage;
35 if($ctype == '') $ctype = 'text/css';
36 } else if ($gen == 'js') {
38 if($smaxage == '') $smaxage = $wgSquidMaxage;
39 if($ctype == '') $ctype = 'text/javascript';
43 $this->mCharset
= !empty($charset) ?
$charset : $wgInputEncoding;
44 $this->mSmaxage
= ($smaxage != '') ?
$smaxage : 0;
45 $this->mMaxage
= ($maxage != '') ?
$maxage : 86400;
46 if(empty($ctype) or !in_array($ctype, $allowedCTypes)) {
47 $this->mContentType
= 'text/x-wiki';
49 $this->mContentType
= $ctype;
54 global $wgUser, $wgOut;
55 header( "Content-type: ".$this->mContentType
.'; charset='.$this->mCharset
);
56 # allow the client to cache this for 24 hours
57 header( 'Cache-Control: s-maxage='.$this->mSmaxage
.', max-age='.$this->mMaxage
);
59 $sk = $wgUser->getSkin();
60 $sk->initPage($wgOut);
61 if($this->mGen
== 'css') {
62 echo $sk->getUserStylesheet();
63 } else if($this->mGen
== 'js') {
64 echo $sk->getUserJs();
67 echo $this->getrawtext();
72 function getrawtext () {
73 global $wgInputEncoding, $wgLang;
74 $fname = 'RawPage::getrawtext';
76 if( !$this->mTitle
) return '';
77 $dbr =& wfGetDB( DB_SLAVE
);
78 extract( $dbr->tableNames( 'cur', 'old' ) );
80 $t = $dbr->strencode( $this->mTitle
->getDBKey() );
81 $ns = $this->mTitle
->getNamespace();
83 if($ns == NS_MEDIAWIKI
) {
85 if($wgInputEncoding != $this->mCharset
)
86 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset
, $rawtext );
89 # else get it from the DB
90 if(!empty($this->mOldId
)) {
91 $sql = "SELECT old_text AS text,old_timestamp AS timestamp,".
92 "old_user AS user,old_flags AS flags FROM $old " .
93 "WHERE old_id={$this->mOldId}";
95 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
96 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM $cur " .
97 "WHERE cur_namespace=$ns AND cur_title='$t'";
99 $res = $dbr->query( $sql, $fname );
100 if( $s = $dbr->fetchObject( $res ) ) {
101 $rawtext = Article
::getRevisionText( $s, "" );
102 if($wgInputEncoding != $this->mCharset
)
103 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset
, $rawtext );
104 header( 'Last-modified: '.gmdate( "D, j M Y H:i:s", wfTimestamp2Unix( $s->timestamp
)).' GMT' );