Add "longdesc" attribute to all (non-external) images, containing
[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 * @package MediaWiki
11 */
12
13 /**
14 * @todo document
15 * @package MediaWiki
16 */
17 class RawPage {
18
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;
24
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' );
31 if($gen == 'css') {
32 $this->mGen = $gen;
33 if($smaxage == '') $smaxage = $wgSquidMaxage;
34 if($ctype == '') $ctype = 'text/css';
35 } else if ($gen == 'js') {
36 $this->mGen = $gen;
37 if($smaxage == '') $smaxage = $wgSquidMaxage;
38 if($ctype == '') $ctype = 'text/javascript';
39 } else {
40 $this->mGen = false;
41 }
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';
47 } else {
48 $this->mContentType = $ctype;
49 }
50 }
51
52 function view() {
53 global $wgUser, $wgOut, $wgScript;
54
55 if( strcmp( $wgScript, $_SERVER['PHP_SELF'] ) ) {
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.
60
61 $destUrl = $this->mTitle->getFullUrl(
62 'action=raw' .
63 '&ctype=' . urlencode( $this->mContentType ) .
64 '&smaxage=' . urlencode( $this->mSmaxage ) .
65 '&maxage=' . urlencode( $this->mMaxage ) .
66 '&gen=' . urlencode( $this->mGen ) .
67 '&oldid=' . urlencode( $this->mOldId ) );
68 header( 'Location: ' . $destUrl );
69 $wgOut->disable();
70 return;
71 }
72
73 header( "Content-type: ".$this->mContentType.'; charset='.$this->mCharset );
74 # allow the client to cache this for 24 hours
75 header( 'Cache-Control: s-maxage='.$this->mSmaxage.', max-age='.$this->mMaxage );
76 if($this->mGen) {
77 $sk = $wgUser->getSkin();
78 $sk->initPage($wgOut);
79 if($this->mGen == 'css') {
80 echo $sk->getUserStylesheet();
81 } else if($this->mGen == 'js') {
82 echo $sk->getUserJs();
83 }
84 } else {
85 echo $this->getrawtext();
86 }
87 $wgOut->disable();
88 }
89
90 function getrawtext () {
91 global $wgInputEncoding, $wgContLang;
92 $fname = 'RawPage::getrawtext';
93
94 if( !$this->mTitle ) return '';
95 $dbr =& wfGetDB( DB_SLAVE );
96 extract( $dbr->tableNames( 'cur', 'old' ) );
97
98 $t = $dbr->strencode( $this->mTitle->getDBKey() );
99 $ns = $this->mTitle->getNamespace();
100 # special case
101 if($ns == NS_MEDIAWIKI) {
102 $rawtext = wfMsg($t);
103 return $rawtext;
104 }
105 # else get it from the DB
106 if(!empty($this->mOldId)) {
107 $sql = "SELECT old_text AS text,old_timestamp AS timestamp,".
108 "old_user AS user,old_flags AS flags FROM $old " .
109 "WHERE old_id={$this->mOldId}";
110 } else {
111 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
112 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM $cur " .
113 "WHERE cur_namespace=$ns AND cur_title='$t'";
114 }
115 $res = $dbr->query( $sql, $fname );
116 if( $s = $dbr->fetchObject( $res ) ) {
117 $rawtext = Article::getRevisionText( $s, "" );
118 header( 'Last-modified: '.gmdate( "D, j M Y H:i:s", wfTimestamp2Unix( $s->timestamp )).' GMT' );
119 return $rawtext;
120 } else {
121 return '';
122 }
123 }
124 }
125 ?>