From 52cbd588b5a382b39cfab0eabc6cbc39540d0356 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Fri, 15 Jul 2011 20:56:46 +0000 Subject: [PATCH] * Use local context instead of global variables * Call Linker methods satically * Use wfMessage() instead of OutputPage::addWikiMsgArray() with a third parameter --- includes/specials/SpecialConfirmemail.php | 73 ++++++++++------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/includes/specials/SpecialConfirmemail.php b/includes/specials/SpecialConfirmemail.php index b8dfaba97d..70bbfe39b6 100644 --- a/includes/specials/SpecialConfirmemail.php +++ b/includes/specials/SpecialConfirmemail.php @@ -44,31 +44,27 @@ class EmailConfirmation extends UnlistedSpecialPage { * @param $code Confirmation code passed to the page */ function execute( $code ) { - global $wgUser, $wgOut; $this->setHeaders(); if ( wfReadOnly() ) { - $wgOut->readOnlyPage(); - return; + throw new ReadOnlyError; } if( empty( $code ) ) { - if( $wgUser->isLoggedIn() ) { - if( Sanitizer::validateEmail( $wgUser->getEmail() ) ) { + if( $this->getUser()->isLoggedIn() ) { + if( Sanitizer::validateEmail( $this->getUser()->getEmail() ) ) { $this->showRequestForm(); } else { - $wgOut->addWikiMsg( 'confirmemail_noemail' ); + $this->getOutput()->addWikiMsg( 'confirmemail_noemail' ); } } else { - $title = SpecialPage::getTitleFor( 'Userlogin' ); - $skin = $this->getSkin(); - $llink = $skin->linkKnown( - $title, + $llink = Linker::linkKnown( + SpecialPage::getTitleFor( 'Userlogin' ), wfMsgHtml( 'loginreqlink' ), array(), array( 'returnto' => $this->getTitle()->getPrefixedText() ) ); - $wgOut->addWikiMsgArray( 'confirmemail_needlogin', array( $llink ), array( 'replaceafter' ) ); + $this->getOutput()->addHTML( wfMessage( 'confirmemail_needlogin' )->rawParams( $llink )->parse() ); } } else { $this->attemptConfirm( $code ); @@ -79,33 +75,34 @@ class EmailConfirmation extends UnlistedSpecialPage { * Show a nice form for the user to request a confirmation mail */ function showRequestForm() { - global $wgOut, $wgUser, $wgLang, $wgRequest; - if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getText( 'token' ) ) ) { - $status = $wgUser->sendConfirmationMail(); + $user = $this->getUser(); + $out = $this->getOutput(); + if( $this->getRequest()->wasPosted() && $user->matchEditToken( $this->getRequest()->getText( 'token' ) ) ) { + $status = $user->sendConfirmationMail(); if ( $status->isGood() ) { - $wgOut->addWikiMsg( 'confirmemail_sent' ); + $out->addWikiMsg( 'confirmemail_sent' ); } else { - $wgOut->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) ); + $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) ); } } else { - if( $wgUser->isEmailConfirmed() ) { + if( $user->isEmailConfirmed() ) { // date and time are separate parameters to facilitate localisation. // $time is kept for backward compat reasons. // 'emailauthenticated' is also used in SpecialPreferences.php - $time = $wgLang->timeAndDate( $wgUser->mEmailAuthenticated, true ); - $d = $wgLang->date( $wgUser->mEmailAuthenticated, true ); - $t = $wgLang->time( $wgUser->mEmailAuthenticated, true ); - $wgOut->addWikiMsg( 'emailauthenticated', $time, $d, $t ); + $time = $this->getLang()->timeAndDate( $user->mEmailAuthenticated, true ); + $d = $this->getLang()->date( $user->mEmailAuthenticated, true ); + $t = $this->getLang()->time( $user->mEmailAuthenticated, true ); + $out->addWikiMsg( 'emailauthenticated', $time, $d, $t ); } - if( $wgUser->isEmailConfirmationPending() ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", 'confirmemail_pending' ); + if( $user->isEmailConfirmationPending() ) { + $out->wrapWikiMsg( "
\n$1\n
", 'confirmemail_pending' ); } - $wgOut->addWikiMsg( 'confirmemail_text' ); + $out->addWikiMsg( 'confirmemail_text' ); $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalUrl() ) ); - $form .= Html::hidden( 'token', $wgUser->editToken() ); + $form .= Html::hidden( 'token', $user->editToken() ); $form .= Xml::submitButton( wfMsg( 'confirmemail_send' ) ); $form .= Xml::closeElement( 'form' ); - $wgOut->addHTML( $form ); + $out->addHTML( $form ); } } @@ -116,19 +113,18 @@ class EmailConfirmation extends UnlistedSpecialPage { * @param $code Confirmation code */ function attemptConfirm( $code ) { - global $wgUser, $wgOut; $user = User::newFromConfirmationCode( $code ); if( is_object( $user ) ) { $user->confirmEmail(); $user->saveSettings(); - $message = $wgUser->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success'; - $wgOut->addWikiMsg( $message ); - if( !$wgUser->isLoggedIn() ) { + $message = $this->getUser()->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success'; + $this->getOutput()->addWikiMsg( $message ); + if( !$this->getUser()->isLoggedIn() ) { $title = SpecialPage::getTitleFor( 'Userlogin' ); - $wgOut->returnToMain( true, $title ); + $this->getOutput()->returnToMain( true, $title ); } } else { - $wgOut->addWikiMsg( 'confirmemail_invalid' ); + $this->getOutput()->addWikiMsg( 'confirmemail_invalid' ); } } @@ -150,9 +146,7 @@ class EmailInvalidation extends UnlistedSpecialPage { $this->setHeaders(); if ( wfReadOnly() ) { - global $wgOut; - $wgOut->readOnlyPage(); - return; + throw new ReadOnlyError; } $this->attemptInvalidate( $code ); @@ -165,17 +159,16 @@ class EmailInvalidation extends UnlistedSpecialPage { * @param $code Confirmation code */ function attemptInvalidate( $code ) { - global $wgUser, $wgOut; $user = User::newFromConfirmationCode( $code ); if( is_object( $user ) ) { $user->invalidateEmail(); $user->saveSettings(); - $wgOut->addWikiMsg( 'confirmemail_invalidated' ); - if( !$wgUser->isLoggedIn() ) { - $wgOut->returnToMain(); + $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' ); + if( !$this->getUser()->isLoggedIn() ) { + $this->getOutput()->returnToMain(); } } else { - $wgOut->addWikiMsg( 'confirmemail_invalid' ); + $this->getOutput()->addWikiMsg( 'confirmemail_invalid' ); } } } -- 2.20.1