New, simple method to retrieve the plain source of an article
[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 echo $this->getrawtext();
23 wfAbruptExit();
24 }
25
26 function getrawtext () {
27 global $wgInputEncoding, $wgLang;
28 if( !$this->mTitle ) return '';
29 $t = wfStrencode( $this->mTitle->getDBKey() );
30 $ns = $this->mTitle->getNamespace();
31 if(!empty($this->mOldId)) {
32 $sql = "SELECT old_text as text,old_timestamp as timestamp,old_user as user,old_flags as flags FROM old " .
33 "WHERE old_id={$this->mOldId}";
34 } else {
35 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
36 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
37 "WHERE cur_namespace=$ns AND cur_title='$t'";
38 }
39 $res = wfQuery( $sql, DB_READ );
40 if( $s = wfFetchObject( $res ) ) {
41 $rawtext = Article::getRevisionText( $s, "" );
42 if($wgInputEncoding != $this->mCharset)
43 $rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
44 return $rawtext;
45 } else {
46 return '';
47 }
48 }
49 }
50 ?>