Index: trunk/phase3/includes/api/ApiEmailUser.php |
— | — | @@ -1,10 +1,10 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on June 1, 2008 |
6 | 6 | * API for MediaWiki 1.8+ |
7 | 7 | * |
8 | | - * Copyright (C) 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com> |
| 8 | + * Copyright © 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com> |
9 | 9 | * |
10 | 10 | * This program is free software; you can redistribute it and/or modify |
11 | 11 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | |
26 | 26 | if ( !defined( 'MEDIAWIKI' ) ) { |
27 | 27 | // Eclipse helper - will be ignored in production |
28 | | - require_once ( "ApiBase.php" ); |
| 28 | + require_once( "ApiBase.php" ); |
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
— | — | @@ -33,43 +33,51 @@ |
34 | 34 | class ApiEmailUser extends ApiBase { |
35 | 35 | |
36 | 36 | public function __construct( $main, $action ) { |
37 | | - parent :: __construct( $main, $action ); |
| 37 | + parent::__construct( $main, $action ); |
38 | 38 | } |
39 | 39 | |
40 | 40 | public function execute() { |
41 | 41 | global $wgUser; |
42 | 42 | // Check whether email is enabled |
43 | | - if ( !EmailUserForm::userEmailEnabled() ) |
| 43 | + if ( !EmailUserForm::userEmailEnabled() ) { |
44 | 44 | $this->dieUsageMsg( array( 'usermaildisabled' ) ); |
| 45 | + } |
45 | 46 | |
46 | 47 | $params = $this->extractRequestParams(); |
47 | 48 | // Check required parameters |
48 | | - if ( !isset( $params['target'] ) ) |
| 49 | + if ( !isset( $params['target'] ) ) { |
49 | 50 | $this->dieUsageMsg( array( 'missingparam', 'target' ) ); |
50 | | - if ( !isset( $params['text'] ) ) |
| 51 | + } |
| 52 | + if ( !isset( $params['text'] ) ) { |
51 | 53 | $this->dieUsageMsg( array( 'missingparam', 'text' ) ); |
52 | | - |
53 | | - // Validate target |
| 54 | + } |
| 55 | + |
| 56 | + // Validate target |
54 | 57 | $targetUser = EmailUserForm::validateEmailTarget( $params['target'] ); |
55 | | - if ( !( $targetUser instanceof User ) ) |
| 58 | + if ( !( $targetUser instanceof User ) ) { |
56 | 59 | $this->dieUsageMsg( array( $targetUser ) ); |
57 | | - |
| 60 | + } |
| 61 | + |
58 | 62 | // Check permissions |
59 | 63 | $error = EmailUserForm::getPermissionsError( $wgUser, $params['token'] ); |
60 | | - if ( $error ) |
| 64 | + if ( $error ) { |
61 | 65 | $this->dieUsageMsg( array( $error ) ); |
| 66 | + } |
62 | 67 | |
63 | 68 | $form = new EmailUserForm( $targetUser, $params['text'], $params['subject'], $params['ccme'] ); |
64 | 69 | $retval = $form->doSubmit(); |
65 | | - if ( is_null( $retval ) ) |
| 70 | + if ( is_null( $retval ) ) { |
66 | 71 | $result = array( 'result' => 'Success' ); |
67 | | - else |
68 | | - $result = array( 'result' => 'Failure', |
69 | | - 'message' => $retval->getMessage() ); |
70 | | - |
| 72 | + } else { |
| 73 | + $result = array( |
| 74 | + 'result' => 'Failure', |
| 75 | + 'message' => $retval->getMessage() |
| 76 | + ); |
| 77 | + } |
| 78 | + |
71 | 79 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
72 | 80 | } |
73 | | - |
| 81 | + |
74 | 82 | public function mustBePosted() { |
75 | 83 | return true; |
76 | 84 | } |
— | — | @@ -79,7 +87,7 @@ |
80 | 88 | } |
81 | 89 | |
82 | 90 | public function getAllowedParams() { |
83 | | - return array ( |
| 91 | + return array( |
84 | 92 | 'target' => null, |
85 | 93 | 'subject' => null, |
86 | 94 | 'text' => null, |
— | — | @@ -89,7 +97,7 @@ |
90 | 98 | } |
91 | 99 | |
92 | 100 | public function getParamDescription() { |
93 | | - return array ( |
| 101 | + return array( |
94 | 102 | 'target' => 'User to send email to', |
95 | 103 | 'subject' => 'Subject header', |
96 | 104 | 'text' => 'Mail body', |
— | — | @@ -103,21 +111,21 @@ |
104 | 112 | 'Email a user.' |
105 | 113 | ); |
106 | 114 | } |
107 | | - |
108 | | - public function getPossibleErrors() { |
| 115 | + |
| 116 | + public function getPossibleErrors() { |
109 | 117 | return array_merge( parent::getPossibleErrors(), array( |
110 | 118 | array( 'usermaildisabled' ), |
111 | 119 | array( 'missingparam', 'target' ), |
112 | 120 | array( 'missingparam', 'text' ), |
113 | | - ) ); |
| 121 | + ) ); |
114 | 122 | } |
115 | | - |
| 123 | + |
116 | 124 | public function getTokenSalt() { |
117 | 125 | return ''; |
118 | 126 | } |
119 | 127 | |
120 | 128 | protected function getExamples() { |
121 | | - return array ( |
| 129 | + return array( |
122 | 130 | 'api.php?action=emailuser&target=WikiSysop&text=Content' |
123 | 131 | ); |
124 | 132 | } |
— | — | @@ -126,4 +134,3 @@ |
127 | 135 | return __CLASS__ . ': $Id$'; |
128 | 136 | } |
129 | 137 | } |
130 | | - |
\ No newline at end of file |