Index: trunk/phase3/maintenance/language/messages.inc |
— | — | @@ -463,6 +463,11 @@ |
464 | 464 | 'loginlanguagelinks', |
465 | 465 | 'suspicious-userlogout', |
466 | 466 | ), |
| 467 | + 'mail' => array( |
| 468 | + 'pear-mail-error', |
| 469 | + 'php-mail-error', |
| 470 | + 'php-mail-error-unknown', |
| 471 | + ), |
467 | 472 | 'passwordstrength' => array( |
468 | 473 | 'password-strength', |
469 | 474 | 'password-strength-bad', |
— | — | @@ -3268,6 +3273,7 @@ |
3269 | 3274 | 'errors' => 'General errors', |
3270 | 3275 | 'virus' => 'Virus scanner', |
3271 | 3276 | 'login' => 'Login and logout pages', |
| 3277 | + 'mail' => 'E-mail sending', |
3272 | 3278 | 'passwordstrength' => 'JavaScript password checks', |
3273 | 3279 | 'resetpass' => 'Password reset dialog', |
3274 | 3280 | 'toolbar' => 'Edit page toolbar', |
Index: trunk/phase3/maintenance/language/messageTypes.inc |
— | — | @@ -91,6 +91,8 @@ |
92 | 92 | 'loginstart', |
93 | 93 | 'loginend', |
94 | 94 | 'loginlanguagelinks', |
| 95 | + 'pear-mail-error', |
| 96 | + 'php-mail-error', |
95 | 97 | 'markaspatrolledlink', |
96 | 98 | 'newarticletextanon', |
97 | 99 | 'newsectionheaderdefaultlevel', |
Index: trunk/phase3/includes/User.php |
— | — | @@ -2893,7 +2893,7 @@ |
2894 | 2894 | * mail to the user's given address. |
2895 | 2895 | * |
2896 | 2896 | * @param $changed Boolean: whether the adress changed |
2897 | | - * @return \types{\bool,\type{WikiError}} True on success, a WikiError object on failure. |
| 2897 | + * @return Status object |
2898 | 2898 | */ |
2899 | 2899 | function sendConfirmationMail( $changed = false ) { |
2900 | 2900 | global $wgLang; |
— | — | @@ -2923,7 +2923,7 @@ |
2924 | 2924 | * @param $body \string Message body |
2925 | 2925 | * @param $from \string Optional From address; if unspecified, default $wgPasswordSender will be used |
2926 | 2926 | * @param $replyto \string Reply-To address |
2927 | | - * @return \types{\bool,\type{WikiError}} True on success, a WikiError object on failure |
| 2927 | + * @return Status object |
2928 | 2928 | */ |
2929 | 2929 | function sendMail( $subject, $body, $from = null, $replyto = null ) { |
2930 | 2930 | if( is_null( $from ) ) { |
Index: trunk/phase3/includes/Status.php |
— | — | @@ -299,4 +299,13 @@ |
300 | 300 | } |
301 | 301 | return false; |
302 | 302 | } |
| 303 | + |
| 304 | + /** |
| 305 | + * Backward compatibility function for WikiError -> Status migration |
| 306 | + * |
| 307 | + * @return String |
| 308 | + */ |
| 309 | + public function getMessage() { |
| 310 | + return $this->getWikiText(); |
| 311 | + } |
303 | 312 | } |
Index: trunk/phase3/includes/UserMailer.php |
— | — | @@ -90,9 +90,9 @@ |
91 | 91 | # Based on the result return an error string, |
92 | 92 | if( PEAR::isError( $mailResult ) ) { |
93 | 93 | wfDebug( "PEAR::Mail failed: " . $mailResult->getMessage() . "\n" ); |
94 | | - return new WikiError( $mailResult->getMessage() ); |
| 94 | + return Status::newFatal( 'pear-mail-error', $mailResult->getMessage() ); |
95 | 95 | } else { |
96 | | - return true; |
| 96 | + return Status::newGood(); |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
— | — | @@ -108,7 +108,7 @@ |
109 | 109 | * @param $body String: email's text. |
110 | 110 | * @param $replyto MailAddress: optional reply-to email (default: null). |
111 | 111 | * @param $contentType String: optional custom Content-Type |
112 | | - * @return mixed True on success, a WikiError object on failure. |
| 112 | + * @return Status object |
113 | 113 | */ |
114 | 114 | static function send( $to, $from, $subject, $body, $replyto=null, $contentType=null ) { |
115 | 115 | global $wgSMTP, $wgOutputEncoding, $wgEnotifImpersonal; |
— | — | @@ -179,19 +179,20 @@ |
180 | 180 | if( PEAR::isError( $mail_object ) ) { |
181 | 181 | wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" ); |
182 | 182 | wfRestoreWarnings(); |
183 | | - return new WikiError( $mail_object->getMessage() ); |
| 183 | + return Status::newFatal( 'pear-mail-error', $mail_object->getMessage() ); |
184 | 184 | } |
185 | 185 | |
186 | 186 | wfDebug( "Sending mail via PEAR::Mail to $dest\n" ); |
187 | 187 | $chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips ); |
188 | 188 | foreach ($chunks as $chunk) { |
189 | | - $e = self::sendWithPear($mail_object, $chunk, $headers, $body); |
190 | | - if( WikiError::isError( $e ) ) { |
| 189 | + $status = self::sendWithPear($mail_object, $chunk, $headers, $body); |
| 190 | + if( !$status->isOK() ) { |
191 | 191 | wfRestoreWarnings(); |
192 | | - return $e; |
| 192 | + return $status; |
193 | 193 | } |
194 | 194 | } |
195 | 195 | wfRestoreWarnings(); |
| 196 | + return Status::newGood(); |
196 | 197 | } else { |
197 | 198 | # In the following $headers = expression we removed "Reply-To: {$from}\r\n" , because it is treated differently |
198 | 199 | # (fifth parameter of the PHP mail function, see some lines below) |
— | — | @@ -236,13 +237,13 @@ |
237 | 238 | |
238 | 239 | if ( self::$mErrorString ) { |
239 | 240 | wfDebug( "Error sending mail: " . self::$mErrorString . "\n" ); |
240 | | - return new WikiError( self::$mErrorString ); |
| 241 | + return Status::newFatal( 'php-mail-error', self::$mErrorString ); |
241 | 242 | } elseif (! $sent ) { |
242 | 243 | //mail function only tells if there's an error |
243 | 244 | wfDebug( "Error sending mail\n" ); |
244 | | - return new WikiError( 'mail() failed' ); |
| 245 | + return Status::newFatal( 'php-mail-error-unknown' ); |
245 | 246 | } else { |
246 | | - return true; |
| 247 | + return Status::newGood(); |
247 | 248 | } |
248 | 249 | } |
249 | 250 | } |
Index: trunk/phase3/includes/specials/SpecialUserlogin.php |
— | — | @@ -170,8 +170,8 @@ |
171 | 171 | $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
172 | 172 | $wgOut->setArticleRelated( false ); |
173 | 173 | |
174 | | - if( WikiError::isError( $result ) ) { |
175 | | - $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) ); |
| 174 | + if( !$result->isGood() ) { |
| 175 | + $this->mainLoginForm( wfMsg( 'mailerror', $result->getWikiText() ) ); |
176 | 176 | } else { |
177 | 177 | $wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() ); |
178 | 178 | $wgOut->returnToMain( false ); |
— | — | @@ -199,11 +199,11 @@ |
200 | 200 | |
201 | 201 | # Send out an email authentication message if needed |
202 | 202 | if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) ) { |
203 | | - $error = $u->sendConfirmationMail(); |
204 | | - if( WikiError::isError( $error ) ) { |
205 | | - $wgOut->addWikiMsg( 'confirmemail_sendfailed', $error->getMessage() ); |
| 203 | + $status = $u->sendConfirmationMail(); |
| 204 | + if( $status->isGood() ) { |
| 205 | + $wgOut->addWikiMsg( 'confirmemail_oncreate' ); |
206 | 206 | } else { |
207 | | - $wgOut->addWikiMsg( 'confirmemail_oncreate' ); |
| 207 | + $wgOut->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) ); |
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
— | — | @@ -787,11 +787,11 @@ |
788 | 788 | } |
789 | 789 | |
790 | 790 | $result = $this->mailPasswordInternal( $u, true, 'passwordremindertitle', 'passwordremindertext' ); |
791 | | - if( WikiError::isError( $result ) ) { |
792 | | - $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) ); |
793 | | - } else { |
| 791 | + if( $result->isGood() ) { |
794 | 792 | $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' ); |
795 | 793 | self::clearLoginToken(); |
| 794 | + } else { |
| 795 | + $this->mainLoginForm( $result->getWikiText( 'mailerror' ) ); |
796 | 796 | } |
797 | 797 | } |
798 | 798 | |
— | — | @@ -801,18 +801,18 @@ |
802 | 802 | * @param $throttle Boolean |
803 | 803 | * @param $emailTitle String: message name of email title |
804 | 804 | * @param $emailText String: message name of email text |
805 | | - * @return Mixed: true on success, WikiError on failure |
| 805 | + * @return Status object |
806 | 806 | * @private |
807 | 807 | */ |
808 | 808 | function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) { |
809 | 809 | global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry; |
810 | 810 | |
811 | 811 | if ( $u->getEmail() == '' ) { |
812 | | - return new WikiError( wfMsg( 'noemail', $u->getName() ) ); |
| 812 | + return Status::newFatal( 'noemail', $u->getName() ); |
813 | 813 | } |
814 | 814 | $ip = wfGetIP(); |
815 | 815 | if( !$ip ) { |
816 | | - return new WikiError( wfMsg( 'badipaddress' ) ); |
| 816 | + return Status::newFatal( 'badipaddress' ); |
817 | 817 | } |
818 | 818 | |
819 | 819 | wfRunHooks( 'User::mailPasswordInternal', array( &$wgUser, &$ip, &$u ) ); |
Index: trunk/phase3/includes/specials/SpecialConfirmemail.php |
— | — | @@ -81,11 +81,11 @@ |
82 | 82 | function showRequestForm() { |
83 | 83 | global $wgOut, $wgUser, $wgLang, $wgRequest; |
84 | 84 | if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) { |
85 | | - $ok = $wgUser->sendConfirmationMail(); |
86 | | - if ( WikiError::isError( $ok ) ) { |
87 | | - $wgOut->addWikiMsg( 'confirmemail_sendfailed', $ok->toString() ); |
| 85 | + $status = $wgUser->sendConfirmationMail(); |
| 86 | + if ( $status->isGood() ) { |
| 87 | + $wgOut->addWikiMsg( 'confirmemail_sent' ); |
88 | 88 | } else { |
89 | | - $wgOut->addWikiMsg( 'confirmemail_sent' ); |
| 89 | + $wgOut->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) ); |
90 | 90 | } |
91 | 91 | } else { |
92 | 92 | if( $wgUser->isEmailConfirmed() ) { |
Index: trunk/phase3/includes/specials/SpecialEmailuser.php |
— | — | @@ -142,7 +142,7 @@ |
143 | 143 | $wgOut->setPagetitle( wfMsg( 'emailpage' ) ); |
144 | 144 | $result = $form->show(); |
145 | 145 | |
146 | | - if( $result === true ){ |
| 146 | + if( $result === true || ( $result instanceof Status && $result->isGood() ) ){ |
147 | 147 | $wgOut->setPagetitle( wfMsg( 'emailsent' ) ); |
148 | 148 | $wgOut->addWikiMsg( 'emailsenttext' ); |
149 | 149 | $wgOut->returnToMain( false, $this->mTargetObj->getUserPage() ); |
— | — | @@ -277,10 +277,10 @@ |
278 | 278 | $replyTo = null; |
279 | 279 | } |
280 | 280 | |
281 | | - $mailResult = UserMailer::send( $to, $mailFrom, $subject, $text, $replyTo ); |
| 281 | + $status = UserMailer::send( $to, $mailFrom, $subject, $text, $replyTo ); |
282 | 282 | |
283 | | - if( WikiError::isError( $mailResult ) && false ) { |
284 | | - return $mailResult->getMessage(); |
| 283 | + if( !$status->isGood() && false ) { |
| 284 | + return $status; |
285 | 285 | } else { |
286 | 286 | // if the user requested a copy of this mail, do this now, |
287 | 287 | // unless they are emailing themselves, in which case one |
— | — | @@ -292,20 +292,12 @@ |
293 | 293 | $subject |
294 | 294 | ); |
295 | 295 | wfRunHooks( 'EmailUserCC', array( &$from, &$from, &$cc_subject, &$text ) ); |
296 | | - $ccResult = UserMailer::send( $from, $from, $cc_subject, $text ); |
297 | | - if( WikiError::isError( $ccResult ) ) { |
298 | | - // At this stage, the user's CC mail has failed, but their |
299 | | - // original mail has succeeded. It's unlikely, but still, |
300 | | - // what to do? We can either show them an error, or we can |
301 | | - // say everything was fine, or we can say we sort of failed |
302 | | - // AND sort of succeeded. Of these options, simply saying |
303 | | - // there was an error is probably best. |
304 | | - return $ccResult->getMessage(); |
305 | | - } |
| 296 | + $ccStatus = UserMailer::send( $from, $from, $cc_subject, $text ); |
| 297 | + $status->merge( $ccStatus ); |
306 | 298 | } |
307 | 299 | |
308 | 300 | wfRunHooks( 'EmailUserComplete', array( $to, $from, $subject, $text ) ); |
309 | | - return true; |
| 301 | + return $status; |
310 | 302 | } |
311 | 303 | } |
312 | 304 | } |
Index: trunk/phase3/includes/WikiError.php |
— | — | @@ -60,7 +60,13 @@ |
61 | 61 | * @return bool |
62 | 62 | */ |
63 | 63 | public static function isError( $object ) { |
64 | | - return $object instanceof WikiError; |
| 64 | + if ( $object instanceof WikiError ) { |
| 65 | + return true; |
| 66 | + } elseif ( $object instanceof Status ) { |
| 67 | + return !$object->isOK(); |
| 68 | + } else { |
| 69 | + return false; |
| 70 | + } |
65 | 71 | } |
66 | 72 | } |
67 | 73 | |
Index: trunk/phase3/includes/Preferences.php |
— | — | @@ -1272,8 +1272,8 @@ |
1273 | 1273 | # Mail a temporary password to the dirty address. |
1274 | 1274 | # User can come back through the confirmation URL to re-enable email. |
1275 | 1275 | $result = $wgUser->sendConfirmationMail( $oldaddr != '' ); |
1276 | | - if ( WikiError::isError( $result ) ) { |
1277 | | - return wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) ); |
| 1276 | + if ( !$result->isGood() ) { |
| 1277 | + return htmlspecialchars( $result->getWikiText( 'mailerror' ) ); |
1278 | 1278 | } elseif ( $entryPoint == 'ui' ) { |
1279 | 1279 | $result = 'eauth'; |
1280 | 1280 | } |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -1144,6 +1144,11 @@ |
1145 | 1145 | * Nederlands|nl', # do not translate or duplicate this message to other languages |
1146 | 1146 | 'suspicious-userlogout' => 'Your request to log out was denied because it looks like it was sent by a broken browser or caching proxy.', |
1147 | 1147 | |
| 1148 | +# E-mail sending |
| 1149 | +'pear-mail-error' => '$1', # do not translate or duplicate this message to other languages |
| 1150 | +'php-mail-error' => '$1', # do not translate or duplicate this message to other languages |
| 1151 | +'php-mail-error-unknown' => "Unkown error in PHP's mail() function", |
| 1152 | + |
1148 | 1153 | # JavaScript password checks |
1149 | 1154 | 'password-strength' => 'Estimated password strength: $1', |
1150 | 1155 | 'password-strength-bad' => 'BAD', |