API: Log usage of various deprecated features
[lhc/web/wiklou.git] / includes / api / ApiWatch.php
index 953df58..8060260 100644 (file)
@@ -43,53 +43,33 @@ class ApiWatch extends ApiBase {
                }
 
                $params = $this->extractRequestParams();
+
+               $this->getResult()->beginContinuation( $params['continue'], array(), array() );
+
                $pageSet = $this->getPageSet();
                // by default we use pageset to extract the page to work on.
                // title is still supported for backward compatibility
                if ( !isset( $params['title'] ) ) {
-                       if ( $params['entirewatchlist'] && $pageSet->getDataSource() !== null ) {
-                               $this->dieUsage(
-                                       "Cannot use 'entirewatchlist' at the same time as '{$pageSet->getDataSource()}'",
-                                       'multisource'
-                               );
+                       $pageSet->execute();
+                       $res = $pageSet->getInvalidTitlesAndRevisions( array(
+                               'invalidTitles',
+                               'special',
+                               'missingIds',
+                               'missingRevIds',
+                               'interwikiTitles'
+                       ) );
+
+                       foreach ( $pageSet->getMissingTitles() as $title ) {
+                               $r = $this->watchTitle( $title, $user, $params );
+                               $r['missing'] = 1;
+                               $res[] = $r;
                        }
 
-                       if ( $params['entirewatchlist'] ) {
-                               if ( !$params['unwatch'] ) {
-                                       $this->dieUsage(
-                                               "'entirewatchlist' option can only be used with 'unwatch' parameter.",
-                                               'invalidparammix'
-                                       );
-                               } else {
-                                       // We're going to do this in the database as a bulk operation
-                                       // instead of one at a time, so it doesn't time out on largeish lists.
-                                       $dbw = wfGetDB( DB_MASTER );
-                                       $dbw->delete( 'watchlist', array( 'wl_user' => $user->getId() ), __METHOD__ );
-                                       $user->invalidateCache();
-                                       $res = array();
-                               }
-                       } else {
-                               $pageSet->execute();
-                               $res = $pageSet->getInvalidTitlesAndRevisions( array(
-                                       'invalidTitles',
-                                       'special',
-                                       'missingIds',
-                                       'missingRevIds',
-                                       'interwikiTitles'
-                               ) );
-
-                               foreach ( $pageSet->getMissingTitles() as $title ) {
-                                       $r = $this->watchTitle( $title, $user, $params );
-                                       $r['missing'] = 1;
-                                       $res[] = $r;
-                               }
-
-                               foreach ( $pageSet->getGoodTitles() as $title ) {
-                                       $r = $this->watchTitle( $title, $user, $params );
-                                       $res[] = $r;
-                               }
-                               $this->getResult()->setIndexedTagName( $res, 'w' );
+                       foreach ( $pageSet->getGoodTitles() as $title ) {
+                               $r = $this->watchTitle( $title, $user, $params );
+                               $res[] = $r;
                        }
+                       $this->getResult()->setIndexedTagName( $res, 'w' );
                } else {
                        // dont allow use of old title parameter with new pageset parameters.
                        $extraParams = array_keys( array_filter( $pageSet->extractRequestParams(), function ( $x ) {
@@ -104,6 +84,7 @@ class ApiWatch extends ApiBase {
                                );
                        }
 
+                       $this->logFeatureUsage( 'action=watch&title' );
                        $title = Title::newFromText( $params['title'] );
                        if ( !$title || !$title->isWatchable() ) {
                                $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
@@ -111,6 +92,7 @@ class ApiWatch extends ApiBase {
                        $res = $this->watchTitle( $title, $user, $params, true );
                }
                $this->getResult()->addValue( null, $this->getModuleName(), $res );
+               $this->getResult()->endContinuation();
        }
 
        private function watchTitle( Title $title, User $user, array $params,
@@ -198,12 +180,12 @@ class ApiWatch extends ApiBase {
                                ApiBase::PARAM_DEPRECATED => true
                        ),
                        'unwatch' => false,
-                       'entirewatchlist' => false,
                        'uselang' => null,
                        'token' => array(
                                ApiBase::PARAM_TYPE => 'string',
                                ApiBase::PARAM_REQUIRED => true
                        ),
+                       'continue' => '',
                );
                if ( $flags ) {
                        $result += $this->getPageSet()->getFinalParams( $flags );
@@ -218,20 +200,9 @@ class ApiWatch extends ApiBase {
                return $psModule->getParamDescription() + array(
                        'title' => 'The page to (un)watch. use titles instead',
                        'unwatch' => 'If set the page will be unwatched rather than watched',
-                       'entirewatchlist' => 'Work on all watched pages without returning a list; can only be used together with \'unwatch\' option.',
                        'uselang' => 'Language to show the message in',
                        'token' => 'A token previously acquired via prop=info',
-               );
-       }
-
-       public function getResultProperties() {
-               return array(
-                       '' => array(
-                               'title' => 'string',
-                               'unwatched' => 'boolean',
-                               'watched' => 'boolean',
-                               'message' => 'string'
-                       )
+                       'continue' => 'When more results are available, use this to continue',
                );
        }
 
@@ -239,14 +210,6 @@ class ApiWatch extends ApiBase {
                return 'Add or remove pages from/to the current user\'s watchlist.';
        }
 
-       public function getPossibleErrors() {
-               return array_merge( parent::getPossibleErrors(), array(
-                       array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ),
-                       array( 'invalidtitle', 'title' ),
-                       array( 'hookaborted' ),
-               ) );
-       }
-
        public function getExamples() {
                return array(
                        'api.php?action=watch&titles=Main_Page' => 'Watch the page "Main Page"',