r92305 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92304‎ | r92305 | r92306 >
Date:20:56, 15 July 2011
Author:ialex
Status:ok
Tags:
Comment:
* Use local context instead of global variables
* Call Linker methods satically
* Use wfMessage() instead of OutputPage::addWikiMsgArray() with a third parameter
Modified paths:
  • /trunk/phase3/includes/specials/SpecialConfirmemail.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialConfirmemail.php
@@ -44,31 +44,27 @@
4545 * @param $code Confirmation code passed to the page
4646 */
4747 function execute( $code ) {
48 - global $wgUser, $wgOut;
4948 $this->setHeaders();
5049
5150 if ( wfReadOnly() ) {
52 - $wgOut->readOnlyPage();
53 - return;
 51+ throw new ReadOnlyError;
5452 }
5553
5654 if( empty( $code ) ) {
57 - if( $wgUser->isLoggedIn() ) {
58 - if( Sanitizer::validateEmail( $wgUser->getEmail() ) ) {
 55+ if( $this->getUser()->isLoggedIn() ) {
 56+ if( Sanitizer::validateEmail( $this->getUser()->getEmail() ) ) {
5957 $this->showRequestForm();
6058 } else {
61 - $wgOut->addWikiMsg( 'confirmemail_noemail' );
 59+ $this->getOutput()->addWikiMsg( 'confirmemail_noemail' );
6260 }
6361 } else {
64 - $title = SpecialPage::getTitleFor( 'Userlogin' );
65 - $skin = $this->getSkin();
66 - $llink = $skin->linkKnown(
67 - $title,
 62+ $llink = Linker::linkKnown(
 63+ SpecialPage::getTitleFor( 'Userlogin' ),
6864 wfMsgHtml( 'loginreqlink' ),
6965 array(),
7066 array( 'returnto' => $this->getTitle()->getPrefixedText() )
7167 );
72 - $wgOut->addWikiMsgArray( 'confirmemail_needlogin', array( $llink ), array( 'replaceafter' ) );
 68+ $this->getOutput()->addHTML( wfMessage( 'confirmemail_needlogin' )->rawParams( $llink )->parse() );
7369 }
7470 } else {
7571 $this->attemptConfirm( $code );
@@ -79,33 +75,34 @@
8076 * Show a nice form for the user to request a confirmation mail
8177 */
8278 function showRequestForm() {
83 - global $wgOut, $wgUser, $wgLang, $wgRequest;
84 - if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
85 - $status = $wgUser->sendConfirmationMail();
 79+ $user = $this->getUser();
 80+ $out = $this->getOutput();
 81+ if( $this->getRequest()->wasPosted() && $user->matchEditToken( $this->getRequest()->getText( 'token' ) ) ) {
 82+ $status = $user->sendConfirmationMail();
8683 if ( $status->isGood() ) {
87 - $wgOut->addWikiMsg( 'confirmemail_sent' );
 84+ $out->addWikiMsg( 'confirmemail_sent' );
8885 } else {
89 - $wgOut->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
 86+ $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) );
9087 }
9188 } else {
92 - if( $wgUser->isEmailConfirmed() ) {
 89+ if( $user->isEmailConfirmed() ) {
9390 // date and time are separate parameters to facilitate localisation.
9491 // $time is kept for backward compat reasons.
9592 // 'emailauthenticated' is also used in SpecialPreferences.php
96 - $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated, true );
97 - $d = $wgLang->date( $wgUser->mEmailAuthenticated, true );
98 - $t = $wgLang->time( $wgUser->mEmailAuthenticated, true );
99 - $wgOut->addWikiMsg( 'emailauthenticated', $time, $d, $t );
 93+ $time = $this->getLang()->timeAndDate( $user->mEmailAuthenticated, true );
 94+ $d = $this->getLang()->date( $user->mEmailAuthenticated, true );
 95+ $t = $this->getLang()->time( $user->mEmailAuthenticated, true );
 96+ $out->addWikiMsg( 'emailauthenticated', $time, $d, $t );
10097 }
101 - if( $wgUser->isEmailConfirmationPending() ) {
102 - $wgOut->wrapWikiMsg( "<div class=\"error mw-confirmemail-pending\">\n$1\n</div>", 'confirmemail_pending' );
 98+ if( $user->isEmailConfirmationPending() ) {
 99+ $out->wrapWikiMsg( "<div class=\"error mw-confirmemail-pending\">\n$1\n</div>", 'confirmemail_pending' );
103100 }
104 - $wgOut->addWikiMsg( 'confirmemail_text' );
 101+ $out->addWikiMsg( 'confirmemail_text' );
105102 $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl() ) );
106 - $form .= Html::hidden( 'token', $wgUser->editToken() );
 103+ $form .= Html::hidden( 'token', $user->editToken() );
107104 $form .= Xml::submitButton( wfMsg( 'confirmemail_send' ) );
108105 $form .= Xml::closeElement( 'form' );
109 - $wgOut->addHTML( $form );
 106+ $out->addHTML( $form );
110107 }
111108 }
112109
@@ -116,19 +113,18 @@
117114 * @param $code Confirmation code
118115 */
119116 function attemptConfirm( $code ) {
120 - global $wgUser, $wgOut;
121117 $user = User::newFromConfirmationCode( $code );
122118 if( is_object( $user ) ) {
123119 $user->confirmEmail();
124120 $user->saveSettings();
125 - $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
126 - $wgOut->addWikiMsg( $message );
127 - if( !$wgUser->isLoggedIn() ) {
 121+ $message = $this->getUser()->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
 122+ $this->getOutput()->addWikiMsg( $message );
 123+ if( !$this->getUser()->isLoggedIn() ) {
128124 $title = SpecialPage::getTitleFor( 'Userlogin' );
129 - $wgOut->returnToMain( true, $title );
 125+ $this->getOutput()->returnToMain( true, $title );
130126 }
131127 } else {
132 - $wgOut->addWikiMsg( 'confirmemail_invalid' );
 128+ $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
133129 }
134130 }
135131
@@ -150,9 +146,7 @@
151147 $this->setHeaders();
152148
153149 if ( wfReadOnly() ) {
154 - global $wgOut;
155 - $wgOut->readOnlyPage();
156 - return;
 150+ throw new ReadOnlyError;
157151 }
158152
159153 $this->attemptInvalidate( $code );
@@ -165,17 +159,16 @@
166160 * @param $code Confirmation code
167161 */
168162 function attemptInvalidate( $code ) {
169 - global $wgUser, $wgOut;
170163 $user = User::newFromConfirmationCode( $code );
171164 if( is_object( $user ) ) {
172165 $user->invalidateEmail();
173166 $user->saveSettings();
174 - $wgOut->addWikiMsg( 'confirmemail_invalidated' );
175 - if( !$wgUser->isLoggedIn() ) {
176 - $wgOut->returnToMain();
 167+ $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
 168+ if( !$this->getUser()->isLoggedIn() ) {
 169+ $this->getOutput()->returnToMain();
177170 }
178171 } else {
179 - $wgOut->addWikiMsg( 'confirmemail_invalid' );
 172+ $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
180173 }
181174 }
182175 }

Status & tagging log