Merge "Added some extra tests for ORMRow class"
[lhc/web/wiklou.git] / includes / api / ApiEmailUser.php
index 886e3e1..4b6ba00 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * API for MediaWiki 1.8+
+ *
  *
  * Created on June 1, 2008
  *
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( "ApiBase.php" );
-}
-
 /**
  * API Module to facilitate sending of emails to users
  * @ingroup API
@@ -40,8 +35,6 @@ class ApiEmailUser extends ApiBase {
        }
 
        public function execute() {
-               global $wgUser;
-
                $params = $this->extractRequestParams();
 
                // Validate target
@@ -51,7 +44,7 @@ class ApiEmailUser extends ApiBase {
                }
 
                // Check permissions and errors
-               $error = SpecialEmailUser::getPermissionsError( $wgUser, $params['token'] );
+               $error = SpecialEmailUser::getPermissionsError( $this->getUser(), $params['token'] );
                if ( $error ) {
                        $this->dieUsageMsg( array( $error ) );
                }
@@ -62,7 +55,18 @@ class ApiEmailUser extends ApiBase {
                        'Subject' => $params['subject'],
                        'CCMe' => $params['ccme'],
                );
-               $retval = SpecialEmailUser::submit( $data );
+               $retval = SpecialEmailUser::submit( $data, $this->getContext() );
+
+               if ( $retval instanceof Status ) {
+                       // SpecialEmailUser sometimes returns a status
+                       // sometimes it doesn't.
+                       if ( $retval->isGood() ) {
+                               $retval = true;
+                       } else {
+                               $retval = $retval->getErrorsArray();
+                       }
+               }
+
                if ( $retval === true ) {
                        $result = array( 'result' => 'Success' );
                } else {
@@ -109,6 +113,23 @@ class ApiEmailUser extends ApiBase {
                );
        }
 
+       public function getResultProperties() {
+               return array(
+                       '' => array(
+                               'result' => array(
+                                       ApiBase::PROP_TYPE => array(
+                                               'Success',
+                                               'Failure'
+                                       ),
+                               ),
+                               'message' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       )
+               );
+       }
+
        public function getDescription() {
                return 'Email a user.';
        }
@@ -119,16 +140,24 @@ class ApiEmailUser extends ApiBase {
                ) );
        }
 
+       public function needsToken() {
+               return true;
+       }
+
        public function getTokenSalt() {
                return '';
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
-                       'api.php?action=emailuser&target=WikiSysop&text=Content'
+                       'api.php?action=emailuser&target=WikiSysop&text=Content' => 'Send an email to the User "WikiSysop" with the text "Content"',
                );
        }
 
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/API:E-mail';
+       }
+
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }