'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
public function execute() {
global $wgUser;
+
+ // Check whether email is enabled
+ if ( !EmailUserForm::userEmailEnabled() )
+ $this->dieUsageMsg( array( 'usermaildisabled' ) );
+
$this->getMain()->requestWriteMode();
$params = $this->extractRequestParams();
// 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'] );
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;
}
$error = EmailUserForm::getPermissionsError( $wgUser, $wgRequest->getVal( 'wpEditToken' ) );
if ( $error ) {
- switch ( $error[0] ) {
+ switch ( $error ) {
case 'blockedemailuser':
$wgOut->blockedPage();
return;
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();
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;
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;