5 * Created on June 1, 2008
7 * Copyright © 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
28 * API Module to facilitate sending of emails to users
31 class ApiEmailUser
extends ApiBase
{
33 public function __construct( $main, $action ) {
34 parent
::__construct( $main, $action );
37 public function execute() {
38 $params = $this->extractRequestParams();
41 $targetUser = SpecialEmailUser
::getTarget( $params['target'] );
42 if ( !( $targetUser instanceof User
) ) {
43 $this->dieUsageMsg( array( $targetUser ) );
46 // Check permissions and errors
47 $error = SpecialEmailUser
::getPermissionsError( $this->getUser(), $params['token'] );
49 $this->dieUsageMsg( array( $error ) );
53 'Target' => $targetUser->getName(),
54 'Text' => $params['text'],
55 'Subject' => $params['subject'],
56 'CCMe' => $params['ccme'],
58 $retval = SpecialEmailUser
::submit( $data, $this->getContext() );
60 if ( $retval instanceof Status
) {
61 // SpecialEmailUser sometimes returns a status
62 // sometimes it doesn't.
63 if ( $retval->isGood() ) {
66 $retval = $retval->getErrorsArray();
70 if ( $retval === true ) {
71 $result = array( 'result' => 'Success' );
74 'result' => 'Failure',
79 $this->getResult()->addValue( null, $this->getModuleName(), $result );
82 public function mustBePosted() {
86 public function isWriteMode() {
90 public function getAllowedParams() {
93 ApiBase
::PARAM_TYPE
=> 'string',
94 ApiBase
::PARAM_REQUIRED
=> true
98 ApiBase
::PARAM_TYPE
=> 'string',
99 ApiBase
::PARAM_REQUIRED
=> true
106 public function getParamDescription() {
108 'target' => 'User to send email to',
109 'subject' => 'Subject header',
110 'text' => 'Mail body',
111 'token' => 'A token previously acquired via prop=info',
112 'ccme' => 'Send a copy of this mail to me',
116 public function getResultProperties() {
120 ApiBase
::PROP_TYPE
=> array(
126 ApiBase
::PROP_TYPE
=> 'string',
127 ApiBase
::PROP_NULLABLE
=> true
133 public function getDescription() {
134 return 'Email a user.';
137 public function getPossibleErrors() {
138 return array_merge( parent
::getPossibleErrors(), array(
139 array( 'usermaildisabled' ),
143 public function needsToken() {
147 public function getTokenSalt() {
151 public function getExamples() {
153 'api.php?action=emailuser&target=WikiSysop&text=Content' => 'Send an email to the User "WikiSysop" with the text "Content"',
157 public function getHelpUrls() {
158 return 'https://www.mediawiki.org/wiki/API:E-mail';
161 public function getVersion() {
162 return __CLASS__
. ': $Id$';