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' );
21 var $mArticle, $mTitle, $mRequest;
23 function RawPage( &$article, $request = false ) {
24 global $wgRequest, $wgInputEncoding, $wgSquidMaxage, $wgJsMimeType;
26 $allowedCTypes = array('text/x-wiki', $wgJsMimeType, 'text/css', 'application/x-zope-edit');
27 $this->mArticle
=& $article;
28 $this->mTitle
=& $article->mTitle
;
30 if ( $request === false ) {
31 $this->mRequest
=& $wgRequest;
33 $this->mRequest
= $request;
36 $ctype = $this->mRequest
->getText( 'ctype' );
37 $smaxage = $this->mRequest
->getInt( 'smaxage', $wgSquidMaxage );
38 $maxage = $this->mRequest
->getInt( 'maxage', $wgSquidMaxage );
39 $this->mOldId
= $this->mRequest
->getInt( 'oldid' );
40 # special case for 'generated' raw things: user css/js
41 $gen = $this->mRequest
->getText( 'gen' );
44 if($smaxage == '') $smaxage = $wgSquidMaxage;
45 if($ctype == '') $ctype = 'text/css';
46 } else if ($gen == 'js') {
48 if($smaxage == '') $smaxage = $wgSquidMaxage;
49 if($ctype == '') $ctype = $wgJsMimeType;
53 $this->mCharset
= $wgInputEncoding;
54 $this->mSmaxage
= $smaxage;
55 $this->mMaxage
= $maxage;
56 if(empty($ctype) or !in_array($ctype, $allowedCTypes)) {
57 $this->mContentType
= 'text/x-wiki';
59 $this->mContentType
= $ctype;
64 global $wgOut, $wgScript;
66 if( isset( $_SERVER['SCRIPT_URL'] ) ) {
67 # Normally we use PHP_SELF to get the URL to the script
68 # as it was called, minus the query string.
70 # Some sites use Apache rewrite rules to handle subdomains,
71 # and have PHP set up in a weird way that causes PHP_SELF
72 # to contain the rewritten URL instead of the one that the
75 # If in this mode, use SCRIPT_URL instead, which mod_rewrite
76 # provides containing the "before" URL.
77 $url = $_SERVER['SCRIPT_URL'];
79 $url = $_SERVER['PHP_SELF'];
81 if( strcmp( $wgScript, $url ) ) {
82 # Internet Explorer will ignore the Content-Type header if it
83 # thinks it sees a file extension it recognizes. Make sure that
84 # all raw requests are done through the script node, which will
85 # have eg '.php' and should remain safe.
87 # We used to redirect to a canonical-form URL as a general
88 # backwards-compatibility / good-citizen nice thing. However
89 # a lot of servers are set up in buggy ways, resulting in
90 # redirect loops which hang the browser until the CSS load
93 # Just return a 403 Forbidden and get it over with.
94 wfHttpError( 403, 'Forbidden',
95 'Raw pages must be accessed through the primary script entry point.' );
99 header( "Content-type: ".$this->mContentType
.'; charset='.$this->mCharset
);
100 # allow the client to cache this for 24 hours
101 header( 'Cache-Control: s-maxage='.$this->mSmaxage
.', max-age='.$this->mMaxage
);
102 echo $this->getRawText();
106 function getRawText() {
107 global $wgUser, $wgOut;
109 $sk = $wgUser->getSkin();
110 $sk->initPage($wgOut);
111 if($this->mGen
== 'css') {
112 return $sk->getUserStylesheet();
113 } else if($this->mGen
== 'js') {
114 return $sk->getUserJs();
117 return $this->getArticleText();
121 function getArticleText () {
122 if( $this->mTitle
) {
123 # Special case for MediaWiki: messages; we can hit the message cache.
124 if( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
125 $rawtext = wfMsgForContent( $this->mTitle
->getDbkey() );
129 # else get it from the DB
130 $rev = Revision
::newFromTitle( $this->mTitle
, $this->mOldId
);
132 $lastmod = wfTimestamp( TS_RFC2822
, $rev->getTimestamp() );
133 header( 'Last-modified: ' . $lastmod );
134 return $rev->getText();
138 # Bad title or page does not exist
139 if( $this->mContentType
== 'text/x-wiki' ) {
140 # Don't return a 404 response for CSS or JavaScript;
141 # 404s aren't generally cached and it would create
142 # extra hits when user CSS/JS are on and the user doesn't
144 header( "HTTP/1.0 404 Not Found" );