Mass convert NULL -> null. Left strings and comments alone, obviously.
[lhc/web/wiklou.git] / includes / api / ApiEmailUser.php
1 <?php
2
3 /*
4 * Created on June 1, 2008
5 * API for MediaWiki 1.8+
6 *
7 * Copyright (C) 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
8 *
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.
13 *
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.
18 *
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
23 */
24
25 if (!defined('MEDIAWIKI')) {
26 // Eclipse helper - will be ignored in production
27 require_once ("ApiBase.php");
28 }
29
30
31 /**
32 * @ingroup API
33 */
34 class ApiEmailUser extends ApiBase {
35
36 public function __construct($main, $action) {
37 parent :: __construct($main, $action);
38 }
39
40 public function execute() {
41 global $wgUser;
42 // Check whether email is enabled
43 if ( !EmailUserForm::userEmailEnabled() )
44 $this->dieUsageMsg( array( 'usermaildisabled' ) );
45
46 $params = $this->extractRequestParams();
47 // Check required parameters
48 if ( !isset( $params['target'] ) )
49 $this->dieUsageMsg( array( 'missingparam', 'target' ) );
50 if ( !isset( $params['text'] ) )
51 $this->dieUsageMsg( array( 'missingparam', 'text' ) );
52 if ( !isset( $params['token'] ) )
53 $this->dieUsageMsg( array( 'missingparam', 'token' ) );
54
55 // Validate target
56 $targetUser = EmailUserForm::validateEmailTarget( $params['target'] );
57 if ( !( $targetUser instanceof User ) )
58 $this->dieUsageMsg( array( $targetUser ) );
59
60 // Check permissions
61 $error = EmailUserForm::getPermissionsError( $wgUser, $params['token'] );
62 if ( $error )
63 $this->dieUsageMsg( array( $error ) );
64
65
66 $form = new EmailUserForm( $targetUser, $params['text'], $params['subject'], $params['ccme'] );
67 $retval = $form->doSubmit();
68 if ( is_null( $retval ) )
69 $result = array( 'result' => 'Success' );
70 else
71 $result = array( 'result' => 'Failure',
72 'message' => $retval->getMessage() );
73
74 $this->getResult()->addValue( null, $this->getModuleName(), $result );
75 }
76
77 public function mustBePosted() { return true; }
78
79 public function isWriteMode() {
80 return true;
81 }
82
83 public function getAllowedParams() {
84 return array (
85 'target' => null,
86 'subject' => null,
87 'text' => null,
88 'token' => null,
89 'ccme' => false,
90 );
91 }
92
93 public function getParamDescription() {
94 return array (
95 'target' => 'User to send email to',
96 'subject' => 'Subject header',
97 'text' => 'Mail body',
98 'token' => 'A token previously acquired via prop=info',
99 'ccme' => 'Send a copy of this mail to me',
100 );
101 }
102
103 public function getDescription() {
104 return array(
105 'Email a user.'
106 );
107 }
108
109 protected function getExamples() {
110 return array (
111 'api.php?action=emailuser&target=WikiSysop&text=Content'
112 );
113 }
114
115 public function getVersion() {
116 return __CLASS__ . ': $Id$';
117 }
118 }
119