<?php
-
/**
+ *
+ *
* Created on June 1, 2008
- * API for MediaWiki 1.8+
*
* Copyright © 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
*
*
* 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' ) ) {
- // Eclipse helper - will be ignored in production
- require_once( "ApiBase.php" );
-}
-
/**
+ * API Module to facilitate sending of emails to users
* @ingroup API
*/
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'] );
+ $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( $this->getUser(), $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, $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 getDescription() {
+ public function getResultProperties() {
return array(
- 'Email a user.'
+ '' => 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.';
+ }
+
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$';
}