Merge "Separate select() parameter summary from detail"
[lhc/web/wiklou.git] / includes / api / ApiSetNotificationTimestamp.php
index 70e36d2..04be450 100644 (file)
@@ -46,6 +46,8 @@ class ApiSetNotificationTimestamp extends ApiBase {
                $params = $this->extractRequestParams();
                $this->requireMaxOneParameter( $params, 'timestamp', 'torevid', 'newerthanrevid' );
 
+               $this->getResult()->beginContinuation( $params['continue'], array(), array() );
+
                $pageSet = $this->getPageSet();
                if ( $params['entirewatchlist'] && $pageSet->getDataSource() !== null ) {
                        $this->dieUsage(
@@ -70,22 +72,26 @@ class ApiSetNotificationTimestamp extends ApiBase {
                                $this->dieUsage( 'torevid may only be used with a single page', 'multpages' );
                        }
                        $title = reset( $pageSet->getGoodTitles() );
-                       $timestamp = Revision::getTimestampFromId( $title, $params['torevid'] );
-                       if ( $timestamp ) {
-                               $timestamp = $dbw->timestamp( $timestamp );
-                       } else {
-                               $timestamp = null;
+                       if ( $title ) {
+                               $timestamp = Revision::getTimestampFromId( $title, $params['torevid'] );
+                               if ( $timestamp ) {
+                                       $timestamp = $dbw->timestamp( $timestamp );
+                               } else {
+                                       $timestamp = null;
+                               }
                        }
                } elseif ( isset( $params['newerthanrevid'] ) ) {
                        if ( $params['entirewatchlist'] || $pageSet->getGoodTitleCount() > 1 ) {
                                $this->dieUsage( 'newerthanrevid may only be used with a single page', 'multpages' );
                        }
                        $title = reset( $pageSet->getGoodTitles() );
-                       $revid = $title->getNextRevisionID( $params['newerthanrevid'] );
-                       if ( $revid ) {
-                               $timestamp = $dbw->timestamp( Revision::getTimestampFromId( $title, $revid ) );
-                       } else {
-                               $timestamp = null;
+                       if ( $title ) {
+                               $revid = $title->getNextRevisionID( $params['newerthanrevid'] );
+                               if ( $revid ) {
+                                       $timestamp = $dbw->timestamp( Revision::getTimestampFromId( $title, $revid ) );
+                               } else {
+                                       $timestamp = null;
+                               }
                        }
                }
 
@@ -124,51 +130,55 @@ class ApiSetNotificationTimestamp extends ApiBase {
                                $result[] = $rev;
                        }
 
-                       // Now process the valid titles
-                       $lb = new LinkBatch( $pageSet->getTitles() );
-                       $dbw->update( 'watchlist', array( 'wl_notificationtimestamp' => $timestamp ),
-                               array( 'wl_user' => $user->getID(), $lb->constructSet( 'wl', $dbw ) ),
-                               __METHOD__
-                       );
-
-                       // Query the results of our update
-                       $timestamps = array();
-                       $res = $dbw->select(
-                               'watchlist',
-                               array( 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ),
-                               array( 'wl_user' => $user->getID(), $lb->constructSet( 'wl', $dbw ) ),
-                               __METHOD__
-                       );
-                       foreach ( $res as $row ) {
-                               $timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp;
-                       }
+                       if ( $pageSet->getTitles() ) {
+                               // Now process the valid titles
+                               $lb = new LinkBatch( $pageSet->getTitles() );
+                               $dbw->update( 'watchlist', array( 'wl_notificationtimestamp' => $timestamp ),
+                                       array( 'wl_user' => $user->getID(), $lb->constructSet( 'wl', $dbw ) ),
+                                       __METHOD__
+                               );
 
-                       // Now, put the valid titles into the result
-                       /** @var $title Title */
-                       foreach ( $pageSet->getTitles() as $title ) {
-                               $ns = $title->getNamespace();
-                               $dbkey = $title->getDBkey();
-                               $r = array(
-                                       'ns' => intval( $ns ),
-                                       'title' => $title->getPrefixedText(),
+                               // Query the results of our update
+                               $timestamps = array();
+                               $res = $dbw->select(
+                                       'watchlist',
+                                       array( 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ),
+                                       array( 'wl_user' => $user->getID(), $lb->constructSet( 'wl', $dbw ) ),
+                                       __METHOD__
                                );
-                               if ( !$title->exists() ) {
-                                       $r['missing'] = '';
+                               foreach ( $res as $row ) {
+                                       $timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp;
                                }
-                               if ( isset( $timestamps[$ns] ) && array_key_exists( $dbkey, $timestamps[$ns] ) ) {
-                                       $r['notificationtimestamp'] = '';
-                                       if ( $timestamps[$ns][$dbkey] !== null ) {
-                                               $r['notificationtimestamp'] = wfTimestamp( TS_ISO_8601, $timestamps[$ns][$dbkey] );
+
+                               // Now, put the valid titles into the result
+                               /** @var $title Title */
+                               foreach ( $pageSet->getTitles() as $title ) {
+                                       $ns = $title->getNamespace();
+                                       $dbkey = $title->getDBkey();
+                                       $r = array(
+                                               'ns' => intval( $ns ),
+                                               'title' => $title->getPrefixedText(),
+                                       );
+                                       if ( !$title->exists() ) {
+                                               $r['missing'] = '';
                                        }
-                               } else {
-                                       $r['notwatched'] = '';
+                                       if ( isset( $timestamps[$ns] ) && array_key_exists( $dbkey, $timestamps[$ns] ) ) {
+                                               $r['notificationtimestamp'] = '';
+                                               if ( $timestamps[$ns][$dbkey] !== null ) {
+                                                       $r['notificationtimestamp'] = wfTimestamp( TS_ISO_8601, $timestamps[$ns][$dbkey] );
+                                               }
+                                       } else {
+                                               $r['notwatched'] = '';
+                                       }
+                                       $result[] = $r;
                                }
-                               $result[] = $r;
                        }
 
                        $apiResult->setIndexedTagName( $result, 'page' );
                }
                $apiResult->addValue( null, $this->getModuleName(), $result );
+
+               $apiResult->endContinuation();
        }
 
        /**
@@ -214,6 +224,7 @@ class ApiSetNotificationTimestamp extends ApiBase {
                        'newerthanrevid' => array(
                                ApiBase::PARAM_TYPE => 'integer'
                        ),
+                       'continue' => '',
                );
                if ( $flags ) {
                        $result += $this->getPageSet()->getFinalParams( $flags );
@@ -229,6 +240,7 @@ class ApiSetNotificationTimestamp extends ApiBase {
                        'torevid' => 'Revision to set the notification timestamp to (one page only)',
                        'newerthanrevid' => 'Revision to set the notification timestamp newer than (one page only)',
                        'token' => 'A token previously acquired via prop=info',
+                       'continue' => 'When more results are available, use this to continue',
                );
        }
 
@@ -273,7 +285,7 @@ class ApiSetNotificationTimestamp extends ApiBase {
                return array( 'Update the notification timestamp for watched pages.',
                        'This affects the highlighting of changed pages in the watchlist and history,',
                        'and the sending of email when the "Email me when a page on my watchlist is',
-                       'changed" preference is enabled'
+                       'changed" preference is enabled.'
                );
        }