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 |
1 | 60 | + native |
Name: svn:keywords |
2 | 61 | + Id |
Index: trunk/phase3/includes/api/ApiQuery.php |
— | — | @@ -160,6 +160,14 @@ |
161 | 161 | function getModules() { |
162 | 162 | return array_merge($this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules); |
163 | 163 | } |
| 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 | + } |
164 | 172 | |
165 | 173 | /** |
166 | 174 | * Query execution happens in the following steps: |
— | — | @@ -347,6 +355,27 @@ |
348 | 356 | |
349 | 357 | $result->setIndexedTagName($pages, 'page'); |
350 | 358 | $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 | + } |
351 | 380 | } |
352 | 381 | } |
353 | 382 | |
— | — | @@ -415,6 +444,8 @@ |
416 | 445 | ), |
417 | 446 | 'redirects' => false, |
418 | 447 | 'indexpageids' => false, |
| 448 | + 'export' => false, |
| 449 | + 'exportnowrap' => false, |
419 | 450 | ); |
420 | 451 | } |
421 | 452 | |
— | — | @@ -491,14 +522,16 @@ |
492 | 523 | 'meta' => 'Which meta data to get about the site', |
493 | 524 | 'generator' => 'Use the output of a list as the input for other prop/list/meta items', |
494 | 525 | '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', |
496 | 529 | ); |
497 | 530 | } |
498 | 531 | |
499 | 532 | public function getDescription() { |
500 | 533 | return array ( |
501 | 534 | '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.', |
503 | 536 | 'All data modifications will first have to use query to acquire a token to prevent abuse from malicious sites.' |
504 | 537 | ); |
505 | 538 | } |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -228,6 +228,7 @@ |
229 | 229 | 'ApiFormatFeedWrapper' => 'includes/api/ApiFormatBase.php', |
230 | 230 | 'ApiFormatJson' => 'includes/api/ApiFormatJson.php', |
231 | 231 | 'ApiFormatPhp' => 'includes/api/ApiFormatPhp.php', |
| 232 | + 'ApiFormatRaw' => 'includes/api/ApiFormatRaw.php', |
232 | 233 | 'ApiFormatTxt' => 'includes/api/ApiFormatTxt.php', |
233 | 234 | 'ApiFormatWddx' => 'includes/api/ApiFormatWddx.php', |
234 | 235 | 'ApiFormatXml' => 'includes/api/ApiFormatXml.php', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -155,6 +155,7 @@ |
156 | 156 | * (bug 17224) Added siprop=rightsinfo to meta=siteinfo |
157 | 157 | * (bug 17239) Added prop=displaytitle to action=parse |
158 | 158 | * (bug 17317) Added watch parameter to action=protect |
| 159 | +* (bug 17007) Added export and exportnowrap parameters to action=query |
159 | 160 | |
160 | 161 | === Languages updated in 1.15 === |
161 | 162 | |