r46730 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46729‎ | r46730 | r46731 >
Date:20:07, 2 February 2009
Author:catrope
Status:deferred (Comments)
Tags:
Comment:
* API: (bug 17007) Add export functionality to the API
* Accessed through the export and exportnowrap parameters added to action=query
* To facilitate &exportnowrap, add ApiFormatRaw, a formatter that just spits out its input without any formatting (not accessible through &format= of course)
* Fix up the action=query description message to reflect the deprecation of query.php
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiFormatRaw.php (added) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiFormatRaw.php
@@ -0,0 +1,58 @@
 2+<?php
 3+
 4+/*
 5+ * Created on Feb 2, 2009
 6+ *
 7+ * API for MediaWiki 1.8+
 8+ *
 9+ * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
 10+ *
 11+ * This program is free software; you can redistribute it and/or modify
 12+ * it under the terms of the GNU General Public License as published by
 13+ * the Free Software Foundation; either version 2 of the License, or
 14+ * (at your option) any later version.
 15+ *
 16+ * This program is distributed in the hope that it will be useful,
 17+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 19+ * GNU General Public License for more details.
 20+ *
 21+ * You should have received a copy of the GNU General Public License along
 22+ * with this program; if not, write to the Free Software Foundation, Inc.,
 23+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 24+ * http://www.gnu.org/copyleft/gpl.html
 25+ */
 26+
 27+if (!defined('MEDIAWIKI')) {
 28+ // Eclipse helper - will be ignored in production
 29+ require_once ('ApiFormatBase.php');
 30+}
 31+
 32+/**
 33+ * Formatter that spits out anything you like with any desired MIME type
 34+ * @ingroup API
 35+ */
 36+class ApiFormatRaw extends ApiFormatBase {
 37+
 38+ public function __construct($main, $format) {
 39+ parent :: __construct($main, $format);
 40+ }
 41+
 42+ public function getMimeType() {
 43+ $data = $this->getResultData();
 44+ if(!isset($data['mime']))
 45+ ApiBase::dieDebug(__METHOD__, "No MIME type set for raw formatter");
 46+ return $data['mime'];
 47+ }
 48+
 49+ public function execute() {
 50+ $data = $this->getResultData();
 51+ if(!isset($data['text']))
 52+ ApiBase::dieDebug(__METHOD__, "No text given for raw formatter");
 53+ $this->printText($data['text']);
 54+ }
 55+
 56+ public function getVersion() {
 57+ return __CLASS__ . ': $Id$';
 58+ }
 59+}
Property changes on: trunk/phase3/includes/api/ApiFormatRaw.php
___________________________________________________________________
Name: svn:eol-style
160 + native
Name: svn:keywords
261 + Id
Index: trunk/phase3/includes/api/ApiQuery.php
@@ -160,6 +160,14 @@
161161 function getModules() {
162162 return array_merge($this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules);
163163 }
 164+
 165+ public function getCustomPrinter() {
 166+ // If &exportnowrap is set, use the raw formatter
 167+ if ($this->getParameter('exportnowrap'))
 168+ return new ApiFormatRaw($this->getMain());
 169+ else
 170+ return null;
 171+ }
164172
165173 /**
166174 * Query execution happens in the following steps:
@@ -347,6 +355,27 @@
348356
349357 $result->setIndexedTagName($pages, 'page');
350358 $result->addValue('query', 'pages', $pages);
 359+
 360+ if ($this->params['export']) {
 361+ $exporter = new WikiExporter($this->getDB());
 362+ // WikiExporter writes to stdout, so catch its
 363+ // output with an ob
 364+ ob_start();
 365+ $exporter->openStream();
 366+ foreach ($pageSet->getGoodTitles() as $title)
 367+ if ($title->userCanRead())
 368+ $exporter->pageByTitle($title);
 369+ $exporter->closeStream();
 370+ $exportxml = ob_get_contents();
 371+ ob_end_clean();
 372+ if ($this->params['exportnowrap']) {
 373+ $result->reset();
 374+ // Raw formatter will handle this
 375+ $result->addValue(null, 'text', $exportxml);
 376+ $result->addValue(null, 'mime', 'text/xml');
 377+ } else
 378+ $result->addValue('query', 'export', $exportxml);
 379+ }
351380 }
352381 }
353382
@@ -415,6 +444,8 @@
416445 ),
417446 'redirects' => false,
418447 'indexpageids' => false,
 448+ 'export' => false,
 449+ 'exportnowrap' => false,
419450 );
420451 }
421452
@@ -491,14 +522,16 @@
492523 'meta' => 'Which meta data to get about the site',
493524 'generator' => 'Use the output of a list as the input for other prop/list/meta items',
494525 'redirects' => 'Automatically resolve redirects',
495 - 'indexpageids' => 'Include an additional pageids section listing all returned page IDs.'
 526+ 'indexpageids' => 'Include an additional pageids section listing all returned page IDs.',
 527+ 'export' => 'Export the current revisions of all given or generated pages',
 528+ 'exportnowrap' => 'Return the export XML without wrapping it in an XML result',
496529 );
497530 }
498531
499532 public function getDescription() {
500533 return array (
501534 'Query API module allows applications to get needed pieces of data from the MediaWiki databases,',
502 - 'and is loosely based on the Query API interface currently available on all MediaWiki servers.',
 535+ 'and is loosely based on the old query.php interface.',
503536 'All data modifications will first have to use query to acquire a token to prevent abuse from malicious sites.'
504537 );
505538 }
Index: trunk/phase3/includes/AutoLoader.php
@@ -228,6 +228,7 @@
229229 'ApiFormatFeedWrapper' => 'includes/api/ApiFormatBase.php',
230230 'ApiFormatJson' => 'includes/api/ApiFormatJson.php',
231231 'ApiFormatPhp' => 'includes/api/ApiFormatPhp.php',
 232+ 'ApiFormatRaw' => 'includes/api/ApiFormatRaw.php',
232233 'ApiFormatTxt' => 'includes/api/ApiFormatTxt.php',
233234 'ApiFormatWddx' => 'includes/api/ApiFormatWddx.php',
234235 'ApiFormatXml' => 'includes/api/ApiFormatXml.php',
Index: trunk/phase3/RELEASE-NOTES
@@ -155,6 +155,7 @@
156156 * (bug 17224) Added siprop=rightsinfo to meta=siteinfo
157157 * (bug 17239) Added prop=displaytitle to action=parse
158158 * (bug 17317) Added watch parameter to action=protect
 159+* (bug 17007) Added export and exportnowrap parameters to action=query
159160
160161 === Languages updated in 1.15 ===
161162

Follow-up revisions

RevisionCommit summaryAuthorDate
r46815* API: (bug 17007) Add action=import...catrope20:11, 4 February 2009

Comments

#Comment by Catrope (talk | contribs)   22:13, 4 February 2009

Fixed up in r46819; DO NOT scap this without also scapping r46819.

Status & tagging log