Fix parse error: syntax error, unexpected '}' in includes/api/ApiMain.php on line 467
[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 © 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 * @ingroup API
32 */
33 class ApiEmailUser extends ApiBase {
34
35 public function __construct( $main, $action ) {
36 parent::__construct( $main, $action );
37 }
38
39 public function execute() {
40 global $wgUser;
41 // Check whether email is enabled
42 if ( !EmailUserForm::userEmailEnabled() ) {
43 $this->dieUsageMsg( array( 'usermaildisabled' ) );
44 }
45
46 $params = $this->extractRequestParams();
47 // Check required parameters
48 if ( !isset( $params['target'] ) ) {
49 $this->dieUsageMsg( array( 'missingparam', 'target' ) );
50 }
51 if ( !isset( $params['text'] ) ) {
52 $this->dieUsageMsg( array( 'missingparam', 'text' ) );
53 }
54
55 // Validate target
56 $targetUser = EmailUserForm::validateEmailTarget( $params['target'] );
57 if ( !( $targetUser instanceof User ) ) {
58 $this->dieUsageMsg( array( $targetUser ) );
59 }
60
61 // Check permissions
62 $error = EmailUserForm::getPermissionsError( $wgUser, $params['token'] );
63 if ( $error ) {
64 $this->dieUsageMsg( array( $error ) );
65 }
66
67 $form = new EmailUserForm( $targetUser, $params['text'], $params['subject'], $params['ccme'] );
68 $retval = $form->doSubmit();
69 if ( is_null( $retval ) ) {
70 $result = array( 'result' => 'Success' );
71 } else {
72 $result = array(
73 'result' => 'Failure',
74 'message' => $retval->getMessage()
75 );
76 }
77
78 $this->getResult()->addValue( null, $this->getModuleName(), $result );
79 }
80
81 public function mustBePosted() {
82 return true;
83 }
84
85 public function isWriteMode() {
86 return true;
87 }
88
89 public function getAllowedParams() {
90 return array(
91 'target' => null,
92 'subject' => null,
93 'text' => null,
94 'token' => null,
95 'ccme' => false,
96 );
97 }
98
99 public function getParamDescription() {
100 return array(
101 'target' => 'User to send email to',
102 'subject' => 'Subject header',
103 'text' => 'Mail body',
104 'token' => 'A token previously acquired via prop=info',
105 'ccme' => 'Send a copy of this mail to me',
106 );
107 }
108
109 public function getDescription() {
110 return array(
111 'Email a user.'
112 );
113 }
114
115 public function getPossibleErrors() {
116 return array_merge( parent::getPossibleErrors(), array(
117 array( 'usermaildisabled' ),
118 array( 'missingparam', 'target' ),
119 array( 'missingparam', 'text' ),
120 ) );
121 }
122
123 public function getTokenSalt() {
124 return '';
125 }
126
127 protected function getExamples() {
128 return array(
129 'api.php?action=emailuser&target=WikiSysop&text=Content'
130 );
131 }
132
133 public function getVersion() {
134 return __CLASS__ . ': $Id$';
135 }
136 }