r39768 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39767‎ | r39768 | r39769 >
Date:15:44, 21 August 2008
Author:catrope
Status:old
Tags:
Comment:
Adding action=watch to the API
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiWatch.php (added) (history)

Diff [purge]

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 @@
7878 'move' => 'ApiMove',
7979 'edit' => 'ApiEditPage',
8080 'emailuser' => 'ApiEmailUser',
 81+ 'watch' => 'ApiWatch',
8182 );
8283
8384 /**
Index: trunk/phase3/includes/AutoLoader.php
@@ -292,6 +292,7 @@
293293 'ApiRollback' => 'includes/api/ApiRollback.php',
294294 'ApiUnblock' => 'includes/api/ApiUnblock.php',
295295 'ApiUndelete' => 'includes/api/ApiUndelete.php',
 296+ 'ApiWatch' => 'includes/api/ApiWatch.php',
296297 'Services_JSON' => 'includes/api/ApiFormatJson_json.php',
297298 'Services_JSON_Error' => 'includes/api/ApiFormatJson_json.php',
298299 'Spyc' => 'includes/api/ApiFormatYaml_spyc.php',
Index: trunk/phase3/RELEASE-NOTES
@@ -167,6 +167,7 @@
168168 * list={backlinks,embeddedin,imageusage} now return arrays with keys 0, 1, 2,
169169 etc. (AKA lists) instead of arrays with pageIDs as keys (AKA hash tables)
170170 for consistency with other list modules.
 171+* Added action=watch
171172
172173 === Languages updated in 1.14 ===
173174

Status & tagging log