Followup r71831, it's not mutually exclusive!
[lhc/web/wiklou.git] / includes / api / ApiEmailUser.php
index 64a2c35..886e3e1 100644 (file)
@@ -1,9 +1,9 @@
 <?php
-
 /**
- * Created on June 1, 2008
  * API for MediaWiki 1.8+
  *
+ * Created on June 1, 2008
+ *
  * Copyright © 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -28,6 +30,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 }
 
 /**
+ * API Module to facilitate sending of emails to users
  * @ingroup API
  */
 class ApiEmailUser extends ApiBase {
@@ -40,33 +43,26 @@ class ApiEmailUser extends ApiBase {
                global $wgUser;
 
                $params = $this->extractRequestParams();
-               // Check required parameters
-               if ( !isset( $params['target'] ) ) {
-                       $this->dieUsageMsg( array( 'missingparam', 'target' ) );
-               }
-               if ( !isset( $params['text'] ) ) {
-                       $this->dieUsageMsg( array( 'missingparam', 'text' ) );
-               }
 
                // Validate target
-               $targetUser = SpecialEmailuser::getTarget( $params['target'] );
+               $targetUser = SpecialEmailUser::getTarget( $params['target'] );
                if ( !( $targetUser instanceof User ) ) {
                        $this->dieUsageMsg( array( $targetUser ) );
                }
 
                // Check permissions and errors
-               $error = SpecialEmailuser::getPermissionsError( $wgUser, $params['token'] );
+               $error = SpecialEmailUser::getPermissionsError( $wgUser, $params['token'] );
                if ( $error ) {
                        $this->dieUsageMsg( array( $error ) );
                }
 
                $data = array(
-                       'Target' => $targetUser->getName(), 
-                       'Text' => $params['text'], 
-                       'Subject' => $params['subject'], 
+                       'Target' => $targetUser->getName(),
+                       'Text' => $params['text'],
+                       'Subject' => $params['subject'],
                        'CCMe' => $params['ccme'],
                );
-               $retval = SpecialEmailuser::submit( $data );
+               $retval = SpecialEmailUser::submit( $data );
                if ( $retval === true ) {
                        $result = array( 'result' => 'Success' );
                } else {
@@ -89,9 +85,15 @@ class ApiEmailUser extends ApiBase {
 
        public function getAllowedParams() {
                return array(
-                       'target' => null,
+                       'target' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_REQUIRED => true
+                       ),
                        'subject' => null,
-                       'text' => null,
+                       'text' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_REQUIRED => true
+                       ),
                        'token' => null,
                        'ccme' => false,
                );
@@ -108,16 +110,12 @@ class ApiEmailUser extends ApiBase {
        }
 
        public function getDescription() {
-               return array(
-                       'Email a user.'
-               );
+               return 'Email a user.';
        }
 
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'usermaildisabled' ),
-                       array( 'missingparam', 'target' ),
-                       array( 'missingparam', 'text' ),
                ) );
        }