Index: trunk/phase3/includes/api/ApiWatch.php |
— | — | @@ -0,0 +1,99 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/*
|
| 5 | + * Created on Jan 4, 2008
|
| 6 | + *
|
| 7 | + * API for MediaWiki 1.8+
|
| 8 | + *
|
| 9 | + * Copyright (C) 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com,
|
| 10 | + *
|
| 11 | + * This program is free software; you can redistribute it and/or modify
|
| 12 | + * it under the terms of the GNU General Public License as published by
|
| 13 | + * the Free Software Foundation; either version 2 of the License, or
|
| 14 | + * (at your option) any later version.
|
| 15 | + *
|
| 16 | + * This program is distributed in the hope that it will be useful,
|
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 19 | + * GNU General Public License for more details.
|
| 20 | + *
|
| 21 | + * You should have received a copy of the GNU General Public License along
|
| 22 | + * with this program; if not, write to the Free Software Foundation, Inc.,
|
| 23 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 24 | + * http://www.gnu.org/copyleft/gpl.html
|
| 25 | + */
|
| 26 | +
|
| 27 | +if (!defined('MEDIAWIKI')) {
|
| 28 | + // Eclipse helper - will be ignored in production
|
| 29 | + require_once ('ApiBase.php');
|
| 30 | +}
|
| 31 | +
|
| 32 | +/**
|
| 33 | + * API module to allow users to log out of the wiki. API equivalent of
|
| 34 | + * Special:Userlogout.
|
| 35 | + *
|
| 36 | + * @ingroup API
|
| 37 | + */
|
| 38 | +class ApiWatch extends ApiBase {
|
| 39 | +
|
| 40 | + public function __construct($main, $action) {
|
| 41 | + parent :: __construct($main, $action);
|
| 42 | + }
|
| 43 | +
|
| 44 | + public function execute() {
|
| 45 | + global $wgUser;
|
| 46 | + $this->getMain()->requestWriteMode();
|
| 47 | + if(!$wgUser->isLoggedIn())
|
| 48 | + $this->dieUsage('You must be logged-in to have a watchlist', 'notloggedin');
|
| 49 | + $params = $this->extractRequestParams();
|
| 50 | + $title = Title::newFromText($params['title']);
|
| 51 | + if(!$title)
|
| 52 | + $this->dieUsageMsg(array('invalidtitle', $params['title']));
|
| 53 | + $article = new Article($title);
|
| 54 | + $res = array('title' => $title->getPrefixedText());
|
| 55 | + if($params['unwatch'])
|
| 56 | + {
|
| 57 | + $res['unwatched'] = '';
|
| 58 | + $success = $article->doUnwatch();
|
| 59 | + }
|
| 60 | + else
|
| 61 | + {
|
| 62 | + $res['watched'] = '';
|
| 63 | + $success = $article->doWatch();
|
| 64 | + }
|
| 65 | + if(!$success)
|
| 66 | + $this->dieUsageMsg(array('hookaborted'));
|
| 67 | + $this->getResult()->addValue(null, $this->getModuleName(), $res);
|
| 68 | + }
|
| 69 | +
|
| 70 | + public function getAllowedParams() {
|
| 71 | + return array (
|
| 72 | + 'title' => null,
|
| 73 | + 'unwatch' => false,
|
| 74 | + );
|
| 75 | + }
|
| 76 | +
|
| 77 | + public function getParamDescription() {
|
| 78 | + return array (
|
| 79 | + 'title' => 'The page to (un)watch',
|
| 80 | + 'unwatch' => 'If set the page will be unwatched rather than watched',
|
| 81 | + );
|
| 82 | + }
|
| 83 | +
|
| 84 | + public function getDescription() {
|
| 85 | + return array (
|
| 86 | + 'Add or remove a page from/to the current user\'s watchlist'
|
| 87 | + );
|
| 88 | + }
|
| 89 | +
|
| 90 | + protected function getExamples() {
|
| 91 | + return array(
|
| 92 | + 'api.php?action=watch&title=Main_Page',
|
| 93 | + 'api.php?action=watch&title=Main_Page&unwatch',
|
| 94 | + );
|
| 95 | + }
|
| 96 | +
|
| 97 | + public function getVersion() {
|
| 98 | + return __CLASS__ . ': $Id: ApiLogout.php 35294 2008-05-24 20:44:49Z btongminh $';
|
| 99 | + }
|
| 100 | +}
|
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -77,6 +77,7 @@ |
78 | 78 | 'move' => 'ApiMove', |
79 | 79 | 'edit' => 'ApiEditPage', |
80 | 80 | 'emailuser' => 'ApiEmailUser', |
| 81 | + 'watch' => 'ApiWatch', |
81 | 82 | ); |
82 | 83 | |
83 | 84 | /** |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -292,6 +292,7 @@ |
293 | 293 | 'ApiRollback' => 'includes/api/ApiRollback.php', |
294 | 294 | 'ApiUnblock' => 'includes/api/ApiUnblock.php', |
295 | 295 | 'ApiUndelete' => 'includes/api/ApiUndelete.php', |
| 296 | + 'ApiWatch' => 'includes/api/ApiWatch.php', |
296 | 297 | 'Services_JSON' => 'includes/api/ApiFormatJson_json.php', |
297 | 298 | 'Services_JSON_Error' => 'includes/api/ApiFormatJson_json.php', |
298 | 299 | 'Spyc' => 'includes/api/ApiFormatYaml_spyc.php', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -167,6 +167,7 @@ |
168 | 168 | * list={backlinks,embeddedin,imageusage} now return arrays with keys 0, 1, 2, |
169 | 169 | etc. (AKA lists) instead of arrays with pageIDs as keys (AKA hash tables) |
170 | 170 | for consistency with other list modules. |
| 171 | +* Added action=watch |
171 | 172 | |
172 | 173 | === Languages updated in 1.14 === |
173 | 174 | |