Merge "Consistency tweaks"
[lhc/web/wiklou.git] / includes / api / ApiQueryWatchlist.php
index 6baa87d..869faea 100644 (file)
@@ -51,7 +51,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                $fld_loginfo = false;
 
        /**
-        * @param $resultPageSet ApiPageSet
+        * @param ApiPageSet $resultPageSet
         * @return void
         */
        private function run( $resultPageSet = null ) {
@@ -86,6 +86,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                }
 
                $this->addFields( array(
+                       'rc_id',
                        'rc_namespace',
                        'rc_title',
                        'rc_timestamp',
@@ -135,6 +136,22 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
 
                $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'],
                        $params['start'], $params['end'] );
+               // Include in ORDER BY for uniqueness
+               $this->addWhereRange( 'rc_id', $params['dir'], null, null );
+
+               if ( !is_null( $params['continue'] ) ) {
+                       $cont = explode( '|', $params['continue'] );
+                       $this->dieContinueUsageIf( count( $cont ) != 2 );
+                       $op = ( $params['dir'] === 'newer' ? '>' : '<' );
+                       $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
+                       $continueId = (int)$cont[1];
+                       $this->dieContinueUsageIf( $continueId != $cont[1] );
+                       $this->addWhere( "rc_timestamp $op $continueTimestamp OR " .
+                               "(rc_timestamp = $continueTimestamp AND " .
+                               "rc_id $op= $continueId)"
+                       );
+               }
+
                $this->addWhereFld( 'wl_namespace', $params['namespace'] );
 
                if ( !$params['allrev'] ) {
@@ -236,10 +253,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                        if ( ++$count > $params['limit'] ) {
                                // We've reached the one extra which shows that there are
                                // additional pages to be had. Stop here...
-                               $this->setContinueEnumParameter(
-                                       'start',
-                                       wfTimestamp( TS_ISO_8601, $row->rc_timestamp )
-                               );
+                               $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
                                break;
                        }
 
@@ -247,8 +261,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                                $vals = $this->extractRowInfo( $row );
                                $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
                                if ( !$fit ) {
-                                       $this->setContinueEnumParameter( 'start',
-                                               wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) );
+                                       $this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
                                        break;
                                }
                        } else {
@@ -544,6 +557,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                        'token' => array(
                                ApiBase::PARAM_TYPE => 'string'
                        ),
+                       'continue' => null,
                );
        }
 
@@ -588,6 +602,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                        'owner' => 'The name of the user whose watchlist you\'d like to access',
                        'token' => 'Give a security token (settable in preferences) to ' .
                                'allow access to another user\'s watchlist',
+                       'continue' => 'When more results are available, use this to continue',
                );
        }