00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if (!defined('MEDIAWIKI')) {
00027
00028 require_once ('ApiBase.php');
00029 }
00030
00036 class ApiWatch extends ApiBase {
00037
00038 public function __construct($main, $action) {
00039 parent :: __construct($main, $action);
00040 }
00041
00042 public function execute() {
00043 global $wgUser;
00044 if(!$wgUser->isLoggedIn())
00045 $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
00046 $params = $this->extractRequestParams();
00047 $title = Title::newFromText($params['title']);
00048 if(!$title)
00049 $this->dieUsageMsg(array('invalidtitle', $params['title']));
00050 $article = new Article($title);
00051 $res = array('title' => $title->getPrefixedText());
00052 if($params['unwatch'])
00053 {
00054 $res['unwatched'] = '';
00055 $success = $article->doUnwatch();
00056 }
00057 else
00058 {
00059 $res['watched'] = '';
00060 $success = $article->doWatch();
00061 }
00062 if(!$success)
00063 $this->dieUsageMsg(array('hookaborted'));
00064 $this->getResult()->addValue(null, $this->getModuleName(), $res);
00065 }
00066
00067 public function isWriteMode() {
00068 return true;
00069 }
00070
00071 public function getAllowedParams() {
00072 return array (
00073 'title' => null,
00074 'unwatch' => false,
00075 );
00076 }
00077
00078 public function getParamDescription() {
00079 return array (
00080 'title' => 'The page to (un)watch',
00081 'unwatch' => 'If set the page will be unwatched rather than watched',
00082 );
00083 }
00084
00085 public function getDescription() {
00086 return array (
00087 'Add or remove a page from/to the current user\'s watchlist'
00088 );
00089 }
00090
00091 protected function getExamples() {
00092 return array(
00093 'api.php?action=watch&title=Main_Page',
00094 'api.php?action=watch&title=Main_Page&unwatch',
00095 );
00096 }
00097
00098 public function getVersion() {
00099 return __CLASS__ . ': $Id: ApiWatch.php 48091 2009-03-06 13:49:44Z catrope $';
00100 }
00101 }