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 execute() {
34 $params = $this->extractRequestParams();
37 $targetUser = SpecialEmailUser
::getTarget( $params['target'] );
38 if ( !( $targetUser instanceof User
) ) {
39 $this->dieUsageMsg( array( $targetUser ) );
42 // Check permissions and errors
43 $error = SpecialEmailUser
::getPermissionsError( $this->getUser(), $params['token'] );
45 $this->dieUsageMsg( array( $error ) );
49 'Target' => $targetUser->getName(),
50 'Text' => $params['text'],
51 'Subject' => $params['subject'],
52 'CCMe' => $params['ccme'],
54 $retval = SpecialEmailUser
::submit( $data, $this->getContext() );
56 if ( $retval instanceof Status
) {
57 // SpecialEmailUser sometimes returns a status
58 // sometimes it doesn't.
59 if ( $retval->isGood() ) {
62 $retval = $retval->getErrorsArray();
66 if ( $retval === true ) {
67 $result = array( 'result' => 'Success' );
70 'result' => 'Failure',
75 $this->getResult()->addValue( null, $this->getModuleName(), $result );
78 public function mustBePosted() {
82 public function isWriteMode() {
86 public function getAllowedParams() {
89 ApiBase
::PARAM_TYPE
=> 'string',
90 ApiBase
::PARAM_REQUIRED
=> true
94 ApiBase
::PARAM_TYPE
=> 'string',
95 ApiBase
::PARAM_REQUIRED
=> true
101 public function getParamDescription() {
103 'target' => 'User to send email to',
104 'subject' => 'Subject header',
105 'text' => 'Mail body',
106 'ccme' => 'Send a copy of this mail to me',
110 public function getDescription() {
111 return 'Email a user.';
114 public function needsToken() {
118 public function getExamples() {
120 'api.php?action=emailuser&target=WikiSysop&text=Content&token=123ABC'
121 => 'Send an email to the User "WikiSysop" with the text "Content"',
125 public function getHelpUrls() {
126 return 'https://www.mediawiki.org/wiki/API:Email';