X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiEmailUser.php;h=65da13f0d7d19478e87744771a36a28e3c09c69d;hb=b512a8a1974d8317ab848a261ec18510ff1fac26;hp=91e2ad649cb6e465f22cc69751313fea4939f197;hpb=38299137f71cf5da61ce21d82536e5c04d112d34;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiEmailUser.php b/includes/api/ApiEmailUser.php index 91e2ad649c..65da13f0d7 100644 --- a/includes/api/ApiEmailUser.php +++ b/includes/api/ApiEmailUser.php @@ -1,10 +1,10 @@ + * Copyright © 2008 Bryan Tong Minh * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,95 +22,87 @@ * http://www.gnu.org/copyleft/gpl.html */ -if (!defined('MEDIAWIKI')) { +if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); + require_once( "ApiBase.php" ); } - /** * @ingroup API */ class ApiEmailUser extends ApiBase { - public function __construct($main, $action) { - parent :: __construct($main, $action); + public function __construct( $main, $action ) { + parent::__construct( $main, $action ); } public function execute() { global $wgUser; - // Check whether email is enabled - if ( !EmailUserForm::userEmailEnabled() ) + if ( !EmailUserForm::userEmailEnabled() ) { $this->dieUsageMsg( array( 'usermaildisabled' ) ); - - $this->getMain()->requestWriteMode(); + } + $params = $this->extractRequestParams(); - // Check required parameters - if ( !isset( $params['target'] ) ) + if ( !isset( $params['target'] ) ) { $this->dieUsageMsg( array( 'missingparam', 'target' ) ); - // Validate target + } + if ( !isset( $params['text'] ) ) { + $this->dieUsageMsg( array( 'missingparam', 'text' ) ); + } + + // Validate target $targetUser = EmailUserForm::validateEmailTarget( $params['target'] ); - if( isset( $params['check'] ) ) - if($targetUser instanceof User) { - $result = array( 'result' => 'Enabled' ); - $this->getResult()->addValue( null, $this->getModuleName(), $result ); - return; - } - else { - $result = array( 'result' => 'Disabled' ); - $this->getResult()->addValue( null, $this->getModuleName(), $result ); - return; - } //$this->dieUsageMsg( array( 'usermailenabled' ) ) : $this->dieUsageMsg( array( 'usermaildisabled' ) ); - if ( !( $targetUser instanceof User ) ) + if ( !( $targetUser instanceof User ) ) { $this->dieUsageMsg( array( $targetUser ) ); - - //Check more parameters - if ( !isset( $params['text'] ) ) - $this->dieUsageMsg( array( 'missingparam', 'text' ) ); - if ( !isset( $params['token'] ) ) - $this->dieUsageMsg( array( 'missingparam', 'token' ) ); - - + } + // Check permissions $error = EmailUserForm::getPermissionsError( $wgUser, $params['token'] ); - if ( $error ) + if ( $error ) { $this->dieUsageMsg( array( $error ) ); - - + } + $form = new EmailUserForm( $targetUser, $params['text'], $params['subject'], $params['ccme'] ); $retval = $form->doSubmit(); - if ( is_null( $retval ) ) + if ( is_null( $retval ) ) { $result = array( 'result' => 'Success' ); - else - $result = array( 'result' => 'Failure', - 'message' => $retval->getMessage() ); - + } else { + $result = array( + 'result' => 'Failure', + 'message' => $retval->getMessage() + ); + } + $this->getResult()->addValue( null, $this->getModuleName(), $result ); } - - public function mustBePosted() { return true; } + + public function mustBePosted() { + return true; + } + + public function isWriteMode() { + return true; + } public function getAllowedParams() { - return array ( + return array( 'target' => null, 'subject' => null, 'text' => null, 'token' => null, 'ccme' => false, - 'check' => null, ); } public function getParamDescription() { - return array ( + return array( 'target' => 'User to send email to', 'subject' => 'Subject header', 'text' => 'Mail body', 'token' => 'A token previously acquired via prop=info', 'ccme' => 'Send a copy of this mail to me', - 'check' => 'Check if the user has email enabled', ); } @@ -120,15 +112,25 @@ class ApiEmailUser extends ApiBase { ); } + public function getPossibleErrors() { + return array_merge( parent::getPossibleErrors(), array( + array( 'usermaildisabled' ), + array( 'missingparam', 'target' ), + array( 'missingparam', 'text' ), + ) ); + } + + public function getTokenSalt() { + return ''; + } + protected function getExamples() { - return array ( - 'api.php?action=emailuser&target=WikiSysop&text=Content', - 'api.php?action=emailuser&target=WikiSysop&check=yes', + return array( + 'api.php?action=emailuser&target=WikiSysop&text=Content' ); } public function getVersion() { return __CLASS__ . ': $Id$'; } -} - \ No newline at end of file +}