]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/api/ApiWatch.php
MediaWiki 1.16.1
[autoinstalls/mediawiki.git] / includes / api / ApiWatch.php
index ab122fea624e5e9dc5200ad18164e0cba0c65d39..391d91e21a3032212d479c2c99b6b61b1a988e21 100644 (file)
  * http://www.gnu.org/copyleft/gpl.html
  */
 
-if (!defined('MEDIAWIKI')) {
+if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ('ApiBase.php');
+       require_once ( 'ApiBase.php' );
 }
 
 /**
- * API module to allow users to log out of the wiki. API equivalent of
- * Special:Userlogout.
+ * API module to allow users to watch a page
  *
  * @ingroup API
  */
 class ApiWatch extends ApiBase {
 
-       public function __construct($main, $action) {
-               parent :: __construct($main, $action);
+       public function __construct( $main, $action ) {
+               parent :: __construct( $main, $action );
        }
 
        public function execute() {
                global $wgUser;
-               $this->getMain()->requestWriteMode();
-               if(!$wgUser->isLoggedIn())
-                       $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
+               if ( !$wgUser->isLoggedIn() )
+                       $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
+
                $params = $this->extractRequestParams();
-               $title = Title::newFromText($params['title']);
-               if(!$title)
-                       $this->dieUsageMsg(array('invalidtitle', $params['title']));
-               $article = new Article($title);
-               $res = array('title' => $title->getPrefixedText());
-               if($params['unwatch'])
+               $title = Title::newFromText( $params['title'] );
+
+               if ( !$title )
+                       $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+
+               $article = new Article( $title );
+               $res = array( 'title' => $title->getPrefixedText() );
+
+               if ( $params['unwatch'] )
                {
                        $res['unwatched'] = '';
                        $success = $article->doUnwatch();
@@ -61,9 +63,13 @@ class ApiWatch extends ApiBase {
                        $res['watched'] = '';
                        $success = $article->doWatch();
                }
-               if(!$success)
-                       $this->dieUsageMsg(array('hookaborted'));
-               $this->getResult()->addValue(null, $this->getModuleName(), $res);
+               if ( !$success )
+                       $this->dieUsageMsg( array( 'hookaborted' ) );
+               $this->getResult()->addValue( null, $this->getModuleName(), $res );
+       }
+
+       public function isWriteMode() {
+               return true;
        }
 
        public function getAllowedParams() {
@@ -85,6 +91,14 @@ class ApiWatch extends ApiBase {
                        'Add or remove a page 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' ),
+               ) );
+       }
 
        protected function getExamples() {
                return array(
@@ -94,6 +108,6 @@ class ApiWatch extends ApiBase {
        }
 
        public function getVersion() {
-               return __CLASS__ . ': $Id: ApiWatch.php 40460 2008-09-04 22:20:32Z ialex $';
+               return __CLASS__ . ': $Id: ApiWatch.php 69578 2010-07-20 02:46:20Z tstarling $';
        }
 }