New, simple method to retrieve the plain source of an article
authorGabriel Wicke <gwicke@users.mediawiki.org>
Wed, 28 Apr 2004 17:38:48 +0000 (17:38 +0000)
committerGabriel Wicke <gwicke@users.mediawiki.org>
Wed, 28 Apr 2004 17:38:48 +0000 (17:38 +0000)
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 [new file with mode: 0644]
includes/SpecialExport.php
index.php

diff --git a/includes/RawPage.php b/includes/RawPage.php
new file mode 100644 (file)
index 0000000..faf2726
--- /dev/null
@@ -0,0 +1,50 @@
+<?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 );
+               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 '';
+               }
+       }
+}
+?>
index 8497113..06aa57d 100644 (file)
@@ -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() );
index 91b6eb5..0d54b6b 100644 (file)
--- 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 );