* Fixup validation methods in UserEmailForm a bit so that they don't return arrays when it's not necessary.
* Add email errors to the API's message map
This commit is contained in:
parent
597d9c6dee
commit
a9fd7beaef
3 changed files with 31 additions and 18 deletions
|
|
@ -633,7 +633,11 @@ abstract class ApiBase {
|
|||
'ipb_blocked_as_range' => array('code' => 'blockedasrange', 'info' => "IP address ``\$1'' was blocked as part of range ``\$2''. You can't unblock the IP invidually, but you can unblock the range as a whole."),
|
||||
'ipb_cant_unblock' => array('code' => 'cantunblock', 'info' => "The block you specified was not found. It may have been unblocked already"),
|
||||
'mailnologin' => array('code' => 'cantsend', 'info' => "You're not logged in or you don't have a confirmed e-mail address, so you can't send e-mail"),
|
||||
'usermaildisabled' => array('code' => 'usermaildisabled' 'info' => "User email has been disabled"),
|
||||
'blockedemailuser' => array('code' => 'blockedfrommail', 'info' => "You have been blocked from sending e-mail"),
|
||||
'notarget' => array('code' => 'notarget', 'info' => "You have not specified a valid target for this action"),
|
||||
'noemail' => array('code' => 'noemail', 'info' => "The user has not specified a valid e-mail address, or has chosen not to receive e-mail from other users"),
|
||||
|
||||
|
||||
|
||||
// API-specific messages
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ class ApiEmailUser extends ApiBase {
|
|||
|
||||
public function execute() {
|
||||
global $wgUser;
|
||||
|
||||
// Check whether email is enabled
|
||||
if ( !EmailUserForm::userEmailEnabled() )
|
||||
$this->dieUsageMsg( array( 'usermaildisabled' ) );
|
||||
|
||||
$this->getMain()->requestWriteMode();
|
||||
$params = $this->extractRequestParams();
|
||||
|
||||
|
|
@ -53,12 +58,12 @@ class ApiEmailUser extends ApiBase {
|
|||
// Validate target
|
||||
$targetUser = EmailUserForm::validateEmailTarget( $params['target'] );
|
||||
if ( !( $targetUser instanceof User ) )
|
||||
$this->dieUsageMsg( array( $targetUser[0] ) );
|
||||
$this->dieUsageMsg( array( $targetUser ) );
|
||||
|
||||
// Check permissions
|
||||
$error = EmailUserForm::getPermissionsError( $wgUser, $params['token'] );
|
||||
if ( $error )
|
||||
$this->dieUsageMsg( array( $error[0] ) );
|
||||
$this->dieUsageMsg( array( $error ) );
|
||||
|
||||
|
||||
$form = new EmailUserForm( $targetUser, $params['text'], $params['subject'], $params['ccme'] );
|
||||
|
|
|
|||
|
|
@ -10,12 +10,17 @@
|
|||
function wfSpecialEmailuser( $par ) {
|
||||
global $wgRequest, $wgUser, $wgOut;
|
||||
|
||||
if ( !EmailUserForm::userEmailEnabled() ) {
|
||||
$wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
|
||||
return;
|
||||
}
|
||||
|
||||
$action = $wgRequest->getVal( 'action' );
|
||||
$target = isset($par) ? $par : $wgRequest->getVal( 'target' );
|
||||
$targetUser = EmailUserForm::validateEmailTarget( $target );
|
||||
|
||||
if ( !( $targetUser instanceof User ) ) {
|
||||
$wgOut->showErrorPage( $targetUser[0], $targetUser[1] );
|
||||
$wgOut->showErrorPage( $targetUser.'title', $targetUser.'text' );
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +35,7 @@ function wfSpecialEmailuser( $par ) {
|
|||
|
||||
$error = EmailUserForm::getPermissionsError( $wgUser, $wgRequest->getVal( 'wpEditToken' ) );
|
||||
if ( $error ) {
|
||||
switch ( $error[0] ) {
|
||||
switch ( $error ) {
|
||||
case 'blockedemailuser':
|
||||
$wgOut->blockedPage();
|
||||
return;
|
||||
|
|
@ -40,12 +45,11 @@ function wfSpecialEmailuser( $par ) {
|
|||
case 'sessionfailure':
|
||||
$form->showForm();
|
||||
return;
|
||||
default:
|
||||
$wgOut->showErrorPage( $error[0], $error[1] );
|
||||
case 'mailnologin':
|
||||
$wgOut->showErrorPage( 'mailnologin', 'mailnologintext' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( "submit" == $action && $wgRequest->wasPosted() ) {
|
||||
$result = $form->doSubmit();
|
||||
|
|
@ -228,27 +232,27 @@ class EmailUserForm {
|
|||
return $this->target;
|
||||
}
|
||||
|
||||
static function validateEmailTarget ( $target ) {
|
||||
static function userEmailEnabled() {
|
||||
global $wgEnableEmail, $wgEnableUserEmail;
|
||||
|
||||
if( !( $wgEnableEmail && $wgEnableUserEmail ) )
|
||||
return array( "nosuchspecialpage", "nospecialpagetext" );
|
||||
return $wgEnableEmail && $wgEnableEmail;
|
||||
|
||||
}
|
||||
static function validateEmailTarget ( $target ) {
|
||||
if ( "" == $target ) {
|
||||
wfDebug( "Target is empty.\n" );
|
||||
return array( "notargettitle", "notargettext" );
|
||||
return "notarget";
|
||||
}
|
||||
|
||||
$nt = Title::newFromURL( $target );
|
||||
if ( is_null( $nt ) ) {
|
||||
wfDebug( "Target is invalid title.\n" );
|
||||
return array( "notargettitle", "notargettext" );
|
||||
return "notarget";
|
||||
}
|
||||
|
||||
$nu = User::newFromName( $nt->getText() );
|
||||
if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
|
||||
wfDebug( "Target is invalid user or can't receive.\n" );
|
||||
return array( "noemailtitle", "noemailtext" );
|
||||
return "noemail";
|
||||
}
|
||||
|
||||
return $nu;
|
||||
|
|
@ -256,22 +260,22 @@ class EmailUserForm {
|
|||
static function getPermissionsError ( $user, $editToken ) {
|
||||
if( !$user->canSendEmail() ) {
|
||||
wfDebug( "User can't send.\n" );
|
||||
return array( "mailnologin", "mailnologintext" );
|
||||
return "mailnologin";
|
||||
}
|
||||
|
||||
if( $user->isBlockedFromEmailuser() ) {
|
||||
wfDebug( "User is blocked from sending e-mail.\n" );
|
||||
return array( "blockedemailuser", "" );
|
||||
return "blockedemailuser";
|
||||
}
|
||||
|
||||
if( $user->pingLimiter( 'emailuser' ) ) {
|
||||
wfDebug( "Ping limiter triggered.\n" );
|
||||
return array( 'actionthrottledtext', '' );
|
||||
return 'actionthrottledtext';
|
||||
}
|
||||
|
||||
if( !$user->matchEditToken( $editToken ) ) {
|
||||
wfDebug( "Matching edit token failed.\n" );
|
||||
return array( 'sessionfailure', '' );
|
||||
return 'sessionfailure';
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue