Merge "AJAXify watchlist editor"
[lhc/web/wiklou.git] / includes / api / ApiWatch.php
index 0509f1f..f307f9a 100644 (file)
@@ -40,14 +40,27 @@ class ApiWatch extends ApiBase {
                if ( !$user->isLoggedIn() ) {
                        $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
                }
-
                $params = $this->extractRequestParams();
-               $title = Title::newFromText( $params['title'] );
-
-               if ( !$title || $title->getNamespace() < 0 ) {
-                       $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+               // titles can handle basic request of 1 title,
+               // but title is still supported for backward compatability
+               if ( isset( $params['title'] ) ) {
+                       $title = Title::newFromText( $params['title'] );
+                       if ( !$title || $title->getNamespace() < 0 ) {
+                               $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+                       }
+                       $res = $this->watchTitle( $title, $user, $params);
+               } else {
+                       $pageSet = new ApiPageSet( $this );
+                       $pageSet->execute();
+                       $res = array();
+                       foreach ( $pageSet->getTitles() as $title ) {
+                               $r = $this->watchTitle( $title, $user, $params);
+                               $res[] = $r;
+                       }
                }
-
+               $this->getResult()->addValue( null, $this->getModuleName(), $res );
+       }
+       private function watchTitle( $title, $user, $params ) {
                $res = array( 'title' => $title->getPrefixedText() );
 
                if ( $params['unwatch'] ) {
@@ -62,7 +75,7 @@ class ApiWatch extends ApiBase {
                if ( !$success ) {
                        $this->dieUsageMsg( 'hookaborted' );
                }
-               $this->getResult()->addValue( null, $this->getModuleName(), $res );
+               return $res;
        }
 
        public function mustBePosted() {
@@ -85,7 +98,10 @@ class ApiWatch extends ApiBase {
                return array(
                        'title' => array(
                                ApiBase::PARAM_TYPE => 'string',
-                               ApiBase::PARAM_REQUIRED => true
+                       ),
+                       'titles' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_ISMULTI => true
                        ),
                        'unwatch' => false,
                        'token' => array(