X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiEmailUser.php;h=8aff6f8afd463d5a4fc170855a07d27dbe02a7b3;hp=efb9769b95b0fcddaed76d8e5f155d3f5b43c290;hb=49748181dd56ec97e7ba7c13e684a16abceb3cc0;hpb=8a6b7ff80dfd308f3607ae342aa6fd772b2e148c diff --git a/includes/api/ApiEmailUser.php b/includes/api/ApiEmailUser.php index efb9769b95..8aff6f8afd 100644 --- a/includes/api/ApiEmailUser.php +++ b/includes/api/ApiEmailUser.php @@ -36,7 +36,16 @@ class ApiEmailUser extends ApiBase { // Validate target $targetUser = SpecialEmailUser::getTarget( $params['target'] ); if ( !( $targetUser instanceof User ) ) { - $this->dieUsageMsg( array( $targetUser ) ); + switch ( $targetUser ) { + case 'notarget': + $this->dieWithError( 'apierror-notarget' ); + case 'noemail': + $this->dieWithError( [ 'noemail', $params['target'] ] ); + case 'nowikiemail': + $this->dieWithError( 'nowikiemailtext', 'nowikiemail' ); + default: + $this->dieWithError( [ 'apierror-unknownerror', $targetUser ] ); + } } // Check permissions and errors @@ -46,35 +55,26 @@ class ApiEmailUser extends ApiBase { $this->getConfig() ); if ( $error ) { - $this->dieUsageMsg( array( $error ) ); + $this->dieWithError( $error ); } - $data = array( + $data = [ 'Target' => $targetUser->getName(), 'Text' => $params['text'], 'Subject' => $params['subject'], 'CCMe' => $params['ccme'], - ); + ]; $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 instanceof Status ) { + // This is probably the reason + $retval = Status::newFatal( 'hookaborted' ); } - if ( $retval === true ) { - $result = array( 'result' => 'Success' ); - } else { - $result = array( - 'result' => 'Failure', - 'message' => $retval - ); - } + $result = array_filter( [ + 'result' => $retval->isGood() ? 'Success' : $retval->isOk() ? 'Warnings' : 'Failure', + 'warnings' => $this->getErrorFormatter()->arrayFromStatus( $retval, 'warning' ), + 'errors' => $this->getErrorFormatter()->arrayFromStatus( $retval, 'error' ), + ] ); $this->getResult()->addValue( null, $this->getModuleName(), $result ); } @@ -88,18 +88,18 @@ class ApiEmailUser extends ApiBase { } public function getAllowedParams() { - return array( - 'target' => array( + return [ + 'target' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true - ), + ], 'subject' => null, - 'text' => array( + 'text' => [ ApiBase::PARAM_TYPE => 'text', ApiBase::PARAM_REQUIRED => true - ), + ], 'ccme' => false, - ); + ]; } public function needsToken() { @@ -107,10 +107,10 @@ class ApiEmailUser extends ApiBase { } protected function getExamplesMessages() { - return array( + return [ 'action=emailuser&target=WikiSysop&text=Content&token=123ABC' => 'apihelp-emailuser-example-email', - ); + ]; } public function getHelpUrls() {