jenkins-bot has submitted this change and it was merged.

Change subject: (bug 40658) Support query continue in CheckUserLog API
......................................................................


(bug 40658) Support query continue in CheckUserLog API

Adds support for query continue to CheckUserLog API, and as a result,
also fixes the incorrect limit issue.

Adds support for a direction option and corrects limit parameter in
the example URL as well.

Change-Id: I2fa2cae10831c2da21002232a812e9c7721a4c0f
---
M api/ApiQueryCheckUserLog.php
1 file changed, 62 insertions(+), 14 deletions(-)

Approvals:
  Yurik: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/api/ApiQueryCheckUserLog.php b/api/ApiQueryCheckUserLog.php
index 7f117f3..84e5c7d 100644
--- a/api/ApiQueryCheckUserLog.php
+++ b/api/ApiQueryCheckUserLog.php
@@ -15,38 +15,73 @@
                        $this->dieUsage( 'You need the checkuser-log right', 
'permissionerror' );
                }
 
-               list( $user, $limit, $target, $from, $to ) = array( 
$params['user'], $params['limit'],
-                       $params['target'], $params['from'], $params['to'] );
+               $limit = $params['limit'];
+               $continue = $params['continue'];
+               $dir = $params['dir'];
 
                $this->addTables( 'cu_log' );
                $this->addOption( 'LIMIT', $limit + 1 );
-               $this->addTimestampWhereRange( 'cul_timestamp', 'older', $from, 
$to );
-               $this->addFields( array( 
-                       'cul_timestamp', 'cul_user_text', 'cul_reason', 
'cul_type', 'cul_target_text' ) );
+               $this->addTimestampWhereRange( 'cul_timestamp', $dir, 
$params['from'], $params['to'] );
+               $this->addFields( array(
+                       'cul_id', 'cul_timestamp', 'cul_user_text', 
'cul_reason', 'cul_type', 'cul_target_text' ) );
 
-               if ( isset( $user ) ) {
-                       $this->addWhereFld( 'cul_user_text', $user );
+               // Order by both timestamp and id
+               $order = ( $dir === 'newer' ? '' : ' DESC' );
+               $this->addOption( 'ORDER BY', array( 'cul_timestamp' . $order, 
'cul_id' . $order ) );
+
+               if ( isset( $params['user'] ) ) {
+                       $this->addWhereFld( 'cul_user_text', $params['user'] );
                }
-               if ( isset( $target ) ) {
-                       $this->addWhereFld( 'cul_target_text', $target );
+               if ( isset( $params['target'] ) ) {
+                       $this->addWhereFld( 'cul_target_text', 
$params['target'] );
+               }
+
+               if ( $continue !== null ) {
+                       $cont = explode( '|', $continue );
+                       $op = $dir === 'older' ? '<' : '>';
+                       if ( count( $cont ) !== 2 || wfTimestamp( TS_UNIX, 
$cont[0] ) === false ) {
+                               $this->dieUsage( 'Invalid continue param. You 
should pass the ' .
+                                                               'original value 
returned by the previous query', '_badcontinue' );
+                       }
+
+                       $db = $this->getDB();
+                       $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) 
);
+                       $id = intval( $cont[1] );
+
+                       $this->addWhere(
+                               "cul_timestamp $op $timestamp OR " .
+                               "(cul_timestamp = $timestamp AND " .
+                               "cul_id $op= $id)"
+                       );
                }
 
                $res = $this->select( __METHOD__ );
                $result = $this->getResult();
 
-               $log = array();
+               $count = 0;
+               $makeContinue = function ( $row ) {
+                       return wfTimestamp( TS_ISO_8601, $row->cul_timestamp ) 
. '|' . $row->cul_id;
+               };
                foreach ( $res as $row ) {
-                       $log[] = array(
+                       if ( ++$count > $limit ) {
+                               $this->setContinueEnumParameter( 'continue', 
$makeContinue( $row ) );
+                               break;
+                       }
+                       $log = array(
                                'timestamp' => wfTimestamp( TS_ISO_8601, 
$row->cul_timestamp ),
                                'checkuser' => $row->cul_user_text,
                                'type'      => $row->cul_type,
                                'reason'    => $row->cul_reason,
                                'target'    => $row->cul_target_text,
                        );
+                       $fit = $result->addValue( array( 'query', 
$this->getModuleName(), 'entries' ), null, $log );
+                       if ( !$fit ) {
+                               $this->setContinueEnumParameter( 'continue', 
$makeContinue( $row ) );
+                               break;
+                       }
                }
 
-               $result->addValue( array( 'query', $this->getModuleName() ), 
'entries', $log );
-               $result->setIndexedTagName_internal( 
+               $result->setIndexedTagName_internal(
                        array( 'query', $this->getModuleName(), 'entries' ), 
'entry' );
        }
 
@@ -61,22 +96,35 @@
                                ApiBase::PARAM_MAX  => ApiBase::LIMIT_BIG1,
                                ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2,
                        ),
+                       'dir' => array(
+                               ApiBase::PARAM_DFLT => 'older',
+                               ApiBase::PARAM_TYPE => array(
+                                       'newer',
+                                       'older'
+                               )
+                       ),
                        'from'  => array(
                                ApiBase::PARAM_TYPE => 'timestamp',
                        ),
                        'to'    => array(
                                ApiBase::PARAM_TYPE => 'timestamp',
                        ),
+                       'continue' => null,
                );
        }
 
        public function getParamDescription() {
+               $p = $this->getModulePrefix();
                return array(
                        'user'   => 'Username of CheckUser',
                        'target' => "Checked user or IP-address/range",
                        'limit'  => 'Limit of rows',
+                       'dir' => array( "In which direction to enumerate}",
+                               " newer          - List oldest first. Note: 
{$p}from has to be before {$p}to.",
+                               " older          - List newest first (default). 
Note: {$p}from has to be later than {$p}to." ),
                        'from'   => 'The timestamp to start enumerating from',
                        'to'     => 'The timestamp to end enumerating',
+                       'continue' => 'When more results are available, use 
this to continue',
                );
        }
 
@@ -94,7 +142,7 @@
 
        public function getExamples() {
                return array(
-                       
'api.php?action=query&list=checkuserlog&culuser=WikiSysop&limit=25',
+                       
'api.php?action=query&list=checkuserlog&culuser=WikiSysop&cullimit=25',
                        
'api.php?action=query&list=checkuserlog&cultarget=127.0.0.1&culfrom=20111015230000',
                );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/33702
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2fa2cae10831c2da21002232a812e9c7721a4c0f
Gerrit-PatchSet: 15
Gerrit-Project: mediawiki/extensions/CheckUser
Gerrit-Branch: master
Gerrit-Owner: Grunny <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Grunny <[email protected]>
Gerrit-Reviewer: Huji <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Yurik <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to