Index: trunk/phase3/includes/api/ApiQuery.php |
— | — | @@ -81,6 +81,7 @@ |
82 | 82 | 'users' => 'ApiQueryUsers', |
83 | 83 | 'random' => 'ApiQueryRandom', |
84 | 84 | 'protectedtitles' => 'ApiQueryProtectedTitles', |
| 85 | + 'querypage' => 'ApiQueryQuerypage', |
85 | 86 | ); |
86 | 87 | |
87 | 88 | private $mQueryMetaModules = array ( |
Index: trunk/phase3/includes/api/ApiQueryQuerypage.php |
— | — | @@ -0,0 +1,137 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on Jul 12, 2009 |
| 6 | + * |
| 7 | + * API for MediaWiki 1.8+ |
| 8 | + * |
| 9 | + * Copyright (C) 2009 Bryan Tong Minh <Bryan.TongMinh@Gmail.com> |
| 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 ('ApiQueryBase.php'); |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Query module to access querypages |
| 34 | + * |
| 35 | + * @ingroup API |
| 36 | + */ |
| 37 | +class ApiQueryQuerypage extends ApiQueryBase { |
| 38 | + static $queryPages = array( |
| 39 | + 'brokenredirects' => 'BrokenRedirectsPage' |
| 40 | + ); |
| 41 | + |
| 42 | + public function __construct($query, $moduleName) { |
| 43 | + parent :: __construct($query, $moduleName, 'qp'); |
| 44 | + } |
| 45 | + |
| 46 | + public function execute() { |
| 47 | + $this->run(); |
| 48 | + } |
| 49 | + |
| 50 | + public function executeGenerator($resultPageSet) { |
| 51 | + $this->run( $resultPageSet ); |
| 52 | + } |
| 53 | + |
| 54 | + private function run($resultPageSet = null) { |
| 55 | + $params = $this->extractRequestParams(); |
| 56 | + $offset = $params['offset']; |
| 57 | + $limit = $params['limit']; |
| 58 | + |
| 59 | + // Try to find an entry in $wgQueryPages |
| 60 | + $qpName = $params['querypage']; |
| 61 | + if ( is_null( $qpName ) ) |
| 62 | + $this->dieUsageMsg( array( 'missingparam', 'querypage' ) ); |
| 63 | + if ( !isset( self::$queryPages[$qpName] ) ) |
| 64 | + $this->dieUsage( 'Querypage unrecognized', 'unknownquerypage' ); |
| 65 | + |
| 66 | + $qpClass = self::$queryPages[$qpName]; |
| 67 | + $qpInstance = new $qpClass; |
| 68 | + $result = $qpInstance->reallyDoQuery( $offset, $limit + 1 ); |
| 69 | + |
| 70 | + $apiResult = $this->getResult(); |
| 71 | + $count = 0; |
| 72 | + while ( $row = $result['dbr']->fetchObject( $result['result'] ) ) { |
| 73 | + if ( ++ $count > $limit ) { |
| 74 | + // We've reached the one extra which shows that there are additional pages to be had. Stop here... |
| 75 | + $this->setContinueEnumParameter( 'offset', $offset + $count - 1 ); |
| 76 | + break; |
| 77 | + } |
| 78 | + if ( is_null( $resultPageSet ) ) { |
| 79 | + // Normal mode; let the query page make a sensible result out of it |
| 80 | + $vals = $qpInstance->formatApiResult( $row ); |
| 81 | + $fit = $apiResult->addValue( array( 'query', $this->getModuleName() ), null, $vals ); |
| 82 | + if( !$fit ) |
| 83 | + { |
| 84 | + $this->setContinueEnumParameter( 'offset', $params['offset'] + $count ); |
| 85 | + break; |
| 86 | + } |
| 87 | + } else { |
| 88 | + // Generator mode; not yet supported |
| 89 | + $resultPageSet->processDbRow( $row ); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + |
| 94 | + if ( is_null( $resultPageSet ) ) { |
| 95 | + $apiResult->setIndexedTagName_internal( array( 'query', $this->getModuleName()), 'p' ); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + public function getAllowedParams() { |
| 100 | + |
| 101 | + return array ( |
| 102 | + 'offset' => 0, |
| 103 | + 'limit' => array ( |
| 104 | + ApiBase :: PARAM_DFLT => 10, |
| 105 | + ApiBase :: PARAM_TYPE => 'limit', |
| 106 | + ApiBase :: PARAM_MIN => 1, |
| 107 | + ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, |
| 108 | + ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 |
| 109 | + ), |
| 110 | + 'querypage' => array( |
| 111 | + ApiBase :: PARAM_TYPE => array_keys( self::$queryPages ) |
| 112 | + ), |
| 113 | + ); |
| 114 | + } |
| 115 | + |
| 116 | + public function getParamDescription() { |
| 117 | + return array ( |
| 118 | + 'offset' => 'The offset to start enumerating from.', |
| 119 | + 'limit' => 'How many total pages to return.', |
| 120 | + 'querypage' => 'Which querypage to use', |
| 121 | + ); |
| 122 | + } |
| 123 | + |
| 124 | + public function getDescription() { |
| 125 | + return 'Query one of the builtin query pages.'; |
| 126 | + } |
| 127 | + |
| 128 | + protected function getExamples() { |
| 129 | + return array ( |
| 130 | + ' Query a list of broken redirects', |
| 131 | + ' api.php?action=query&list=querypage&qpquerypage=brokenredirects', |
| 132 | + ); |
| 133 | + } |
| 134 | + |
| 135 | + public function getVersion() { |
| 136 | + return __CLASS__ . ': $Id:$'; |
| 137 | + } |
| 138 | +} |
\ No newline at end of file |
Property changes on: trunk/phase3/includes/api/ApiQueryQuerypage.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 139 | + native |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -302,6 +302,7 @@ |
303 | 303 | 'ApiQueryLangLinks' => 'includes/api/ApiQueryLangLinks.php', |
304 | 304 | 'ApiQueryLinks' => 'includes/api/ApiQueryLinks.php', |
305 | 305 | 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php', |
| 306 | + 'ApiQueryQuerypage' => 'includes/api/ApiQueryQuerypage.php', |
306 | 307 | 'ApiQueryProtectedTitles' => 'includes/api/ApiQueryProtectedTitles.php', |
307 | 308 | 'ApiQueryRandom' => 'includes/api/ApiQueryRandom.php', |
308 | 309 | 'ApiQueryRecentChanges'=> 'includes/api/ApiQueryRecentChanges.php', |
Index: trunk/phase3/includes/QueryPage.php |
— | — | @@ -176,10 +176,10 @@ |
177 | 177 | * Formats the result as something that can be understood by the API. |
178 | 178 | * Defaults to setting id, ns and title |
179 | 179 | */ |
180 | | - function formatApiResult( $result ) { |
| 180 | + function formatApiResult( $row ) { |
181 | 181 | $title = Title::makeTitle( $row->namespace, $row->title ); |
182 | 182 | return array( |
183 | | - 'pageid' => intval( $row->id ), |
| 183 | + //'pageid' => intval( $row->id ), |
184 | 184 | 'ns' => intval( $title->getNamespace() ), |
185 | 185 | 'title' => $title->getPrefixedText(), |
186 | 186 | ); |
— | — | @@ -361,7 +361,7 @@ |
362 | 362 | * 'count' => number of results, |
363 | 363 | * 'dbr' => the database used for fetching the data |
364 | 364 | */ |
365 | | - protected function reallyDoQuery( $offset, $limit ) { |
| 365 | + public function reallyDoQuery( $offset, $limit ) { |
366 | 366 | $result = array( 'disabled' => false ); |
367 | 367 | |
368 | 368 | $this->offset = $offset; |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -290,6 +290,7 @@ |
291 | 291 | * Added snippet field to list=search output |
292 | 292 | * (bug 17809) Add number of users in user groups to meta=siteinfo |
293 | 293 | * (bug 18533) Add readonly reason to readonly exception |
| 294 | +* (bug 14869) Allow access to QueryPage-based special pages via API |
294 | 295 | |
295 | 296 | === Languages updated in 1.16 === |
296 | 297 | |