# Mail a temporary password to the dirty address.
# User can come back through the confirmation URL to re-enable email.
$result = $wgUser->sendConfirmationMail( $oldaddr != '' );
- if ( WikiError::isError( $result ) ) {
- return wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
+ if ( !$result->isGood() ) {
+ return htmlspecialchars( $result->getWikiText( 'mailerror' ) );
} elseif ( $entryPoint == 'ui' ) {
$result = 'eauth';
}
}
return false;
}
+
+ /**
+ * Backward compatibility function for WikiError -> Status migration
+ *
+ * @return String
+ */
+ public function getMessage() {
+ return $this->getWikiText();
+ }
}
* mail to the user's given address.
*
* @param $changed Boolean: whether the adress changed
- * @return \types{\bool,\type{WikiError}} True on success, a WikiError object on failure.
+ * @return Status object
*/
function sendConfirmationMail( $changed = false ) {
global $wgLang;
* @param $body \string Message body
* @param $from \string Optional From address; if unspecified, default $wgPasswordSender will be used
* @param $replyto \string Reply-To address
- * @return \types{\bool,\type{WikiError}} True on success, a WikiError object on failure
+ * @return Status object
*/
function sendMail( $subject, $body, $from = null, $replyto = null ) {
if( is_null( $from ) ) {
# Based on the result return an error string,
if( PEAR::isError( $mailResult ) ) {
wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" );
- return new WikiError( $mailResult->getMessage() );
+ return Status::newFatal( 'pear-mail-error', $mailResult->getMessage() );
} else {
- return true;
+ return Status::newGood();
}
}
* @param $body String: email's text.
* @param $replyto MailAddress: optional reply-to email (default: null).
* @param $contentType String: optional custom Content-Type
- * @return mixed True on success, a WikiError object on failure.
+ * @return Status object
*/
static function send( $to, $from, $subject, $body, $replyto=null, $contentType=null ) {
global $wgSMTP, $wgOutputEncoding, $wgEnotifImpersonal;
if( PEAR::isError( $mail_object ) ) {
wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
wfRestoreWarnings();
- return new WikiError( $mail_object->getMessage() );
+ return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() );
}
wfDebug( "Sending mail via PEAR::Mail to $dest\n" );
$chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips );
foreach ($chunks as $chunk) {
- $e = self::sendWithPear($mail_object, $chunk, $headers, $body);
- if( WikiError::isError( $e ) ) {
+ $status = self::sendWithPear($mail_object, $chunk, $headers, $body);
+ if( !$status->isOK() ) {
wfRestoreWarnings();
- return $e;
+ return $status;
}
}
wfRestoreWarnings();
+ return Status::newGood();
} else {
# In the following $headers = expression we removed "Reply-To: {$from}\r\n" , because it is treated differently
# (fifth parameter of the PHP mail function, see some lines below)
if ( self::$mErrorString ) {
wfDebug( "Error sending mail: " . self::$mErrorString . "\n" );
- return new WikiError( self::$mErrorString );
+ return Status::newFatal( 'php-mail-error', self::$mErrorString );
} elseif (! $sent ) {
//mail function only tells if there's an error
wfDebug( "Error sending mail\n" );
- return new WikiError( 'mail() failed' );
+ return Status::newFatal( 'php-mail-error-unknown' );
} else {
- return true;
+ return Status::newGood();
}
}
}
* @return bool
*/
public static function isError( $object ) {
- return $object instanceof WikiError;
+ if ( $object instanceof WikiError ) {
+ return true;
+ } elseif ( $object instanceof Status ) {
+ return !$object->isOK();
+ } else {
+ return false;
+ }
}
}
function showRequestForm() {
global $wgOut, $wgUser, $wgLang, $wgRequest;
if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
- $ok = $wgUser->sendConfirmationMail();
- if ( WikiError::isError( $ok ) ) {
- $wgOut->addWikiMsg( 'confirmemail_sendfailed', $ok->toString() );
- } else {
+ $status = $wgUser->sendConfirmationMail();
+ if ( $status->isGood() ) {
$wgOut->addWikiMsg( 'confirmemail_sent' );
+ } else {
+ $wgOut->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
}
} else {
if( $wgUser->isEmailConfirmed() ) {
$wgOut->setPagetitle( wfMsg( 'emailpage' ) );
$result = $form->show();
- if( $result === true ){
+ if( $result === true || ( $result instanceof Status && $result->isGood() ) ){
$wgOut->setPagetitle( wfMsg( 'emailsent' ) );
$wgOut->addWikiMsg( 'emailsenttext' );
$wgOut->returnToMain( false, $this->mTargetObj->getUserPage() );
$replyTo = null;
}
- $mailResult = UserMailer::send( $to, $mailFrom, $subject, $text, $replyTo );
+ $status = UserMailer::send( $to, $mailFrom, $subject, $text, $replyTo );
- if( WikiError::isError( $mailResult ) && false ) {
- return $mailResult->getMessage();
+ if( !$status->isGood() && false ) {
+ return $status;
} else {
// if the user requested a copy of this mail, do this now,
// unless they are emailing themselves, in which case one
$subject
);
wfRunHooks( 'EmailUserCC', array( &$from, &$from, &$cc_subject, &$text ) );
- $ccResult = UserMailer::send( $from, $from, $cc_subject, $text );
- if( WikiError::isError( $ccResult ) ) {
- // At this stage, the user's CC mail has failed, but their
- // original mail has succeeded. It's unlikely, but still,
- // what to do? We can either show them an error, or we can
- // say everything was fine, or we can say we sort of failed
- // AND sort of succeeded. Of these options, simply saying
- // there was an error is probably best.
- return $ccResult->getMessage();
- }
+ $ccStatus = UserMailer::send( $from, $from, $cc_subject, $text );
+ $status->merge( $ccStatus );
}
wfRunHooks( 'EmailUserComplete', array( $to, $from, $subject, $text ) );
- return true;
+ return $status;
}
}
}
$wgOut->setRobotPolicy( 'noindex,nofollow' );
$wgOut->setArticleRelated( false );
- if( WikiError::isError( $result ) ) {
- $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
+ if( !$result->isGood() ) {
+ $this->mainLoginForm( wfMsg( 'mailerror', $result->getWikiText() ) );
} else {
$wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
$wgOut->returnToMain( false );
# Send out an email authentication message if needed
if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) ) {
- $error = $u->sendConfirmationMail();
- if( WikiError::isError( $error ) ) {
- $wgOut->addWikiMsg( 'confirmemail_sendfailed', $error->getMessage() );
- } else {
+ $status = $u->sendConfirmationMail();
+ if( $status->isGood() ) {
$wgOut->addWikiMsg( 'confirmemail_oncreate' );
+ } else {
+ $wgOut->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
}
}
}
$result = $this->mailPasswordInternal( $u, true, 'passwordremindertitle', 'passwordremindertext' );
- if( WikiError::isError( $result ) ) {
- $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
- } else {
+ if( $result->isGood() ) {
$this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
self::clearLoginToken();
+ } else {
+ $this->mainLoginForm( $result->getWikiText( 'mailerror' ) );
}
}
* @param $throttle Boolean
* @param $emailTitle String: message name of email title
* @param $emailText String: message name of email text
- * @return Mixed: true on success, WikiError on failure
+ * @return Status object
* @private
*/
function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry;
if ( $u->getEmail() == '' ) {
- return new WikiError( wfMsg( 'noemail', $u->getName() ) );
+ return Status::newFatal( 'noemail', $u->getName() );
}
$ip = wfGetIP();
if( !$ip ) {
- return new WikiError( wfMsg( 'badipaddress' ) );
+ return Status::newFatal( 'badipaddress' );
}
wfRunHooks( 'User::mailPasswordInternal', array( &$wgUser, &$ip, &$u ) );
* Nederlands|nl', # do not translate or duplicate this message to other languages
'suspicious-userlogout' => 'Your request to log out was denied because it looks like it was sent by a broken browser or caching proxy.',
+# E-mail sending
+'pear-mail-error' => '$1', # do not translate or duplicate this message to other languages
+'php-mail-error' => '$1', # do not translate or duplicate this message to other languages
+'php-mail-error-unknown' => "Unkown error in PHP's mail() function",
+
# JavaScript password checks
'password-strength' => 'Estimated password strength: $1',
'password-strength-bad' => 'BAD',
'loginstart',
'loginend',
'loginlanguagelinks',
+ 'pear-mail-error',
+ 'php-mail-error',
'markaspatrolledlink',
'newarticletextanon',
'newsectionheaderdefaultlevel',
'loginlanguagelinks',
'suspicious-userlogout',
),
+ 'mail' => array(
+ 'pear-mail-error',
+ 'php-mail-error',
+ 'php-mail-error-unknown',
+ ),
'passwordstrength' => array(
'password-strength',
'password-strength-bad',
'errors' => 'General errors',
'virus' => 'Virus scanner',
'login' => 'Login and logout pages',
+ 'mail' => 'E-mail sending',
'passwordstrength' => 'JavaScript password checks',
'resetpass' => 'Password reset dialog',
'toolbar' => 'Edit page toolbar',