r55332 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55331‎ | r55332 | r55333 >
Date:17:34, 19 August 2009
Author:brion
Status:ok
Tags:
Comment:
Revert r54291 "(bug 19004) Added support for tags to the API. Patch by Matthew Britton."
Per notes on code review, this doesn't handle multiple tags correctly right now.
Modified paths:
  • /trunk/extensions/LiquidThreads/schema-changes/thread_history_table.sql (modified) (history)
  • /trunk/extensions/UsabilityInitiative/images/wikiEditor/toolbar/insert-link.png (modified) (history)
  • /trunk/extensions/UsabilityInitiative/images/wikiEditor/toolbar/png24/insert-link.png (modified) (history)
  • /trunk/phase3/CREDITS (modified) (history)
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/ChangeTags.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryLogEvents.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRecentChanges.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryTags.php (deleted) (history)
  • /trunk/phase3/includes/api/ApiQueryUserContributions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialTags.php (modified) (history)

Diff [purge]

Index: trunk/phase3/CREDITS
@@ -83,7 +83,6 @@
8484 * Marcus Buck
8585 * Marooned
8686 * mati
87 -* Matthew Britton
8887 * Max Semenik
8988 * Michael De La Rue
9089 * Michael Walsh
Index: trunk/phase3/includes/ChangeTags.php
@@ -185,35 +185,4 @@
186186 $wgMemc->set( $key, $emptyTags, 300 );
187187 return $emptyTags;
188188 }
189 -
190 - /** Returns associative array of tag names and hitcounts */
191 - static function getHitCounts() {
192 -
193 - global $wgMemc;
194 - $key = wfMemcKey( 'hitcounts' );
195 -
196 - if ($hitcounts = $wgMemc->get( $key ))
197 - return $hitcounts;
198 -
199 - $dbr = wfGetDB( DB_SLAVE );
200 - $hitcounts = array();
201 -
202 - // Fetch defined tags
203 - $res = $dbr->select( 'valid_tag', 'vt_tag', array(), __METHOD__ );
204 - while( $row = $res->fetchObject() ) {
205 - $hitcounts[$row->vt_tag] = 0;
206 - }
207 -
208 - // Fetch hit counts
209 - $res = $dbr->select( 'change_tag', array('ct_tag', 'count(*) AS hitcount'), array(), __METHOD__, array('GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC') );
210 -
211 - while( $row = $res->fetchObject() ) {
212 - $hitcounts[$row->ct_tag] = $row->hitcount;
213 - }
214 -
215 - // Short-term caching
216 - $wgMemc->set( $key, $hitcounts, 300 );
217 - return $hitcounts;
218 - }
219 -
220189 }
Index: trunk/phase3/includes/api/ApiQueryTags.php
@@ -1,167 +0,0 @@
2 -<?php
3 -
4 -/*
5 - * Created on Jul 9, 2009
6 - *
7 - * API for MediaWiki 1.8+
8 - *
9 - * Copyright (C) 2009 Matthew Britton <firstname>.<lastname>@btinternet.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 enumerate change tags.
34 - *
35 - * @ingroup API
36 - */
37 -class ApiQueryTags extends ApiQueryBase {
38 -
39 - private $limit, $result;
40 - private $fld_displayname = false, $fld_description = false,
41 - $fld_hitcount = false;
42 -
43 - public function __construct($query, $moduleName) {
44 - parent :: __construct($query, $moduleName, 'tg');
45 - }
46 -
47 - public function execute() {
48 - $params = $this->extractRequestParams();
49 -
50 - $prop = array_flip($params['prop']);
51 -
52 - $this->fld_displayname = isset($prop['displayname']);
53 - $this->fld_description = isset($prop['description']);
54 - $this->fld_hitcount = isset($prop['hitcount']);
55 -
56 - $this->limit = $params['limit'];
57 - $this->result = $this->getResult();
58 -
59 - $pageSet = $this->getPageSet();
60 - $titles = $pageSet->getTitles();
61 - $data = array();
62 - $ok = true;
63 -
64 - if($this->fld_hitcount) {
65 - foreach( ChangeTags::getHitCounts() as $tag => $count ) {
66 - if(!$ok) break;
67 - $ok = $this->doTag( $tag, $count );
68 - }
69 - } else {
70 - foreach( ChangeTags::listDefinedTags() as $tag ) {
71 - if(!$ok) break;
72 - $ok = $this->doTag( $tag, 0 );
73 - }
74 - }
75 -
76 - $this->result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'tag');
77 - }
78 -
79 - private function doTag( $tagName, $hitcount ) {
80 - static $count = 0;
81 - static $doneTags = array();
82 -
83 - if ( in_array( $tagName, $doneTags ) ) {
84 - return true;
85 - }
86 -
87 - if(++$count > $this->limit)
88 - {
89 - $this->setContinueEnumParameter('continue', $tagName);
90 - return false;
91 - }
92 -
93 - $tag = array();
94 - $tag['name'] = $tagName;
95 -
96 - if($this->fld_displayname)
97 - $tag['displayname'] = ChangeTags::tagDescription( $tagName );
98 -
99 - if($this->fld_description)
100 - {
101 - $msg = wfMsg( "tag-$tagName-description" );
102 - $msg = wfEmptyMsg( "tag-$tagName-description", $msg ) ? '' : $msg;
103 - $tag['description'] = $msg;
104 - }
105 -
106 - if($this->fld_hitcount)
107 - $tag['hitcount'] = $hitcount;
108 -
109 - $doneTags[] = $tagName;
110 -
111 - $fit = $this->result->addValue(array('query', $this->getModuleName()), null, $tag);
112 - if(!$fit)
113 - {
114 - $this->setContinueEnumParameter('continue', $tagName);
115 - return false;
116 - }
117 -
118 - return true;
119 - }
120 -
121 - public function getAllowedParams() {
122 - return array (
123 - 'continue' => array(
124 - ),
125 - 'end' => array(
126 - ),
127 - 'limit' => array(
128 - ApiBase :: PARAM_DFLT => 10,
129 - ApiBase :: PARAM_TYPE => 'limit',
130 - ApiBase :: PARAM_MIN => 1,
131 - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
132 - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
133 - ),
134 - 'prop' => array(
135 - ApiBase :: PARAM_DFLT => 'name',
136 - ApiBase :: PARAM_TYPE => array(
137 - 'name',
138 - 'displayname',
139 - 'description',
140 - 'hitcount'
141 - ),
142 - ApiBase :: PARAM_ISMULTI => true
143 - )
144 - );
145 - }
146 -
147 - public function getParamDescription() {
148 - return array (
149 - 'continue' => 'When more results are available, use this to continue',
150 - 'limit' => 'The maximum number of tags to list',
151 - 'prop' => 'Which properties to get',
152 - );
153 - }
154 -
155 - public function getDescription() {
156 - return 'List change tags.';
157 - }
158 -
159 - protected function getExamples() {
160 - return array (
161 - 'api.php?action=query&list=tags&tgprop=displayname|description|hitcount'
162 - );
163 - }
164 -
165 - public function getVersion() {
166 - return __CLASS__ . ': $Id$';
167 - }
168 -}
Index: trunk/phase3/includes/api/ApiQueryRecentChanges.php
@@ -42,7 +42,7 @@
4343
4444 private $fld_comment = false, $fld_user = false, $fld_flags = false,
4545 $fld_timestamp = false, $fld_title = false, $fld_ids = false,
46 - $fld_sizes = false, $fld_tags = false;
 46+ $fld_sizes = false;
4747 /**
4848 * Get an array mapping token names to their handler functions.
4949 * The prototype for a token function is func($pageid, $title, $rc)
@@ -174,7 +174,6 @@
175175 $this->fld_redirect = isset($prop['redirect']);
176176 $this->fld_patrolled = isset($prop['patrolled']);
177177 $this->fld_loginfo = isset($prop['loginfo']);
178 - $this->fld_tags = isset($prop['tags']);
179178
180179 global $wgUser;
181180 if($this->fld_patrolled && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol())
@@ -204,17 +203,6 @@
205204 $this->addFields('page_is_redirect');
206205 }
207206 }
208 -
209 - if($this->fld_tags || !is_null($params['tag'])) {
210 - $this->addTables('tag_summary');
211 - $this->addJoinConds(array('tag_summary' => array('LEFT JOIN', array('rc_id=ts_rc_id'))));
212 - $this->addFields('ts_tags');
213 - }
214 -
215 - if(!is_null($params['tag'])) {
216 - $this->addWhereFld('ts_tags' , $params['tag']);
217 - }
218 -
219207 $this->token = $params['token'];
220208 $this->addOption('LIMIT', $params['limit'] +1);
221209 $this->addOption('USE INDEX', array('recentchanges' => $index));
@@ -347,10 +335,6 @@
348336 $row->rc_log_type, $row->rc_timestamp);
349337 }
350338
351 - if ($this->fld_tags && isset($row->ts_tags)) {
352 - $vals['tags'] = $row->ts_tags;
353 - }
354 -
355339 if(!is_null($this->token))
356340 {
357341 $tokenFunctions = $this->getTokenFunctions();
@@ -424,7 +408,6 @@
425409 'redirect',
426410 'patrolled',
427411 'loginfo',
428 - 'tags',
429412 )
430413 ),
431414 'token' => array(
@@ -460,8 +443,7 @@
461444 'new',
462445 'log'
463446 )
464 - ),
465 - 'tag' => null,
 447+ )
466448 );
467449 }
468450
@@ -480,7 +462,6 @@
481463 'For example, to see only minor edits done by logged-in users, set show=minor|!anon'
482464 ),
483465 'type' => 'Which types of changes to show.',
484 - 'tag' => 'Only list changes with this tag',
485466 'limit' => 'How many total changes to return.'
486467 );
487468 }
Index: trunk/phase3/includes/api/ApiQueryLogEvents.php
@@ -51,7 +51,6 @@
5252 $this->fld_timestamp = in_array('timestamp', $prop);
5353 $this->fld_comment = in_array('comment', $prop);
5454 $this->fld_details = in_array('details', $prop);
55 - $this->fld_tags = in_array('tags', $prop);
5655
5756 list($tbl_logging, $tbl_page, $tbl_user) = $db->tableNamesN('logging', 'page', 'user');
5857
@@ -86,16 +85,6 @@
8786 $this->addFieldsIf('log_comment', $this->fld_comment);
8887 $this->addFieldsIf('log_params', $this->fld_details);
8988
90 - if($this->fld_tags || !is_null($params['tag'])) {
91 - $this->addTables('tag_summary');
92 - $this->addJoinConds(array('tag_summary' => array('LEFT JOIN', 'log_id=ts_log_id')));
93 - $this->addFields('ts_tags');
94 - }
95 -
96 - if( !is_null($params['tag']) ) {
97 - $this->addWhereFld('ts_tags', $params['tag']);
98 - }
99 -
10089 if( !is_null($params['type']) ) {
10190 $this->addWhereFld('log_type', $params['type']);
10291 $index = 'type_time';
@@ -258,10 +247,6 @@
259248 }
260249 }
261250
262 - if ($this->fld_tags && isset($row->ts_tags)) {
263 - $vals['tags'] = $row->ts_tags;
264 - }
265 -
266251 return $vals;
267252 }
268253
@@ -280,7 +265,6 @@
281266 'timestamp',
282267 'comment',
283268 'details',
284 - 'tags'
285269 )
286270 ),
287271 'type' => array (
@@ -301,7 +285,6 @@
302286 ),
303287 'user' => null,
304288 'title' => null,
305 - 'tag' => null,
306289 'limit' => array (
307290 ApiBase :: PARAM_DFLT => 10,
308291 ApiBase :: PARAM_TYPE => 'limit',
@@ -321,7 +304,6 @@
322305 'dir' => 'In which direction to enumerate.',
323306 'user' => 'Filter entries to those made by the given user.',
324307 'title' => 'Filter entries to those related to a page.',
325 - 'tag' => 'Only list entries with this tag',
326308 'limit' => 'How many total event entries to return.'
327309 );
328310 }
Index: trunk/phase3/includes/api/ApiQuery.php
@@ -74,7 +74,6 @@
7575 'logevents' => 'ApiQueryLogEvents',
7676 'recentchanges' => 'ApiQueryRecentChanges',
7777 'search' => 'ApiQuerySearch',
78 - 'tags' => 'ApiQueryTags',
7978 'usercontribs' => 'ApiQueryContributions',
8079 'watchlist' => 'ApiQueryWatchlist',
8180 'watchlistraw' => 'ApiQueryWatchlistRaw',
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -42,7 +42,7 @@
4343 }
4444
4545 private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false,
46 - $fld_comment = false, $fld_user = false, $fld_content = false, $fld_tags = false;
 46+ $fld_comment = false, $fld_user = false, $fld_content = false;
4747
4848 protected function getTokenFunctions() {
4949 // tokenname => function
@@ -121,8 +121,9 @@
122122 }
123123
124124 $db = $this->getDB();
125 - $this->addTables(array('page', 'revision'));
 125+ $this->addTables('revision');
126126 $this->addFields(Revision::selectFields());
 127+ $this->addTables('page');
127128 $this->addWhere('page_id = rev_page');
128129
129130 $prop = array_flip($params['prop']);
@@ -134,7 +135,6 @@
135136 $this->fld_timestamp = isset ($prop['timestamp']);
136137 $this->fld_comment = isset ($prop['comment']);
137138 $this->fld_size = isset ($prop['size']);
138 - $this->fld_tags = isset ($prop['tags']);
139139 $this->fld_user = isset ($prop['user']);
140140 $this->token = $params['token'];
141141 $this->diffto = $params['diffto'];
@@ -143,16 +143,6 @@
144144 $this->addFields( Revision::selectPageFields() );
145145 }
146146
147 - if ($this->fld_tags || !is_null($params['tag'])) {
148 - $this->addTables('tag_summary');
149 - $this->addJoinConds(array('tag_summary' => array('LEFT JOIN', array('rev_id=ts_rev_id'))));
150 - $this->addFields('ts_tags');
151 - }
152 -
153 - if( !is_null($params['tag']) ) {
154 - $this->addWhereFld('ts_tags', $params['tag']);
155 - }
156 -
157147 if (isset ($prop['content'])) {
158148
159149 // For each page we will request, the user must have read rights for that page
@@ -303,9 +293,9 @@
304294 $this->setContinueEnumParameter('startid', intval($row->rev_id));
305295 break;
306296 }
307 -
 297+ $revision = new Revision( $row );
308298 //
309 - $fit = $this->addPageSubItem($row->rev_page, $this->extractRowInfo($row), 'rev');
 299+ $fit = $this->addPageSubItem($revision->getPage(), $this->extractRowInfo($revision), 'rev');
310300 if(!$fit)
311301 {
312302 if($enumRevMode)
@@ -321,8 +311,7 @@
322312 $db->freeResult($res);
323313 }
324314
325 - private function extractRowInfo( $row ) {
326 - $revision = new Revision( $row );
 315+ private function extractRowInfo( $revision ) {
327316 $title = $revision->getTitle();
328317 $vals = array ();
329318
@@ -364,9 +353,6 @@
365354 }
366355 }
367356
368 - if ($this->fld_tags && $row->ts_tags)
369 - $vals['tags'] = $row->ts_tags;
370 -
371357 if(!is_null($this->token))
372358 {
373359 $tokenFunctions = $this->getTokenFunctions();
@@ -441,7 +427,6 @@
442428 'size',
443429 'comment',
444430 'content',
445 - 'tags'
446431 )
447432 ),
448433 'limit' => array (
@@ -475,7 +460,6 @@
476461 'excludeuser' => array(
477462 ApiBase :: PARAM_TYPE => 'user'
478463 ),
479 - 'tag' => null,
480464 'expandtemplates' => false,
481465 'generatexml' => false,
482466 'section' => null,
@@ -499,7 +483,6 @@
500484 'dir' => 'direction of enumeration - towards "newer" or "older" revisions (enum)',
501485 'user' => 'only include revisions made by user',
502486 'excludeuser' => 'exclude revisions made by user',
503 - 'tag' => 'only list revisions with this tag',
504487 'expandtemplates' => 'expand templates in revision content',
505488 'generatexml' => 'generate XML parse tree for revision content',
506489 'section' => 'only retrieve the content of this section',
Index: trunk/phase3/includes/api/ApiQueryUserContributions.php
@@ -42,7 +42,7 @@
4343 private $params, $username;
4444 private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
4545 $fld_comment = false, $fld_flags = false,
46 - $fld_patrolled = false, $fld_tags = false;
 46+ $fld_patrolled = false;
4747
4848 public function execute() {
4949
@@ -57,7 +57,6 @@
5858 $this->fld_flags = isset($prop['flags']);
5959 $this->fld_timestamp = isset($prop['timestamp']);
6060 $this->fld_patrolled = isset($prop['patrolled']);
61 - $this->fld_tags = isset($prop['tags']);
6261
6362 // TODO: if the query is going only against the revision table, should this be done?
6463 $this->selectNamedDB('contributions', DB_SLAVE, 'contributions');
@@ -142,7 +141,7 @@
143142 private function prepareQuery() {
144143 // We're after the revision table, and the corresponding page
145144 // row for anything we retrieve. We may also need the
146 - // recentchanges row and/or tag summary row.
 145+ // recentchanges row.
147146 global $wgUser;
148147 $tables = array('page', 'revision'); // Order may change
149148 $this->addWhere('page_id=rev_page');
@@ -246,16 +245,6 @@
247246 $this->addFieldsIf('rev_minor_edit', $this->fld_flags);
248247 $this->addFieldsIf('rev_parent_id', $this->fld_flags);
249248 $this->addFieldsIf('rc_patrolled', $this->fld_patrolled);
250 -
251 - if($this->fld_tags || !is_null($this->params['tag'])) {
252 - $this->addTables('tag_summary');
253 - $this->addJoinConds(array('tag_summary' => array('LEFT JOIN', array('rev_id=ts_rev_id'))));
254 - $this->addFields('ts_tags');
255 - }
256 -
257 - if( !is_null($this->params['tag']) ) {
258 - $this->addWhereFld('ts_tags', $this->params['tag']);
259 - }
260249 }
261250
262251 /**
@@ -303,9 +292,6 @@
304293 if ($this->fld_size && !is_null($row->rev_len))
305294 $vals['size'] = intval($row->rev_len);
306295
307 - if ($this->fld_tags && $row->ts_tags)
308 - $vals['tags'] = $row->ts_tags;
309 -
310296 return $vals;
311297 }
312298
@@ -357,7 +343,6 @@
358344 'size',
359345 'flags',
360346 'patrolled',
361 - 'tags',
362347 )
363348 ),
364349 'show' => array (
@@ -369,7 +354,6 @@
370355 '!patrolled',
371356 )
372357 ),
373 - 'tag' => null,
374358 );
375359 }
376360
@@ -386,7 +370,6 @@
387371 'prop' => 'Include additional pieces of information',
388372 'show' => array('Show only items that meet this criteria, e.g. non minor edits only: show=!minor',
389373 'NOTE: if show=patrolled or show=!patrolled is set, revisions older than $wgRCMaxAge won\'t be shown',),
390 - 'tag' => 'Only list contributions with this tag',
391374 );
392375 }
393376
Index: trunk/phase3/includes/AutoLoader.php
@@ -307,7 +307,6 @@
308308 'ApiQueryRevisions' => 'includes/api/ApiQueryRevisions.php',
309309 'ApiQuerySearch' => 'includes/api/ApiQuerySearch.php',
310310 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php',
311 - 'ApiQueryTags' => 'includes/api/ApiQueryTags.php',
312311 'ApiQueryUserInfo' => 'includes/api/ApiQueryUserInfo.php',
313312 'ApiQueryUsers' => 'includes/api/ApiQueryUsers.php',
314313 'ApiQueryWatchlist' => 'includes/api/ApiQueryWatchlist.php',
Index: trunk/phase3/includes/specials/SpecialTags.php
@@ -25,11 +25,17 @@
2626 Xml::tags( 'th', null, wfMsgExt( 'tags-description-header', 'parseinline' ) ) .
2727 Xml::tags( 'th', null, wfMsgExt( 'tags-hitcount-header', 'parseinline' ) )
2828 );
 29+ $dbr = wfGetDB( DB_SLAVE );
 30+ $res = $dbr->select( 'change_tag', array( 'ct_tag', 'count(*) as hitcount' ), array(), __METHOD__, array( 'GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC' ) );
2931
30 - foreach( ChangeTags::getHitCounts() as $tag => $hitcount ) {
31 - $html .= $this->doTagRow( $tag, $hitcount );
 32+ while ( $row = $res->fetchObject() ) {
 33+ $html .= $this->doTagRow( $row->ct_tag, $row->hitcount );
3234 }
3335
 36+ foreach( ChangeTags::listDefinedTags() as $tag ) {
 37+ $html .= $this->doTagRow( $tag, 0 );
 38+ }
 39+
3440 $wgOut->addHTML( Xml::tags( 'table', array( 'class' => 'wikitable mw-tags-table' ), $html ) );
3541 }
3642
Index: trunk/phase3/RELEASE-NOTES
@@ -465,7 +465,6 @@
466466 * (bug 19907) $wgCrossSiteAJAXdomains added to allow specified (or all)
467467 external domains to access api.php via AJAX, if the browser supports the
468468 Access-Control-Allow-Origin HTTP header
469 -* (bug 19004) Added support for tags to the API.
470469
471470 === Languages updated in 1.16 ===
472471
Property changes on: trunk/extensions/UsabilityInitiative/images/wikiEditor/toolbar/insert-link.png
___________________________________________________________________
Deleted: svn:mergeinfo
Property changes on: trunk/extensions/UsabilityInitiative/images/wikiEditor/toolbar/png24/insert-link.png
___________________________________________________________________
Deleted: svn:mergeinfo
Property changes on: trunk/extensions/LiquidThreads/schema-changes/thread_history_table.sql
___________________________________________________________________
Deleted: svn:mergeinfo

Follow-up revisions

RevisionCommit summaryAuthorDate
r58399API: (bug 19004) Add support for tags. Patch by Matthew Brittoncatrope10:42, 1 November 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r54291(bug 19004) Added support for tags to the API. Patch by Matthew Britton.btongminh17:48, 3 August 2009

Status & tagging log