cache headers- allow client to cache for one day
[lhc/web/wiklou.git] / includes / RawPage.php
1 <?php
2 # Copyright (C) 2004 Gabriel Wicke <gw@wikidev.net>
3 # http://www.aulinx.de/
4 # Based on PageHistory and SpecialExport
5 #
6 # License: GPL (http://www.gnu.org/copyleft/gpl.html)
7
8 class RawPage {
9
10 function RawPage( $article ) {
11 global $wgRequest, $wgInputEncoding;
12 $this->mArticle =& $article;
13 $this->mTitle =& $article->mTitle;
14 $ctype = $wgRequest->getText( 'ctype' );
15 $this->mContentType = !empty($ctype)?$ctype:'text/plain';
16 $charset = $wgRequest->getText( 'charset' );
17 $this->mCharset = !empty($charset) ? $charset : $wgInputEncoding;
18 $this->mOldId = $wgRequest->getInt( 'oldid' );
19 }
20 function view() {
21 header( "Content-type: ".$this->mContentType.'; charset='.$this->mCharset );
22 # allow the client to cache this for 24 hours
23 header( 'Cache-Control: s-maxage=0, max-age=86400' );
24 echo $this->getrawtext();
25 wfAbruptExit();
26 }
27
28 function getrawtext () {
29 global $wgInputEncoding, $wgLang;
30 if( !$this->mTitle ) return '';
31 $t = wfStrencode( $this->mTitle->getDBKey() );
32 $ns = $this->mTitle->getNamespace();
33 if(!empty($this->mOldId)) {
34 $sql = "SELECT old_text as text,old_timestamp as timestamp,old_user as user,old_flags as flags FROM old " .
35 "WHERE old_id={$this->mOldId}";
36 } else {
37 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
38 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
39 "WHERE cur_namespace=$ns AND cur_title='$t'";
40 }
41 $res = wfQuery( $sql, DB_READ );
42 if( $s = wfFetchObject( $res ) ) {
43 $rawtext = Article::getRevisionText( $s, "" );
44 if($wgInputEncoding != $this->mCharset)
45 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
46 return $rawtext;
47 } else {
48 return '';
49 }
50 }
51 }
52 ?>