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>
13 require_once( 'Revision.php' );
21 function RawPage( $article ) {
22 global $wgRequest, $wgInputEncoding, $wgSquidMaxage;
23 $allowedCTypes = array('text/x-wiki', 'text/javascript', 'text/css', 'application/x-zope-edit');
24 $this->mArticle
=& $article;
25 $this->mTitle
=& $article->mTitle
;
27 $ctype = $wgRequest->getText( 'ctype' );
28 $smaxage = $wgRequest->getInt( 'smaxage', $wgSquidMaxage );
29 $maxage = $wgRequest->getInt( 'maxage', $wgSquidMaxage );
30 $this->mOldId
= $wgRequest->getInt( 'oldid' );
31 # special case for 'generated' raw things: user css/js
32 $gen = $wgRequest->getText( 'gen' );
35 if($smaxage == '') $smaxage = $wgSquidMaxage;
36 if($ctype == '') $ctype = 'text/css';
37 } else if ($gen == 'js') {
39 if($smaxage == '') $smaxage = $wgSquidMaxage;
40 if($ctype == '') $ctype = 'text/javascript';
44 $this->mCharset
= $wgInputEncoding;
45 $this->mSmaxage
= $smaxage;
46 $this->mMaxage
= $maxage;
47 if(empty($ctype) or !in_array($ctype, $allowedCTypes)) {
48 $this->mContentType
= 'text/x-wiki';
50 $this->mContentType
= $ctype;
55 global $wgUser, $wgOut, $wgScript;
57 if( strcmp( $wgScript, $_SERVER['PHP_SELF'] ) ) {
58 # Internet Explorer will ignore the Content-Type header if it
59 # thinks it sees a file extension it recognizes. Make sure that
60 # all raw requests are done through the script node, which will
61 # have eg '.php' and should remain safe.
63 $destUrl = $this->mTitle
->getFullUrl(
65 '&ctype=' . urlencode( $this->mContentType
) .
66 '&smaxage=' . urlencode( $this->mSmaxage
) .
67 '&maxage=' . urlencode( $this->mMaxage
) .
68 '&gen=' . urlencode( $this->mGen
) .
69 '&oldid=' . urlencode( $this->mOldId
) );
70 header( 'Location: ' . $destUrl );
75 header( "Content-type: ".$this->mContentType
.'; charset='.$this->mCharset
);
76 # allow the client to cache this for 24 hours
77 header( 'Cache-Control: s-maxage='.$this->mSmaxage
.', max-age='.$this->mMaxage
);
79 $sk = $wgUser->getSkin();
80 $sk->initPage($wgOut);
81 if($this->mGen
== 'css') {
82 echo $sk->getUserStylesheet();
83 } else if($this->mGen
== 'js') {
84 echo $sk->getUserJs();
87 echo $this->getrawtext();
92 function getrawtext () {
93 global $wgInputEncoding, $wgContLang;
94 $fname = 'RawPage::getrawtext';
96 if( !$this->mTitle
) return '';
98 # Special case for MediaWiki: messages; we can hit the message cache.
99 if( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
100 $rawtext = wfMsg( $this->mTitle
->getDbkey() );
104 # else get it from the DB
105 $rev = Revision
::newFromTitle( $this->mTitle
, $this->mOldId
);
107 $lastmod = wfTimestamp( TS_RFC2822
, $rev->getTimestamp() );
108 header( 'Last-modified: ' . $lastmod );
109 return $rev->getText();