Merge "(bug 36568) Fixed "Illegal string offset 'LIMIT'" warnings in updater"
[lhc/web/wiklou.git] / includes / api / ApiEmailUser.php
index bc3c7a2..0032bd8 100644 (file)
@@ -1,8 +1,8 @@
 <?php
-
 /**
+ *
+ *
  * Created on June 1, 2008
- * API for MediaWiki 1.8+
  *
  * Copyright © 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
  *
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @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
@@ -38,16 +35,7 @@ class ApiEmailUser extends ApiBase {
        }
 
        public function execute() {
-               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'] );
@@ -56,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 ) );
                }
@@ -67,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 {
@@ -90,9 +89,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,
                );
@@ -115,21 +120,27 @@ class ApiEmailUser extends ApiBase {
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'usermaildisabled' ),
-                       array( 'missingparam', 'target' ),
-                       array( 'missingparam', 'text' ),
                ) );
        }
 
+       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$';
        }