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