aboutsummaryrefslogtreecommitdiffstats
path: root/includes/RawPage.php
blob: 8ed7bcee0e485bc4317087cc67de7539507de617 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
# Copyright (C) 2004 Gabriel Wicke <gw@wikidev.net>
# http://www.aulinx.de/
# Based on PageHistory and SpecialExport
# 
# License: GPL (http://www.gnu.org/copyleft/gpl.html)

class RawPage {

	function RawPage( $article ) {
		global $wgRequest, $wgInputEncoding;
		$this->mArticle =& $article;
		$this->mTitle =& $article->mTitle;
		$ctype = $wgRequest->getText( 'ctype' );
		$this->mContentType = !empty($ctype)?$ctype:'text/plain';
		$charset = $wgRequest->getText( 'charset' );
		$this->mCharset = !empty($charset) ? $charset : $wgInputEncoding;
		$this->mOldId = $wgRequest->getInt( 'oldid' );
	}
	function view() {
		header( "Content-type: ".$this->mContentType.'; charset='.$this->mCharset );
		# allow the client to cache this for 24 hours
		header( 'Cache-Control: s-maxage=0, max-age=86400' );
		echo $this->getrawtext();
		wfAbruptExit();
	}

	function getrawtext () {
		global $wgInputEncoding, $wgLang;
		if( !$this->mTitle ) return '';
		$t = wfStrencode( $this->mTitle->getDBKey() );
		$ns = $this->mTitle->getNamespace();
		if(!empty($this->mOldId)) {
			$sql = "SELECT old_text as text,old_timestamp as timestamp,old_user as user,old_flags as flags FROM old " .
			"WHERE old_id={$this->mOldId}";
		} else {
			$sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
			"cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
			"WHERE cur_namespace=$ns AND cur_title='$t'";
		}
		$res = wfQuery( $sql, DB_READ );
		if( $s = wfFetchObject( $res ) ) {
			$rawtext = Article::getRevisionText( $s, "" );
			if($wgInputEncoding != $this->mCharset)
			$rawtext = $wgLang->iconv( $wgInputEncoding, $this->mCharset, $rawtext );
			return $rawtext;
		} else {
			return '';
		}
	}
}
?>