r53167 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53166‎ | r53167 | r53168 >
Date:12:40, 13 July 2009
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Revert r53147, r53149 and r53163 ("Add API module for QueryPage-based special pages"): this has already been worked on more extensively and cleanly in the querypage-work branch, if you wanna work on this please finalize the implementation there rather than reinventing the wheel.
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 (deleted) (history)
  • /trunk/phase3/includes/specials/SpecialAncientpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialDisambiguations.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryQuerypage.php
@@ -1,154 +0,0 @@
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 - 'ancientpages' => 'AncientPagesPage',
40 - 'brokenredirects' => 'BrokenRedirectsPage',
41 - 'deadendpages' => 'DeadendPagesPage',
42 - 'disambiguations' => 'DisambiguationsPage',
43 - );
44 -
45 - public function __construct($query, $moduleName) {
46 - parent :: __construct($query, $moduleName, 'qp');
47 - }
48 -
49 - public function execute() {
50 - $this->run();
51 - }
52 -
53 - public function executeGenerator($resultPageSet) {
54 - $this->run( $resultPageSet );
55 - }
56 -
57 - private function run($resultPageSet = null) {
58 - $params = $this->extractRequestParams();
59 - $offset = $params['offset'];
60 - $limit = $params['limit'];
61 -
62 - // Try to find an entry in $wgQueryPages
63 - $name = $params['querypage'];
64 - if ( is_null( $name ) )
65 - $this->dieUsageMsg( array( 'missingparam', 'querypage' ) );
66 - if ( !isset( self::$queryPages[$name] ) )
67 - $this->dieUsage( 'Querypage unrecognized', 'unknownquerypage' );
68 -
69 - // Get the result from the query page
70 - $class = self::$queryPages[$name];
71 - $queryPage = new $class;
72 - $result = $queryPage->reallyDoQuery( $offset, $limit + 1 );
73 -
74 - // Output the result
75 - $apiResult = $this->getResult();
76 - $resultPath = array( 'query', $this->getModuleName() );
77 - $count = 0;
78 - while ( $row = $result['dbr']->fetchObject( $result['result'] ) ) {
79 - if ( ++ $count > $limit ) {
80 - // We've reached the one extra which shows that there are additional pages to be had. Stop here...
81 - $this->setContinueEnumParameter( 'offset', $offset + $count - 1 );
82 - break;
83 - }
84 -
85 - if ( is_null( $resultPageSet ) ) {
86 - // Normal mode; let the query page make a sensible result out of it
87 - $vals = $queryPage->formatApiResult( $row );
88 - $fit = $apiResult->addValue( $resultPath, null, $vals );
89 - if( !$fit )
90 - {
91 - $this->setContinueEnumParameter( 'offset', $offset + $count );
92 - break;
93 - }
94 - } else {
95 - // Generator mode; not yet supported
96 - $resultPageSet->processDbRow( $row );
97 - }
98 - }
99 - // Set XML element to 'p'
100 - if ( is_null( $resultPageSet ) ) {
101 - $apiResult->setIndexedTagName_internal( array( 'query', $this->getModuleName()), 'p' );
102 - }
103 -
104 - // Set meta information
105 - if ( $result['cached'] ) {
106 - // Set cached date if available, else simply true
107 - $apiResult->addValue( $resultPath, 'cached',
108 - $result === true ? true : wfTimestamp( TS_ISO_8601, $result['cached'] ) );
109 - }
110 - if ( $result['disabled'] )
111 - // No further updates will be performed
112 - $apiResult->addValue( $resultPath, 'disabled', true );
113 -
114 -
115 - }
116 -
117 - public function getAllowedParams() {
118 - return array (
119 - 'offset' => 0,
120 - 'limit' => array (
121 - ApiBase :: PARAM_DFLT => 10,
122 - ApiBase :: PARAM_TYPE => 'limit',
123 - ApiBase :: PARAM_MIN => 1,
124 - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
125 - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
126 - ),
127 - 'querypage' => array(
128 - ApiBase :: PARAM_TYPE => array_keys( self::$queryPages )
129 - ),
130 - );
131 - }
132 -
133 - public function getParamDescription() {
134 - return array (
135 - 'offset' => 'The offset to start enumerating from.',
136 - 'limit' => 'How many total pages to return.',
137 - 'querypage' => 'Which querypage to use',
138 - );
139 - }
140 -
141 - public function getDescription() {
142 - return 'Query one of the builtin query pages.';
143 - }
144 -
145 - protected function getExamples() {
146 - return array (
147 - ' Query a list of broken redirects',
148 - ' api.php?action=query&list=querypage&qpquerypage=brokenredirects',
149 - );
150 - }
151 -
152 - public function getVersion() {
153 - return __CLASS__ . ': $Id:$';
154 - }
155 -}
\ No newline at end of file
Index: trunk/phase3/includes/api/ApiQuery.php
@@ -81,7 +81,6 @@
8282 'users' => 'ApiQueryUsers',
8383 'random' => 'ApiQueryRandom',
8484 'protectedtitles' => 'ApiQueryProtectedTitles',
85 - 'querypage' => 'ApiQueryQuerypage',
8685 );
8786
8887 private $mQueryMetaModules = array (
Index: trunk/phase3/includes/AutoLoader.php
@@ -302,7 +302,6 @@
303303 'ApiQueryLangLinks' => 'includes/api/ApiQueryLangLinks.php',
304304 'ApiQueryLinks' => 'includes/api/ApiQueryLinks.php',
305305 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php',
306 - 'ApiQueryQuerypage' => 'includes/api/ApiQueryQuerypage.php',
307306 'ApiQueryProtectedTitles' => 'includes/api/ApiQueryProtectedTitles.php',
308307 'ApiQueryRandom' => 'includes/api/ApiQueryRandom.php',
309308 'ApiQueryRecentChanges'=> 'includes/api/ApiQueryRecentChanges.php',
Index: trunk/phase3/includes/specials/SpecialDisambiguations.php
@@ -94,12 +94,6 @@
9595
9696 return "$from $edit $arr $to";
9797 }
98 - function formatApiResult( $row ) {
99 - $linkTo = Title::makeTitle( NS_MAIN, $row->value );
100 - $result = parent::formatApiResult( $row );
101 - $result['to'] = $linkTo->getPrefixedText();
102 - return $result;
103 - }
10498 }
10599
106100 /**
Index: trunk/phase3/includes/specials/SpecialAncientpages.php
@@ -62,10 +62,6 @@
6363 );
6464 return wfSpecialList($link, htmlspecialchars($d) );
6565 }
66 - function formatApiResult( $row ) {
67 - $result = parent::formatApiResult( $row );
68 - $result['timestamp'] = wfTimestamp( TS_ISO_8601, $row->value );
69 - }
7066 }
7167
7268 function wfSpecialAncientpages() {
Index: trunk/phase3/includes/QueryPage.php
@@ -176,11 +176,12 @@
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( $row ) {
 180+ function formatApiResult( $result ) {
181181 $title = Title::makeTitle( $row->namespace, $row->title );
182182 return array(
183 - 'ns' => intval( $title->getNamespace() ),
184 - 'title' => $title->getPrefixedText(),
 183+ 'pageid' => intval( $row->id ),
 184+ 'ns' => intval( $title->getNamespace() ),
 185+ 'title' => $title->getPrefixedText(),
185186 );
186187 }
187188
@@ -360,7 +361,7 @@
361362 * 'count' => number of results,
362363 * 'dbr' => the database used for fetching the data
363364 */
364 - public function reallyDoQuery( $offset, $limit ) {
 365+ protected function reallyDoQuery( $offset, $limit ) {
365366 $result = array( 'disabled' => false );
366367
367368 $this->offset = $offset;
Index: trunk/phase3/RELEASE-NOTES
@@ -292,7 +292,6 @@
293293 * Added snippet field to list=search output
294294 * (bug 17809) Add number of users in user groups to meta=siteinfo
295295 * (bug 18533) Add readonly reason to readonly exception
296 -* (bug 14869) Allow access to QueryPage-based special pages via API
297296
298297 === Languages updated in 1.16 ===
299298

Follow-up revisions

RevisionCommit summaryAuthorDate
r53216Revert r53147 properly; was supposed to be reverted in r53167, but I wasn't f...catrope08:44, 14 July 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r53147Refactored the querying code out of the display code, to allow a future API m...btongminh21:16, 12 July 2009
r53149(bug 14869) Allow access to QueryPage-based special pages via API...btongminh21:51, 12 July 2009
r53163* Added ancientpages, deadendpages and disambiguations to ApiQueryQuerypage...btongminh10:40, 13 July 2009

Comments

#Comment by Bryan (talk | contribs)   19:02, 13 July 2009

Was the refactoring of QueryPage in r53147 purposely unreverted?

#Comment by Catrope (talk | contribs)   08:46, 14 July 2009

Oops, done in r53216. That's what you get for committing stuff when jetlagged.

Status & tagging log