r103810 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103809‎ | r103810 | r103811 >
Date:14:27, 21 November 2011
Author:ialex
Status:ok
Tags:
Comment:
* 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)
Modified paths:
  • /trunk/phase3/includes/specials/SpecialChangeEmail.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialChangeEmail.php
@@ -41,27 +41,22 @@
4242 */
4343 function execute( $par ) {
4444 global $wgAuth;
 45+
4546 $this->checkReadOnly();
4647
47 - $request = $this->getRequest();
48 - $this->mPassword = $request->getVal( 'wpPassword' );
49 - $this->mNewEmail = $request->getVal( 'wpNewEmail' );
50 -
5148 $this->setHeaders();
5249 $this->outputHeader();
5350
54 - $out = $this->getOutput();
55 - $out->disallowUserJs();
56 -
57 - $user = $this->getUser();
58 -
5951 if ( !$wgAuth->allowPropChange( 'emailaddress' ) ) {
60 - $this->error( wfMsgExt( 'cannotchangeemail', 'parseinline' ) );
 52+ $this->error( 'cannotchangeemail' );
6153 return;
6254 }
6355
 56+ $user = $this->getUser();
 57+ $request = $this->getRequest();
 58+
6459 if ( !$request->wasPosted() && !$user->isLoggedIn() ) {
65 - $this->error( wfMsg( 'changeemail-no-info' ) );
 60+ $this->error( 'changeemail-no-info' );
6661 return;
6762 }
6863
@@ -70,6 +65,12 @@
7166 return;
7267 }
7368
 69+ $out = $this->getOutput();
 70+ $out->disallowUserJs();
 71+
 72+ $this->mPassword = $request->getVal( 'wpPassword' );
 73+ $this->mNewEmail = $request->getVal( 'wpNewEmail' );
 74+
7475 if ( $request->wasPosted()
7576 && $user->matchEditToken( $request->getVal( 'token' ) ) )
7677 {
@@ -101,7 +102,7 @@
102103 }
103104
104105 protected function error( $msg ) {
105 - $this->getOutput()->addHTML( Xml::element('p', array( 'class' => 'error' ), $msg ) );
 106+ $this->getOutput()->wrapWikiMsg( "<p class='error'>\n$1\n</p>", $msg );
106107 }
107108
108109 protected function showForm() {
@@ -109,10 +110,10 @@
110111
111112 $oldEmailText = $user->getEmail()
112113 ? $user->getEmail()
113 - : wfMsg( 'changeemail-none' );
 114+ : $this->msg( 'changeemail-none' )->text();
114115
115116 $this->getOutput()->addHTML(
116 - Xml::fieldset( wfMsg( 'changeemail-header' ) ) .
 117+ Xml::fieldset( $this->msg( 'changeemail-header' )->text() ) .
117118 Xml::openElement( 'form',
118119 array(
119120 'method' => 'post',
@@ -120,7 +121,7 @@
121122 'id' => 'mw-changeemail-form' ) ) . "\n" .
122123 Html::hidden( 'token', $user->getEditToken() ) . "\n" .
123124 Html::hidden( 'returnto', $this->getRequest()->getVal( 'returnto' ) ) . "\n" .
124 - wfMsgExt( 'changeemail-text', array( 'parse' ) ) . "\n" .
 125+ $this->msg( 'changeemail-text' )->parseAsBlock() . "\n" .
125126 Xml::openElement( 'table', array( 'id' => 'mw-changeemail-table' ) ) . "\n" .
126127 $this->pretty( array(
127128 array( 'wpName', 'username', 'text', $user->getName() ),
@@ -131,8 +132,8 @@
132133 "<tr>\n" .
133134 "<td></td>\n" .
134135 '<td class="mw-input">' .
135 - Xml::submitButton( wfMsg( 'changeemail-submit' ) ) .
136 - Xml::submitButton( wfMsg( 'changeemail-cancel' ), array( 'name' => 'wpCancel' ) ) .
 136+ Xml::submitButton( $this->msg( 'changeemail-submit' )->text() ) .
 137+ Xml::submitButton( $this->msg( 'changeemail-cancel' )->text(), array( 'name' => 'wpCancel' ) ) .
137138 "</td>\n" .
138139 "</tr>\n" .
139140 Xml::closeElement( 'table' ) .
@@ -157,9 +158,9 @@
158159 $out .= "<tr>\n";
159160 $out .= "\t<td class='mw-label'>";
160161 if ( $type != 'text' ) {
161 - $out .= Xml::label( wfMsg( $label ), $name );
 162+ $out .= Xml::label( $this->msg( $label )->text(), $name );
162163 } else {
163 - $out .= wfMsgHtml( $label );
 164+ $out .= $this->msg( $label )->escaped();
164165 }
165166 $out .= "</td>\n";
166167 $out .= "\t<td class='mw-input'>";
@@ -175,18 +176,18 @@
176177 */
177178 protected function attemptChange( User $user, $pass, $newaddr ) {
178179 if ( $newaddr != '' && !Sanitizer::validateEmail( $newaddr ) ) {
179 - $this->error( wfMsgExt( 'invalidemailaddress', 'parseinline' ) );
 180+ $this->error( 'invalidemailaddress' );
180181 return false;
181182 }
182183
183184 $throttleCount = LoginForm::incLoginThrottle( $user->getName() );
184185 if ( $throttleCount === true ) {
185 - $this->error( wfMsgHtml( 'login-throttled' ) );
 186+ $this->error( 'login-throttled' );
186187 return false;
187188 }
188189
189190 if ( !$user->checkTemporaryPassword( $pass ) && !$user->checkPassword( $pass ) ) {
190 - $this->error( wfMsgHtml( 'wrongpassword' ) );
 191+ $this->error( 'wrongpassword' );
191192 return false;
192193 }
193194

Status & tagging log