<?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
}
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'] );
}
// Check permissions and errors
- $error = SpecialEmailUser::getPermissionsError( $wgUser, $params['token'] );
+ $error = SpecialEmailUser::getPermissionsError( $this->getUser(), $params['token'] );
if ( $error ) {
$this->dieUsageMsg( array( $error ) );
}
'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 {
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,
);
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$';
}