* changed display function for length to Linker::formatRevisionSize
[mediawiki.git] / includes / api / ApiEmailUser.php
blob55188b96a0a61e0573cd37e93aa34b500a92700e
1 <?php
2 /**
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
24 * @file
27 if ( !defined( 'MEDIAWIKI' ) ) {
28 // Eclipse helper - will be ignored in production
29 require_once( "ApiBase.php" );
32 /**
33 * API Module to facilitate sending of emails to users
34 * @ingroup API
36 class ApiEmailUser extends ApiBase {
38 public function __construct( $main, $action ) {
39 parent::__construct( $main, $action );
42 public function execute() {
43 global $wgUser;
45 $params = $this->extractRequestParams();
47 // Validate target
48 $targetUser = SpecialEmailUser::getTarget( $params['target'] );
49 if ( !( $targetUser instanceof User ) ) {
50 $this->dieUsageMsg( array( $targetUser ) );
53 // Check permissions and errors
54 $error = SpecialEmailUser::getPermissionsError( $wgUser, $params['token'] );
55 if ( $error ) {
56 $this->dieUsageMsg( array( $error ) );
59 $data = array(
60 'Target' => $targetUser->getName(),
61 'Text' => $params['text'],
62 'Subject' => $params['subject'],
63 'CCMe' => $params['ccme'],
65 $retval = SpecialEmailUser::submit( $data );
67 if ( $retval instanceof Status ) {
68 // SpecialEmailUser sometimes returns a status
69 // sometimes it doesn't.
70 if ( $retval->isGood() ) {
71 $retval = true;
72 } else {
73 $retval = $retval->getErrorsArray();
77 if ( $retval === true ) {
78 $result = array( 'result' => 'Success' );
79 } else {
80 $result = array(
81 'result' => 'Failure',
82 'message' => $retval
86 $this->getResult()->addValue( null, $this->getModuleName(), $result );
89 public function mustBePosted() {
90 return true;
93 public function isWriteMode() {
94 return true;
97 public function getAllowedParams() {
98 return array(
99 'target' => array(
100 ApiBase::PARAM_TYPE => 'string',
101 ApiBase::PARAM_REQUIRED => true
103 'subject' => null,
104 'text' => array(
105 ApiBase::PARAM_TYPE => 'string',
106 ApiBase::PARAM_REQUIRED => true
108 'token' => null,
109 'ccme' => false,
113 public function getParamDescription() {
114 return array(
115 'target' => 'User to send email to',
116 'subject' => 'Subject header',
117 'text' => 'Mail body',
118 'token' => 'A token previously acquired via prop=info',
119 'ccme' => 'Send a copy of this mail to me',
123 public function getDescription() {
124 return 'Email a user.';
127 public function getPossibleErrors() {
128 return array_merge( parent::getPossibleErrors(), array(
129 array( 'usermaildisabled' ),
130 ) );
133 public function needsToken() {
134 return true;
137 public function getTokenSalt() {
138 return '';
141 protected function getExamples() {
142 return array(
143 'api.php?action=emailuser&target=WikiSysop&text=Content'
147 public function getVersion() {
148 return __CLASS__ . ': $Id$';