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>
19 function RawPage( $article ) {
20 global $wgRequest, $wgInputEncoding, $wgSquidMaxage;
21 $allowedCTypes = array('text/x-wiki', 'text/javascript', 'text/css', 'application/x-zope-edit');
22 $this->mArticle
=& $article;
23 $this->mTitle
=& $article->mTitle
;
25 $ctype = $wgRequest->getText( 'ctype' );
26 $smaxage = $wgRequest->getInt( 'smaxage', $wgSquidMaxage );
27 $maxage = $wgRequest->getInt( 'maxage', $wgSquidMaxage );
28 $this->mOldId
= $wgRequest->getInt( 'oldid' );
29 # special case for 'generated' raw things: user css/js
30 $gen = $wgRequest->getText( 'gen' );
33 if($smaxage == '') $smaxage = $wgSquidMaxage;
34 if($ctype == '') $ctype = 'text/css';
35 } else if ($gen == 'js') {
37 if($smaxage == '') $smaxage = $wgSquidMaxage;
38 if($ctype == '') $ctype = 'text/javascript';
42 $this->mCharset
= $wgInputEncoding;
43 $this->mSmaxage
= $smaxage;
44 $this->mMaxage
= $maxage;
45 if(empty($ctype) or !in_array($ctype, $allowedCTypes)) {
46 $this->mContentType
= 'text/x-wiki';
48 $this->mContentType
= $ctype;
53 global $wgUser, $wgOut, $wgScript;
55 if( strncmp( $wgScript . '?', $_SERVER['REQUEST_URI'], strlen( $wgScript ) +
1 ) ) {
56 # Internet Explorer will ignore the Content-Type header if it
57 # thinks it sees a file extension it recognizes. Make sure that
58 # all raw requests are done through the script node, which will
59 # have eg '.php' and should remain safe.
61 $destUrl = $this->mTitle
->getFullUrl(
63 '&ctype=' . urlencode( $this->mContentType
) .
64 '&smaxage=' . urlencode( $this->mSmaxage
) .
65 '&maxage=' . urlencode( $this->mMaxage
) .
66 '&oldid=' . urlencode( $this->mOldId
) );
67 header( 'Location: ' . $destUrl );
72 header( "Content-type: ".$this->mContentType
.'; charset='.$this->mCharset
);
73 # allow the client to cache this for 24 hours
74 header( 'Cache-Control: s-maxage='.$this->mSmaxage
.', max-age='.$this->mMaxage
);
76 $sk = $wgUser->getSkin();
77 $sk->initPage($wgOut);
78 if($this->mGen
== 'css') {
79 echo $sk->getUserStylesheet();
80 } else if($this->mGen
== 'js') {
81 echo $sk->getUserJs();
84 echo $this->getrawtext();
89 function getrawtext () {
90 global $wgInputEncoding, $wgContLang;
91 $fname = 'RawPage::getrawtext';
93 if( !$this->mTitle
) return '';
94 $dbr =& wfGetDB( DB_SLAVE
);
95 extract( $dbr->tableNames( 'cur', 'old' ) );
97 $t = $dbr->strencode( $this->mTitle
->getDBKey() );
98 $ns = $this->mTitle
->getNamespace();
100 if($ns == NS_MEDIAWIKI
) {
101 $rawtext = wfMsg($t);
104 # else get it from the DB
105 if(!empty($this->mOldId
)) {
106 $sql = "SELECT old_text AS text,old_timestamp AS timestamp,".
107 "old_user AS user,old_flags AS flags FROM $old " .
108 "WHERE old_id={$this->mOldId}";
110 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
111 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM $cur " .
112 "WHERE cur_namespace=$ns AND cur_title='$t'";
114 $res = $dbr->query( $sql, $fname );
115 if( $s = $dbr->fetchObject( $res ) ) {
116 $rawtext = Article
::getRevisionText( $s, "" );
117 header( 'Last-modified: '.gmdate( "D, j M Y H:i:s", wfTimestamp2Unix( $s->timestamp
)).' GMT' );