Changing comments layout preparing for generated documentation with Phpdocumentor
[lhc/web/wiklou.git] / includes / RawPage.php
1 <?php
2 /**
3 * Copyright (C) 2004 Gabriel Wicke <gw@wikidev.net>
4 * http://www.aulinx.de/
5 * Based on PageHistory and SpecialExport
6 *
7 * License: GPL (http://www.gnu.org/copyleft/gpl.html)
8 *
9 * @author Gabriel Wicke <gw@wikidev.net>
10 */
11
12 /**
13 * @todo document
14 */
15 class RawPage {
16
17 function RawPage( $article ) {
18 global $wgRequest, $wgInputEncoding, $wgSquidMaxage;
19 $allowedCTypes = array('text/x-wiki', 'text/javascript', 'text/css', 'application/x-zope-edit');
20 $this->mArticle =& $article;
21 $this->mTitle =& $article->mTitle;
22
23 $ctype = $wgRequest->getText( 'ctype' );
24 $charset = $wgRequest->getText( 'charset' );
25 $smaxage = $wgRequest->getText( 'smaxage' );
26 $maxage = $wgRequest->getText( 'maxage' );
27 $this->mOldId = $wgRequest->getInt( 'oldid' );
28 # special case for 'generated' raw things: user css/js
29 $gen = $wgRequest->getText( 'gen' );
30 if($gen == 'css') {
31 $this->mGen = $gen;
32 if($smaxage == '') $smaxage = $wgSquidMaxage;
33 if($ctype == '') $ctype = 'text/css';
34 } else if ($gen == 'js') {
35 $this->mGen = $gen;
36 if($smaxage == '') $smaxage = $wgSquidMaxage;
37 if($ctype == '') $ctype = 'text/javascript';
38 } else {
39 $this->mGen = false;
40 }
41 $this->mCharset = !empty($charset) ? $charset : $wgInputEncoding;
42 $this->mSmaxage = ($smaxage != '') ? $smaxage : 0;
43 $this->mMaxage = ($maxage != '') ? $maxage : 86400;
44 if(empty($ctype) or !in_array($ctype, $allowedCTypes)) {
45 $this->mContentType = 'text/x-wiki';
46 } else {
47 $this->mContentType = $ctype;
48 }
49 }
50
51 function view() {
52 global $wgUser, $wgOut;
53 header( "Content-type: ".$this->mContentType.'; charset='.$this->mCharset );
54 # allow the client to cache this for 24 hours
55 header( 'Cache-Control: s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage );
56 if($this->mGen) {
57 $sk = $wgUser->getSkin();
58 $sk->initPage($wgOut);
59 if($this->mGen == 'css') {
60 echo $sk->getUserStylesheet();
61 } else if($this->mGen == 'js') {
62 echo $sk->getUserJs();
63 }
64 } else {
65 echo $this->getrawtext();
66 }
67 $wgOut->disable();
68 }
69
70 function getrawtext () {
71 global $wgInputEncoding, $wgLang;
72 $fname = 'RawPage::getrawtext';
73
74 if( !$this->mTitle ) return '';
75 $dbr =& wfGetDB( DB_SLAVE );
76 extract( $dbr->tableNames( 'cur', 'old' ) );
77
78 $t = $dbr->strencode( $this->mTitle->getDBKey() );
79 $ns = $this->mTitle->getNamespace();
80 # special case
81 if($ns == NS_MEDIAWIKI) {
82 $rawtext = wfMsg($t);
83 if($wgInputEncoding != $this->mCharset)
84 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
85 return $rawtext;
86 }
87 # else get it from the DB
88 if(!empty($this->mOldId)) {
89 $sql = "SELECT old_text AS text,old_timestamp AS timestamp,".
90 "old_user AS user,old_flags AS flags FROM $old " .
91 "WHERE old_id={$this->mOldId}";
92 } else {
93 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
94 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM $cur " .
95 "WHERE cur_namespace=$ns AND cur_title='$t'";
96 }
97 $res = $dbr->query( $sql, $fname );
98 if( $s = $dbr->fetchObject( $res ) ) {
99 $rawtext = Article::getRevisionText( $s, "" );
100 if($wgInputEncoding != $this->mCharset)
101 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
102 header( 'Last-modified: '.gmdate( "D, j M Y H:i:s", wfTimestamp2Unix( $s->timestamp )).' GMT' );
103 return $rawtext;
104 } else {
105 return '';
106 }
107 }
108 }
109 ?>