Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Mediawiki-CVS

SVN: [27581] trunk/phase3

 

 

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded


vasilievvv at svn

Nov 17, 2007, 8:45 AM

Post #1 of 1 (81 views)
Permalink
SVN: [27581] trunk/phase3

Revision: 27581
Author: vasilievvv
Date: 2007-11-17 16:45:59 +0000 (Sat, 17 Nov 2007)

Log Message:
-----------
API:
* Add format=raw
* Added raw output support to ApiExpandTemplates and ApiRender

Modified Paths:
--------------
trunk/phase3/RELEASE-NOTES
trunk/phase3/includes/AutoLoader.php
trunk/phase3/includes/api/ApiBase.php
trunk/phase3/includes/api/ApiExpandTemplates.php
trunk/phase3/includes/api/ApiFormatBase.php
trunk/phase3/includes/api/ApiMain.php
trunk/phase3/includes/api/ApiRender.php

Modified: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES 2007-11-17 15:07:49 UTC (rev 27580)
+++ trunk/phase3/RELEASE-NOTES 2007-11-17 16:45:59 UTC (rev 27581)
@@ -187,6 +187,7 @@
* (bug 11562) Added a user_registration parameter/field to the list=allusers query.
* (bug 11588) Preserve document structure for empty dataset in backlinks query.
* Outputting list of all user preferences rather than having to request them by name
+* Add raw formatting support. Now several actions like expandtemplates support raw output with format=raw

=== Languages updated in 1.12 ===


Modified: trunk/phase3/includes/AutoLoader.php
===================================================================
--- trunk/phase3/includes/AutoLoader.php 2007-11-17 15:07:49 UTC (rev 27580)
+++ trunk/phase3/includes/AutoLoader.php 2007-11-17 16:45:59 UTC (rev 27581)
@@ -301,6 +301,7 @@
'Services_JSON' => 'includes/api/ApiFormatJson_json.php',
'ApiFormatJson' => 'includes/api/ApiFormatJson.php',
'ApiFormatPhp' => 'includes/api/ApiFormatPhp.php',
+ 'ApiFormatRaw' => 'includes/api/ApiFormatBase.php',
'ApiFormatWddx' => 'includes/api/ApiFormatWddx.php',
'ApiFormatXml' => 'includes/api/ApiFormatXml.php',
'Spyc' => 'includes/api/ApiFormatYaml_spyc.php',

Modified: trunk/phase3/includes/api/ApiBase.php
===================================================================
--- trunk/phase3/includes/api/ApiBase.php 2007-11-17 15:07:49 UTC (rev 27580)
+++ trunk/phase3/includes/api/ApiBase.php 2007-11-17 16:45:59 UTC (rev 27581)
@@ -509,7 +509,30 @@
wfDebugDieBacktrace("Internal error in $method: $message");
}

+ private $mRawFormat = false;
+
/**
+ * Returns if module supports raw mode
+ */
+ public function supportRaw() {
+ return false;
+ }
+
+ /**
+ * Enables raw mode
+ */
+ public function setRaw() {
+ $this->mRawFormat = true;
+ }
+
+ /**
+ * Checks if raw mode is enabled
+ */
+ public function isRaw() {
+ return $this->mRawFormat;
+ }
+
+ /**
* Profiling: total module execution time
*/
private $mTimeIn = 0, $mModuleTime = 0;
@@ -617,3 +640,4 @@
}
}

+

Modified: trunk/phase3/includes/api/ApiExpandTemplates.php
===================================================================
--- trunk/phase3/includes/api/ApiExpandTemplates.php 2007-11-17 15:07:49 UTC (rev 27580)
+++ trunk/phase3/includes/api/ApiExpandTemplates.php 2007-11-17 16:45:59 UTC (rev 27581)
@@ -55,11 +55,18 @@

// Return result
$result = $this->getResult();
+ if( $this->isRaw() ) {
+ ApiFormatRaw :: setRawData( $result, $retval );
+ }
$retval_array = array();
$result->setContent( $retval_array, $retval );
$result->addValue( null, $this->getModuleName(), $retval_array );
}

+ public function supportRaw() {
+ return true;
+ }
+
protected function getAllowedParams() {
return array (
'title' => array(
@@ -91,3 +98,4 @@
}
}

+

Modified: trunk/phase3/includes/api/ApiFormatBase.php
===================================================================
--- trunk/phase3/includes/api/ApiFormatBase.php 2007-11-17 15:07:49 UTC (rev 27580)
+++ trunk/phase3/includes/api/ApiFormatBase.php 2007-11-17 16:45:59 UTC (rev 27581)
@@ -276,3 +276,49 @@
return __CLASS__ . ': $Id$';
}
}
+
+/**
+ * This printer is used to wrap raw printer
+ * @addtogroup API
+ */
+class ApiFormatRaw extends ApiFormatBase {
+
+ public function __construct($main, $format) {
+ parent :: __construct($main, $format);
+ }
+
+ public static function setRawData( $result, $raw_data ) {
+ $data = & $result->getData();
+ $data['_raw'] = $raw_data;
+ }
+
+ public function getMimeType() {
+ return 'text/plain';
+ }
+
+ public function execute() {
+ $data = $this->getResultData();
+ if( !isset( $data['_raw'] ) && !isset( $data['error'] ) ) {
+ ApiBase :: dieDebug( 'ApiFormatRaw', 'No raw data is set for this module' );
+ }
+ elseif( isset( $data['error'] ) ) {
+ header( '500 Internal error' );
+ echo "{$data['error']['code']}\n";
+ echo "{$data['error']['info']}\n";
+ return;
+ }
+ $this->printText( $data['_raw'] );
+ }
+
+ public function getNeedsRawData() {
+ return true;
+ }
+
+ protected function getDescription() {
+ return 'Output data in raw format. NOTE: not all actions support it' . parent :: getDescription();
+ }
+
+ public function getVersion() {
+ return __CLASS__ . ': $Id$';
+ }
+}

Modified: trunk/phase3/includes/api/ApiMain.php
===================================================================
--- trunk/phase3/includes/api/ApiMain.php 2007-11-17 15:07:49 UTC (rev 27580)
+++ trunk/phase3/includes/api/ApiMain.php 2007-11-17 16:45:59 UTC (rev 27581)
@@ -75,6 +75,7 @@
'xmlfm' => 'ApiFormatXml',
'yaml' => 'ApiFormatYaml',
'yamlfm' => 'ApiFormatYaml',
+ 'raw' => 'ApiFormatRaw',
'rawfm' => 'ApiFormatJson'
);

@@ -292,6 +293,15 @@

if (!$this->mInternalMode) {

+ //Check usage of raw printer
+ if( $params['format'] == 'raw' ) {
+ if( !$module->supportRaw() ) {
+ ApiBase :: dieUsage( 'This module doesn\'t support format=raw', 'rawnotsupported' );
+ return;
+ }
+ $module->setRaw();
+ }
+
// See if custom printer is used
$this->mPrinter = $module->getCustomPrinter();
if (is_null($this->mPrinter)) {
@@ -543,3 +553,4 @@
}


+

Modified: trunk/phase3/includes/api/ApiRender.php
===================================================================
--- trunk/phase3/includes/api/ApiRender.php 2007-11-17 15:07:49 UTC (rev 27580)
+++ trunk/phase3/includes/api/ApiRender.php 2007-11-17 16:45:59 UTC (rev 27581)
@@ -56,11 +56,18 @@

// Return result
$result = $this->getResult();
+ if( $this->isRaw() ) {
+ ApiFormatRaw :: setRawData( $result, $retval );
+ }
$retval_array = array();
$result->setContent( $retval_array, $retval );
$result->addValue( null, $this->getModuleName(), $retval_array );
}

+ public function supportRaw() {
+ return true;
+ }
+
protected function getAllowedParams() {
return array (
'title' => array(
@@ -92,3 +99,4 @@
}
}

+



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS[at]lists.wikimedia.org
http://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.