3 * Copyright © 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * API Module to facilitate sending of emails to users
27 class ApiEmailUser
extends ApiBase
{
29 public function execute() {
30 $params = $this->extractRequestParams();
33 $targetUser = SpecialEmailUser
::getTarget( $params['target'], $this->getUser() );
34 if ( !( $targetUser instanceof User
) ) {
35 switch ( $targetUser ) {
37 $this->dieWithError( 'apierror-notarget' );
39 $this->dieWithError( [ 'noemail', $params['target'] ] );
41 $this->dieWithError( 'nowikiemailtext', 'nowikiemail' );
43 $this->dieWithError( [ 'apierror-unknownerror', $targetUser ] );
47 // Check permissions and errors
48 $error = SpecialEmailUser
::getPermissionsError(
54 $this->dieWithError( $error );
58 'Target' => $targetUser->getName(),
59 'Text' => $params['text'],
60 'Subject' => $params['subject'],
61 'CCMe' => $params['ccme'],
63 $retval = SpecialEmailUser
::submit( $data, $this->getContext() );
64 if ( !$retval instanceof Status
) {
65 // This is probably the reason
66 $retval = Status
::newFatal( 'hookaborted' );
69 $result = array_filter( [
70 'result' => $retval->isGood() ?
'Success' : ( $retval->isOK() ?
'Warnings' : 'Failure' ),
71 'warnings' => $this->getErrorFormatter()->arrayFromStatus( $retval, 'warning' ),
72 'errors' => $this->getErrorFormatter()->arrayFromStatus( $retval, 'error' ),
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
=> 'text',
95 ApiBase
::PARAM_REQUIRED
=> true
101 public function needsToken() {
105 protected function getExamplesMessages() {
107 'action=emailuser&target=WikiSysop&text=Content&token=123ABC'
108 => 'apihelp-emailuser-example-email',
112 public function getHelpUrls() {
113 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Email';