r13835 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r13834‎ | r13835 | r13836 >
Date:06:06, 24 April 2006
Author:yurik
Status:old
Tags:
Comment:
* basic "recent changes" support
Modified paths:
  • /trunk/extensions/BotQuery/query.php (modified) (history)

Diff [purge]

Index: trunk/extensions/BotQuery/query.php
@@ -109,7 +109,7 @@
110110 "General site information",
111111 "Example: query.php?what=info",
112112 )),
113 - 'namespaces' => array( "genMetaNamespaceInfo", true, null, array(
 113+ 'namespaces' => array( "genMetaNamespaceInfo", true, null, array(
114114 "List of localized namespace names",
115115 "Example: query.php?what=namespaces",
116116 )),
@@ -117,6 +117,16 @@
118118 "Information about current user",
119119 "Example: query.php?what=userinfo",
120120 )),
 121+ 'recentchanges' => array( "genMetaRecentChanges", true, array( 'rcfrom','rclimit','rchide' ), array(
 122+ "Adds recently changed articles to the output list.",
 123+ "Parameters supported:",
 124+ "rcfrom - Timestamp of the first entry to start from. The list order reverses.",
 125+ "rclimit - how many total links to return.",
 126+ " Smaller size is possible if pages changes multiple times.",
 127+ "rchide - Which entries to ignore 'minor','bots','anons','liu' (loged-in users).",
 128+ " Cannot specify both anons and liu.",
 129+ "Example: query.php?what=recentchanges&rchide=liu|bots",
 130+ )),
121131 'dblredirects' => array( "genMetaDoubleRedirects", true, null, array(
122132 "List of double-redirect pages",
123133 "THIS QUERY IS CURRENTLY DISABLED DUE TO PERFORMANCE REASONS",
@@ -174,8 +184,8 @@
175185 $this->db = $db;
176186 $this->format = 'html'; // set it here because if parseFormat fails, it should still output something
177187 $this->format = $this->parseFormat( $wgRequest->getVal('format', 'html') );
178 - $this->properties = $this->parseProperties( $wgRequest->getVal('what'));
179 -
 188+ $this->properties = $this->parseMultiValue( 'what', null, array_keys( $this->propGenerators ) );
 189+
180190 // Neither one of these variables is referenced directly!
181191 // Meta generators may append titles or pageids to these varibales.
182192 // Do not modify this values directly - use the AddRaw() method
@@ -252,24 +262,21 @@
253263 $this->dieUsage( "Unrecognised format '$format'", 'badformat' );
254264 }
255265 }
 266+
 267+ function parseMultiValue( $valueName, $defaultValue, $allowedValues ) {
 268+ global $wgRequest;
256269
257 - function parseProperties( $properties ) {
258 - global $wgUser;
259 -
260 - if ( $properties == '' ) {
261 - $this->dieUsage( 'No properties given', 'noproperties' );
 270+ $values = $wgRequest->getVal($valueName, $defaultValue);
 271+ $valuesList = explode( '|', $values );
 272+ $unknownValues = array_diff( $valuesList, $allowedValues);
 273+ if( $unknownValues ) {
 274+ $this->dieUsage("Unrecognised value" . (count($unknownValues)>1?"s '":" '") . implode("', '", $unknownValues) . "' for parameter '$valueName'",
 275+ "unknown_$valueName" );
262276 }
263277
264 - $propList = explode( '|', $properties );
265 - $unknownProperties = array_diff( $propList, array_keys( $this->propGenerators ));
266 - if( $unknownProperties ) {
267 - $this->dieUsage( "Unrecognised propert" . (count($unknownProperties)>1?"ies ":"y ") . implode(', ', $unknownProperties), 'unknownproperty' );
268 - }
269 -
270 - return $propList;
 278+ return $valuesList;
271279 }
272280
273 -
274281 //
275282 // ************************************* GENERATORS *************************************
276283 //
@@ -472,6 +479,69 @@
473480 $this->data['meta']['user'] = $meta;
474481 }
475482
 483+ function genMetaRecentChanges() {
 484+ global $wgRequest;
 485+
 486+ # Get last modified date, for client caching
 487+ $from = $wgRequest->getVal( 'rcfrom' );
 488+ $limit = $wgRequest->getInt( 'rclimit', 20 );
 489+ $hide = $this->parseMultiValue( 'rchide', '', array('','minor','bots','anons','liu') );
 490+
 491+ # It makes no sense to hide both anons and logged-in users
 492+ # Where this occurs, force anons to be shown
 493+ if( in_array('anons', $hide) && in_array('liu', $hide) ) {
 494+ $this->dieUsage( "Both 'anons' and 'liu' cannot be given for 'rchide' parameter", 'rc_badrchide' );
 495+ }
 496+
 497+ $conds = array();
 498+
 499+ if ( $from != '' ) {
 500+ $conds[] = 'rev_timestamp >= ' . $this->prepareTimestamp($from);
 501+ }
 502+
 503+ if ( $limit < 1 || $limit > 5000 ) {
 504+ $this->dieUsage( "Invalid rclimit value '$limit' - must be between 1 and 5000", 'rc_badrclimit' );
 505+ }
 506+
 507+ foreach( $hide as &$elem ) {
 508+ switch( $elem ) {
 509+ case '': // nothing
 510+ break;
 511+ case 'minor':
 512+ $conds[] = 'rc_minor = 0';
 513+ break;
 514+ case 'bots':
 515+ $conds[] = 'rc_bot = 0';
 516+ break;
 517+ case 'anons':
 518+ $conds[] = 'rc_user != 0';
 519+ break;
 520+ case 'liu':
 521+ $conds[] = 'rc_user = 0';
 522+ break;
 523+ default:
 524+ die( "Internal error - Unknown hide param '$elem'" );
 525+ }
 526+ }
 527+
 528+ $options = array( 'USE INDEX' => 'rc_timestamp', 'LIMIT' => $limit );
 529+ $options['ORDER BY'] = 'rc_timestamp' . ( $from != '' ? '' : ' DESC' );
 530+
 531+ $res = $this->db->select(
 532+ 'recentchanges',
 533+ 'rc_cur_id',
 534+ $conds,
 535+ $this->classname . '::genMetaRecentChanges',
 536+ $options
 537+ );
 538+ while ( $row = $this->db->fetchObject( $res ) ) {
 539+ if( $row->rc_cur_id != 0 ) {
 540+ $this->addRaw( 'pageids', $row->rc_cur_id );
 541+ }
 542+ }
 543+ $this->db->freeResult( $res );
 544+ }
 545+
476546 function genMetaDoubleRedirects() {
477547 global $wgRequest, $wgUser;
478548

Status & tagging log