From fdcb585ba8dd29349de4b11db378699e4d9066ec Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 21 Nov 2011 14:27:22 +0000 Subject: [PATCH] * Use local context to get messages * Refactored SpecialChangeEmail::error() to get the message name and call OutputPage::wrapWikiMsg() instead of having lot of different ways to handle messages (including parsing the message and then escape it, which is really bad) --- includes/specials/SpecialChangeEmail.php | 45 ++++++++++++------------ 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/includes/specials/SpecialChangeEmail.php b/includes/specials/SpecialChangeEmail.php index 62be543eb1..9f03ecfe92 100644 --- a/includes/specials/SpecialChangeEmail.php +++ b/includes/specials/SpecialChangeEmail.php @@ -41,27 +41,22 @@ class SpecialChangeEmail extends UnlistedSpecialPage { */ function execute( $par ) { global $wgAuth; - $this->checkReadOnly(); - $request = $this->getRequest(); - $this->mPassword = $request->getVal( 'wpPassword' ); - $this->mNewEmail = $request->getVal( 'wpNewEmail' ); + $this->checkReadOnly(); $this->setHeaders(); $this->outputHeader(); - $out = $this->getOutput(); - $out->disallowUserJs(); - - $user = $this->getUser(); - if ( !$wgAuth->allowPropChange( 'emailaddress' ) ) { - $this->error( wfMsgExt( 'cannotchangeemail', 'parseinline' ) ); + $this->error( 'cannotchangeemail' ); return; } + $user = $this->getUser(); + $request = $this->getRequest(); + if ( !$request->wasPosted() && !$user->isLoggedIn() ) { - $this->error( wfMsg( 'changeemail-no-info' ) ); + $this->error( 'changeemail-no-info' ); return; } @@ -70,6 +65,12 @@ class SpecialChangeEmail extends UnlistedSpecialPage { return; } + $out = $this->getOutput(); + $out->disallowUserJs(); + + $this->mPassword = $request->getVal( 'wpPassword' ); + $this->mNewEmail = $request->getVal( 'wpNewEmail' ); + if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'token' ) ) ) { @@ -101,7 +102,7 @@ class SpecialChangeEmail extends UnlistedSpecialPage { } protected function error( $msg ) { - $this->getOutput()->addHTML( Xml::element('p', array( 'class' => 'error' ), $msg ) ); + $this->getOutput()->wrapWikiMsg( "

\n$1\n

", $msg ); } protected function showForm() { @@ -109,10 +110,10 @@ class SpecialChangeEmail extends UnlistedSpecialPage { $oldEmailText = $user->getEmail() ? $user->getEmail() - : wfMsg( 'changeemail-none' ); + : $this->msg( 'changeemail-none' )->text(); $this->getOutput()->addHTML( - Xml::fieldset( wfMsg( 'changeemail-header' ) ) . + Xml::fieldset( $this->msg( 'changeemail-header' )->text() ) . Xml::openElement( 'form', array( 'method' => 'post', @@ -120,7 +121,7 @@ class SpecialChangeEmail extends UnlistedSpecialPage { 'id' => 'mw-changeemail-form' ) ) . "\n" . Html::hidden( 'token', $user->getEditToken() ) . "\n" . Html::hidden( 'returnto', $this->getRequest()->getVal( 'returnto' ) ) . "\n" . - wfMsgExt( 'changeemail-text', array( 'parse' ) ) . "\n" . + $this->msg( 'changeemail-text' )->parseAsBlock() . "\n" . Xml::openElement( 'table', array( 'id' => 'mw-changeemail-table' ) ) . "\n" . $this->pretty( array( array( 'wpName', 'username', 'text', $user->getName() ), @@ -131,8 +132,8 @@ class SpecialChangeEmail extends UnlistedSpecialPage { "\n" . "\n" . '' . - Xml::submitButton( wfMsg( 'changeemail-submit' ) ) . - Xml::submitButton( wfMsg( 'changeemail-cancel' ), array( 'name' => 'wpCancel' ) ) . + Xml::submitButton( $this->msg( 'changeemail-submit' )->text() ) . + Xml::submitButton( $this->msg( 'changeemail-cancel' )->text(), array( 'name' => 'wpCancel' ) ) . "\n" . "\n" . Xml::closeElement( 'table' ) . @@ -157,9 +158,9 @@ class SpecialChangeEmail extends UnlistedSpecialPage { $out .= "\n"; $out .= "\t"; if ( $type != 'text' ) { - $out .= Xml::label( wfMsg( $label ), $name ); + $out .= Xml::label( $this->msg( $label )->text(), $name ); } else { - $out .= wfMsgHtml( $label ); + $out .= $this->msg( $label )->escaped(); } $out .= "\n"; $out .= "\t"; @@ -175,18 +176,18 @@ class SpecialChangeEmail extends UnlistedSpecialPage { */ protected function attemptChange( User $user, $pass, $newaddr ) { if ( $newaddr != '' && !Sanitizer::validateEmail( $newaddr ) ) { - $this->error( wfMsgExt( 'invalidemailaddress', 'parseinline' ) ); + $this->error( 'invalidemailaddress' ); return false; } $throttleCount = LoginForm::incLoginThrottle( $user->getName() ); if ( $throttleCount === true ) { - $this->error( wfMsgHtml( 'login-throttled' ) ); + $this->error( 'login-throttled' ); return false; } if ( !$user->checkTemporaryPassword( $pass ) && !$user->checkPassword( $pass ) ) { - $this->error( wfMsgHtml( 'wrongpassword' ) ); + $this->error( 'wrongpassword' ); return false; } -- 2.20.1