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, $wgJsMimeType;
24 $allowedCTypes = array('text/x-wiki', $wgJsMimeType, '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 = $wgJsMimeType;
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( isset( $_SERVER['SCRIPT_URL'] ) ) {
59 # Normally we use PHP_SELF to get the URL to the script
60 # as it was called, minus the query string.
62 # Some sites use Apache rewrite rules to handle subdomains,
63 # and have PHP set up in a weird way that causes PHP_SELF
64 # to contain the rewritten URL instead of the one that the
67 # If in this mode, use SCRIPT_URL instead, which mod_rewrite
68 # provides containing the "before" URL.
69 $url = $_SERVER['SCRIPT_URL'];
71 $url = $_SERVER['PHP_SELF'];
73 if( strcmp( $wgScript, $url ) ) {
74 # Internet Explorer will ignore the Content-Type header if it
75 # thinks it sees a file extension it recognizes. Make sure that
76 # all raw requests are done through the script node, which will
77 # have eg '.php' and should remain safe.
79 # We used to redirect to a canonical-form URL as a general
80 # backwards-compatibility / good-citizen nice thing. However
81 # a lot of servers are set up in buggy ways, resulting in
82 # redirect loops which hang the browser until the CSS load
85 # Just return a 403 Forbidden and get it over with.
86 wfHttpError( 403, 'Forbidden',
87 'Raw pages must be accessed through the primary script entry point.' );
91 header( "Content-type: ".$this->mContentType
.'; charset='.$this->mCharset
);
92 # allow the client to cache this for 24 hours
93 header( 'Cache-Control: s-maxage='.$this->mSmaxage
.', max-age='.$this->mMaxage
);
95 $sk = $wgUser->getSkin();
96 $sk->initPage($wgOut);
97 if($this->mGen
== 'css') {
98 echo $sk->getUserStylesheet();
99 } else if($this->mGen
== 'js') {
100 echo $sk->getUserJs();
103 echo $this->getrawtext();
108 function getrawtext () {
109 global $wgInputEncoding, $wgContLang;
110 $fname = 'RawPage::getrawtext';
112 if( $this->mTitle
) {
113 # Special case for MediaWiki: messages; we can hit the message cache.
114 if( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
115 $rawtext = wfMsgForContent( $this->mTitle
->getDbkey() );
119 # else get it from the DB
120 $rev = Revision
::newFromTitle( $this->mTitle
, $this->mOldId
);
122 $lastmod = wfTimestamp( TS_RFC2822
, $rev->getTimestamp() );
123 header( 'Last-modified: ' . $lastmod );
124 return $rev->getText();
128 # Bad title or page does not exist
129 if( $this->mContentType
== 'text/x-wiki' ) {
130 # Don't return a 404 response for CSS or JavaScript;
131 # 404s aren't generally cached and it would create
132 # extra hits when user CSS/JS are on and the user doesn't
134 header( "HTTP/1.0 404 Not Found" );