4 * Created on June 1, 2008
5 * API for MediaWiki 1.8+
7 * Copyright (C) 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * http://www.gnu.org/copyleft/gpl.html
25 if (!defined('MEDIAWIKI')) {
26 // Eclipse helper - will be ignored in production
27 require_once ("ApiBase.php");
34 class ApiEmailUser
extends ApiBase
{
36 public function __construct($main, $action) {
37 parent
:: __construct($main, $action);
40 public function execute() {
42 $this->getMain()->requestWriteMode();
43 $params = $this->extractRequestParams();
45 // Check required parameters
46 if ( !isset( $params['target'] ) )
47 $this->dieUsageMsg( array( 'missingparam', 'target' ) );
48 if ( !isset( $params['text'] ) )
49 $this->dieUsageMsg( array( 'missingparam', 'text' ) );
50 if ( !isset( $params['token'] ) )
51 $this->dieUsageMsg( array( 'missingparam', 'token' ) );
54 $targetUser = EmailUserForm
::validateEmailTarget( $params['target'] );
55 if ( !( $targetUser instanceof User
) )
56 $this->dieUsageMsg( array( $targetUser[0] ) );
59 $error = EmailUserForm
::getPermissionsError( $wgUser, $params['token'] );
61 $this->dieUsageMsg( array( $error[0] ) );
64 $form = new EmailUserForm( $targetUser, $params['text'], $params['subject'], $params['ccme'] );
65 $retval = $form->doSubmit();
66 if ( is_null( $retval ) )
67 $result = array( 'result' => 'Success' );
69 $result = array( 'result' => 'Failure',
70 'message' => $retval->getMessage() );
72 $this->getResult()->addValue( null, $this->getModuleName(), $result );
75 public function mustBePosted() { return true; }
77 public function getAllowedParams() {
87 public function getParamDescription() {
89 'target' => 'User to send email to',
90 'subject' => 'Subject header',
91 'text' => 'Mail body',
92 // FIXME: How to properly get a token?
93 'token' => 'A token previously acquired via prop=info',
94 'ccme' => 'Send a copy of this mail to me',
98 public function getDescription() {
104 protected function getExamples() {
106 'api.php?action=emailuser&target=WikiSysop&text=Content'
110 public function getVersion() {
111 return __CLASS__
. ': $Id: $';