r35681 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35680‎ | r35681 | r35682 >
Date:17:58, 1 June 2008
Author:btongminh
Status:old
Tags:
Comment:
API: Add action=emailuser
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/SpecialEmailuser.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEmailUser.php (added) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiMain.php
@@ -76,6 +76,7 @@
7777 'unblock' => 'ApiUnblock',
7878 'move' => 'ApiMove',
7979 'edit' => 'ApiEditPage',
 80+ 'emailuser' => 'ApiEmailUser',
8081 );
8182
8283 /**
Index: trunk/phase3/includes/api/ApiEmailUser.php
@@ -0,0 +1,117 @@
 2+<?php
 3+
 4+/*
 5+ * Created on June 1, 2008
 6+ * API for MediaWiki 1.8+
 7+ *
 8+ * Copyright (C) 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
 9+ *
 10+ * This program is free software; you can redistribute it and/or modify
 11+ * it under the terms of the GNU General Public License as published by
 12+ * the Free Software Foundation; either version 2 of the License, or
 13+ * (at your option) any later version.
 14+ *
 15+ * This program is distributed in the hope that it will be useful,
 16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 18+ * GNU General Public License for more details.
 19+ *
 20+ * You should have received a copy of the GNU General Public License along
 21+ * with this program; if not, write to the Free Software Foundation, Inc.,
 22+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 23+ * http://www.gnu.org/copyleft/gpl.html
 24+ */
 25+
 26+if (!defined('MEDIAWIKI')) {
 27+ // Eclipse helper - will be ignored in production
 28+ require_once ("ApiBase.php");
 29+}
 30+
 31+
 32+/**
 33+ * @ingroup API
 34+ */
 35+class ApiEmailUser extends ApiBase {
 36+
 37+ public function __construct($main, $action) {
 38+ parent :: __construct($main, $action);
 39+ }
 40+
 41+ public function execute() {
 42+ global $wgUser;
 43+ $this->getMain()->requestWriteMode();
 44+ $params = $this->extractRequestParams();
 45+
 46+ // Check required parameters
 47+ if ( !isset( $params['target'] ) )
 48+ $this->dieUsageMsg( array( 'missingparam', 'target' ) );
 49+ if ( !isset( $params['text'] ) )
 50+ $this->dieUsageMsg( array( 'missingparam', 'text' ) );
 51+ if ( !isset( $params['token'] ) )
 52+ $this->dieUsageMsg( array( 'missingparam', 'token' ) );
 53+
 54+ // Match edit token
 55+ if( !$wgUser->matchEditToken( $params['token'] ) )
 56+ $this->dieUsageMsg( array( 'sessionfailure' ) );
 57+
 58+ // Check permissions
 59+ $errors = EmailUserForm::getPermissionsError( $params['target'] );
 60+ if ( $errors )
 61+ $this->dieUsageMsg( $errors[0] );
 62+
 63+ // Rate limiter
 64+ if( $wgUser->pingLimiter( 'emailuser' ) )
 65+ $this->dieUsageMsg( 'actionthrottledtext' );
 66+
 67+ $form = EmailUserForm::newFromURL( $params['target'],
 68+ $params['text'], $params['subject'], $params['ccme'] );
 69+ $retval = $form->doSubmit();
 70+ if ( is_null( $retval ) )
 71+ $result = array();
 72+ else
 73+ $result = array( 'result' => 'Failure',
 74+ 'message' => $retval->getMessage() );
 75+
 76+ $this->getResult()->addValue( null, $this->getModuleName(), $result );
 77+ }
 78+
 79+ public function mustBePosted() { return true; }
 80+
 81+ public function getAllowedParams() {
 82+ return array (
 83+ 'target' => null,
 84+ 'subject' => null,
 85+ 'text' => null,
 86+ 'token' => null,
 87+ 'ccme' => false,
 88+ );
 89+ }
 90+
 91+ public function getParamDescription() {
 92+ return array (
 93+ 'target' => 'User to send email to',
 94+ 'subject' => 'Subject header',
 95+ 'text' => 'Mail body',
 96+ // FIXME: How to properly get a token?
 97+ 'token' => 'A token previously acquired via prop=info',
 98+ 'ccme' => 'Send a copy of this mail to me',
 99+ );
 100+ }
 101+
 102+ public function getDescription() {
 103+ return array(
 104+ 'Emails a user.'
 105+ );
 106+ }
 107+
 108+ protected function getExamples() {
 109+ return array (
 110+ 'api.php?action=emailuser&target=WikiSysop&text=Content'
 111+ );
 112+ }
 113+
 114+ public function getVersion() {
 115+ return __CLASS__ . ': $Id: $';
 116+ }
 117+}
 118+
\ No newline at end of file
Property changes on: trunk/phase3/includes/api/ApiEmailUser.php
___________________________________________________________________
Added: svn:eol-style
1119 + native
Index: trunk/phase3/includes/SpecialEmailuser.php
@@ -188,7 +188,7 @@
189189 // We can either show them an error, or we can say everything was fine,
190190 // or we can say we sort of failed AND sort of succeeded. Of these options,
191191 // simply saying there was an error is probably best.
192 - return $ccResult->getMessage();
 192+ return $ccResult;
193193 }
194194 }
195195 }
Index: trunk/phase3/includes/AutoLoader.php
@@ -336,6 +336,7 @@
337337
338338 # API
339339 'ApiBase' => 'includes/api/ApiBase.php',
 340+ 'ApiEmailUser' => 'includes/api/ApiEmailUser.php',
340341 'ApiExpandTemplates' => 'includes/api/ApiExpandTemplates.php',
341342 'ApiFeedWatchlist' => 'includes/api/ApiFeedWatchlist.php',
342343 'ApiFormatBase' => 'includes/api/ApiFormatBase.php',
Index: trunk/phase3/RELEASE-NOTES
@@ -389,6 +389,7 @@
390390 * action=block now returns an ISO8601 timestamp, like all other modules do
391391 * Added md5 parameter to action=edit
392392 * (bug 14335) Logging in to unified account using API not possible
 393+* Added action=emailuser to send an email to a user
393394
394395 === Languages updated in 1.13 ===
395396

Status & tagging log