From df106e2f495b8a2d5ec0c6946f7c19d54eaa30e6 Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Wed, 28 Apr 2004 17:38:48 +0000 Subject: [PATCH] New, simple method to retrieve the plain source of an article Syntax: * action=raw * ctype=text/plain (defaults to text/plain, used in the header) * charset=utf-8 (defaults to wgInputEncoding, used in header) * oldid=int (retrieves old version if set) --- includes/RawPage.php | 50 ++++++++++++++++++++++++++++++++++++++ includes/SpecialExport.php | 2 +- index.php | 5 ++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 includes/RawPage.php diff --git a/includes/RawPage.php b/includes/RawPage.php new file mode 100644 index 0000000000..faf2726268 --- /dev/null +++ b/includes/RawPage.php @@ -0,0 +1,50 @@ + +# 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 ); + 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 ''; + } + } +} +?> diff --git a/includes/SpecialExport.php b/includes/SpecialExport.php index 84971135e7..06aa57de45 100644 --- a/includes/SpecialExport.php +++ b/includes/SpecialExport.php @@ -64,7 +64,7 @@ function pages2xml( $pages, $curonly = false ) { } function page2xml( $page, $curonly, $full = false ) { - global $wgInputCharset, $wgLang; + global $wgLang; $title = Title::NewFromText( $page ); if( !$title ) return ""; $t = wfStrencode( $title->getDBKey() ); diff --git a/index.php b/index.php index 91b6eb52c9..0d54b6b2f4 100644 --- a/index.php +++ b/index.php @@ -143,6 +143,11 @@ if ( $search = $wgRequest->getText( 'search' ) ) { $history = new PageHistory( $wgArticle ); $history->history(); break; + case "raw": + include_once( "RawPage.php" ); + $raw = new RawPage( $wgArticle ); + $raw->view(); + break; case "purge": wfPurgeSquidServers(array($wgTitle->getInternalURL())); $wgOut->setSquidMaxage( $wgSquidMaxage ); -- 2.20.1