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>
14 require_once( 'Revision.php' );
22 function RawPage( $article ) {
23 global $wgRequest, $wgInputEncoding, $wgSquidMaxage;
24 $allowedCTypes = array('text/x-wiki', 'text/javascript', 'text/css', 'application/x-zope-edit');
25 $this->mArticle
=& $article;
26 $this->mTitle
=& $article->mTitle
;
28 $ctype = $wgRequest->getText( 'ctype' );
29 $smaxage = $wgRequest->getInt( 'smaxage', $wgSquidMaxage );
30 $maxage = $wgRequest->getInt( 'maxage', $wgSquidMaxage );
31 $this->mOldId
= $wgRequest->getInt( 'oldid' );
32 # special case for 'generated' raw things: user css/js
33 $gen = $wgRequest->getText( 'gen' );
36 if($smaxage == '') $smaxage = $wgSquidMaxage;
37 if($ctype == '') $ctype = 'text/css';
38 } else if ($gen == 'js') {
40 if($smaxage == '') $smaxage = $wgSquidMaxage;
41 if($ctype == '') $ctype = 'text/javascript';
45 $this->mCharset
= $wgInputEncoding;
46 $this->mSmaxage
= $smaxage;
47 $this->mMaxage
= $maxage;
48 if(empty($ctype) or !in_array($ctype, $allowedCTypes)) {
49 $this->mContentType
= 'text/x-wiki';
51 $this->mContentType
= $ctype;
56 global $wgUser, $wgOut, $wgScript;
58 if( strcmp( $wgScript, $_SERVER['PHP_SELF'] ) ) {
59 # Internet Explorer will ignore the Content-Type header if it
60 # thinks it sees a file extension it recognizes. Make sure that
61 # all raw requests are done through the script node, which will
62 # have eg '.php' and should remain safe.
64 $destUrl = $this->mTitle
->getFullUrl(
66 '&ctype=' . urlencode( $this->mContentType
) .
67 '&smaxage=' . urlencode( $this->mSmaxage
) .
68 '&maxage=' . urlencode( $this->mMaxage
) .
69 '&gen=' . urlencode( $this->mGen
) .
70 '&oldid=' . urlencode( $this->mOldId
) );
71 header( 'Location: ' . $destUrl );
76 header( "Content-type: ".$this->mContentType
.'; charset='.$this->mCharset
);
77 # allow the client to cache this for 24 hours
78 header( 'Cache-Control: s-maxage='.$this->mSmaxage
.', max-age='.$this->mMaxage
);
80 $sk = $wgUser->getSkin();
81 $sk->initPage($wgOut);
82 if($this->mGen
== 'css') {
83 echo $sk->getUserStylesheet();
84 } else if($this->mGen
== 'js') {
85 echo $sk->getUserJs();
88 echo $this->getrawtext();
93 function getrawtext () {
94 global $wgInputEncoding, $wgContLang;
95 $fname = 'RawPage::getrawtext';
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();
113 # Bad title or page does not exist
114 if( $this->mContentType
== 'text/x-wiki' ) {
115 # Don't return a 404 response for CSS or JavaScript;
116 # 404s aren't generally cached and it would create
117 # extra hits when user CSS/JS are on and the user doesn't
119 header( "HTTP/1.0 404 Not Found" );