r53149 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53148‎ | r53149 | r53150 >
Date:21:51, 12 July 2009
Author:btongminh
Status:reverted
Tags:
Comment:
(bug 14869) Allow access to QueryPage-based special pages via API
Only brokenredirects for now, until I find out which other special pages are suitable.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/QueryPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryQuerypage.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuery.php
@@ -81,6 +81,7 @@
8282 'users' => 'ApiQueryUsers',
8383 'random' => 'ApiQueryRandom',
8484 'protectedtitles' => 'ApiQueryProtectedTitles',
 85+ 'querypage' => 'ApiQueryQuerypage',
8586 );
8687
8788 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
1139 + native
Index: trunk/phase3/includes/AutoLoader.php
@@ -302,6 +302,7 @@
303303 'ApiQueryLangLinks' => 'includes/api/ApiQueryLangLinks.php',
304304 'ApiQueryLinks' => 'includes/api/ApiQueryLinks.php',
305305 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php',
 306+ 'ApiQueryQuerypage' => 'includes/api/ApiQueryQuerypage.php',
306307 'ApiQueryProtectedTitles' => 'includes/api/ApiQueryProtectedTitles.php',
307308 'ApiQueryRandom' => 'includes/api/ApiQueryRandom.php',
308309 'ApiQueryRecentChanges'=> 'includes/api/ApiQueryRecentChanges.php',
Index: trunk/phase3/includes/QueryPage.php
@@ -176,10 +176,10 @@
177177 * Formats the result as something that can be understood by the API.
178178 * Defaults to setting id, ns and title
179179 */
180 - function formatApiResult( $result ) {
 180+ function formatApiResult( $row ) {
181181 $title = Title::makeTitle( $row->namespace, $row->title );
182182 return array(
183 - 'pageid' => intval( $row->id ),
 183+ //'pageid' => intval( $row->id ),
184184 'ns' => intval( $title->getNamespace() ),
185185 'title' => $title->getPrefixedText(),
186186 );
@@ -361,7 +361,7 @@
362362 * 'count' => number of results,
363363 * 'dbr' => the database used for fetching the data
364364 */
365 - protected function reallyDoQuery( $offset, $limit ) {
 365+ public function reallyDoQuery( $offset, $limit ) {
366366 $result = array( 'disabled' => false );
367367
368368 $this->offset = $offset;
Index: trunk/phase3/RELEASE-NOTES
@@ -290,6 +290,7 @@
291291 * Added snippet field to list=search output
292292 * (bug 17809) Add number of users in user groups to meta=siteinfo
293293 * (bug 18533) Add readonly reason to readonly exception
 294+* (bug 14869) Allow access to QueryPage-based special pages via API
294295
295296 === Languages updated in 1.16 ===
296297

Follow-up revisions

RevisionCommit summaryAuthorDate
r53167Revert r53147, r53149 and r53163 ("Add API module for QueryPage-based special...catrope12:40, 13 July 2009
r78786Merge querypage-work2 branch from trunk. The most relevant changes are:...catrope14:16, 22 December 2010
r78824(bug 14869) Add API module for accessing QueryPage-based special pages. Took ...catrope20:35, 22 December 2010
r78837Per bug 14869 being fixed, bug 8130 and bug 14020 have been fixed. Marking th...reedy21:30, 22 December 2010

Status & tagging log