Index: trunk/extensions/BotQuery/query.php |
— | — | @@ -109,7 +109,7 @@ |
110 | 110 | "General site information", |
111 | 111 | "Example: query.php?what=info", |
112 | 112 | )), |
113 | | - 'namespaces' => array( "genMetaNamespaceInfo", true, null, array( |
| 113 | + 'namespaces' => array( "genMetaNamespaceInfo", true, null, array( |
114 | 114 | "List of localized namespace names", |
115 | 115 | "Example: query.php?what=namespaces", |
116 | 116 | )), |
— | — | @@ -117,6 +117,16 @@ |
118 | 118 | "Information about current user", |
119 | 119 | "Example: query.php?what=userinfo", |
120 | 120 | )), |
| 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 | + )), |
121 | 131 | 'dblredirects' => array( "genMetaDoubleRedirects", true, null, array( |
122 | 132 | "List of double-redirect pages", |
123 | 133 | "THIS QUERY IS CURRENTLY DISABLED DUE TO PERFORMANCE REASONS", |
— | — | @@ -174,8 +184,8 @@ |
175 | 185 | $this->db = $db; |
176 | 186 | $this->format = 'html'; // set it here because if parseFormat fails, it should still output something |
177 | 187 | $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 | + |
180 | 190 | // Neither one of these variables is referenced directly! |
181 | 191 | // Meta generators may append titles or pageids to these varibales. |
182 | 192 | // Do not modify this values directly - use the AddRaw() method |
— | — | @@ -252,24 +262,21 @@ |
253 | 263 | $this->dieUsage( "Unrecognised format '$format'", 'badformat' ); |
254 | 264 | } |
255 | 265 | } |
| 266 | + |
| 267 | + function parseMultiValue( $valueName, $defaultValue, $allowedValues ) { |
| 268 | + global $wgRequest; |
256 | 269 | |
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" ); |
262 | 276 | } |
263 | 277 | |
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; |
271 | 279 | } |
272 | 280 | |
273 | | - |
274 | 281 | // |
275 | 282 | // ************************************* GENERATORS ************************************* |
276 | 283 | // |
— | — | @@ -472,6 +479,69 @@ |
473 | 480 | $this->data['meta']['user'] = $meta; |
474 | 481 | } |
475 | 482 | |
| 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 | + |
476 | 546 | function genMetaDoubleRedirects() { |
477 | 547 | global $wgRequest, $wgUser; |
478 | 548 | |