r95654 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95653‎ | r95654 | r95655 >
Date:09:44, 29 August 2011
Author:ialex
Status:ok
Tags:
Comment:
Use local context instead of global variables
Modified paths:
  • /trunk/phase3/includes/specials/SpecialChangePassword.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialChangePassword.php
@@ -35,34 +35,35 @@
3636 * Main execution point
3737 */
3838 function execute( $par ) {
39 - global $wgUser, $wgAuth, $wgOut, $wgRequest;
 39+ global $wgAuth;
4040
4141 if ( wfReadOnly() ) {
42 - $wgOut->readOnlyPage();
43 - return;
 42+ throw new ReadOnlyError;
4443 }
4544
46 - $this->mUserName = trim( $wgRequest->getVal( 'wpName' ) );
47 - $this->mOldpass = $wgRequest->getVal( 'wpPassword' );
48 - $this->mNewpass = $wgRequest->getVal( 'wpNewPassword' );
49 - $this->mRetype = $wgRequest->getVal( 'wpRetype' );
50 - $this->mDomain = $wgRequest->getVal( 'wpDomain' );
 45+ $request = $this->getRequest();
 46+ $this->mUserName = trim( $request->getVal( 'wpName' ) );
 47+ $this->mOldpass = $request->getVal( 'wpPassword' );
 48+ $this->mNewpass = $request->getVal( 'wpNewPassword' );
 49+ $this->mRetype = $request->getVal( 'wpRetype' );
 50+ $this->mDomain = $request->getVal( 'wpDomain' );
5151
5252 $this->setHeaders();
5353 $this->outputHeader();
54 - $wgOut->disallowUserJs();
 54+ $this->getOutput()->disallowUserJs();
5555
56 - if( !$wgRequest->wasPosted() && !$wgUser->isLoggedIn() ) {
 56+ $user = $this->getUser();
 57+ if( !$request->wasPosted() && !$user->isLoggedIn() ) {
5758 $this->error( wfMsg( 'resetpass-no-info' ) );
5859 return;
5960 }
6061
61 - if( $wgRequest->wasPosted() && $wgRequest->getBool( 'wpCancel' ) ) {
 62+ if( $request->wasPosted() && $request->getBool( 'wpCancel' ) ) {
6263 $this->doReturnTo();
6364 return;
6465 }
6566
66 - if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
 67+ if( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'token' ) ) ) {
6768 try {
6869 $wgAuth->setDomain( $this->mDomain );
6970 if( !$wgAuth->allowPasswordChange() ) {
@@ -71,8 +72,8 @@
7273 }
7374
7475 $this->attemptReset( $this->mNewpass, $this->mRetype );
75 - $wgOut->addWikiMsg( 'resetpass_success' );
76 - if( !$wgUser->isLoggedIn() ) {
 76+ $this->getOutput()->addWikiMsg( 'resetpass_success' );
 77+ if( !$user->isLoggedIn() ) {
7778 LoginForm::setLoginToken();
7879 $token = LoginForm::getLoginToken();
7980 $data = array(
@@ -81,9 +82,9 @@
8283 'wpDomain' => $this->mDomain,
8384 'wpLoginToken' => $token,
8485 'wpPassword' => $this->mNewpass,
85 - 'returnto' => $wgRequest->getVal( 'returnto' ),
 86+ 'returnto' => $request->getVal( 'returnto' ),
8687 );
87 - if( $wgRequest->getCheck( 'wpRemember' ) ) {
 88+ if( $request->getCheck( 'wpRemember' ) ) {
8889 $data['wpRemember'] = 1;
8990 }
9091 $login = new LoginForm( new FauxRequest( $data, true ) );
@@ -98,36 +99,33 @@
99100 }
100101
101102 function doReturnTo() {
102 - global $wgRequest, $wgOut;
103 - $titleObj = Title::newFromText( $wgRequest->getVal( 'returnto' ) );
 103+ $titleObj = Title::newFromText( $this->getRequest()->getVal( 'returnto' ) );
104104 if ( !$titleObj instanceof Title ) {
105105 $titleObj = Title::newMainPage();
106106 }
107 - $wgOut->redirect( $titleObj->getFullURL() );
 107+ $this->getOutput()->redirect( $titleObj->getFullURL() );
108108 }
109109
110110 function error( $msg ) {
111 - global $wgOut;
112 - $wgOut->addHTML( Xml::element('p', array( 'class' => 'error' ), $msg ) );
 111+ $this->getOutput()->addHTML( Xml::element('p', array( 'class' => 'error' ), $msg ) );
113112 }
114113
115114 function showForm() {
116 - global $wgOut, $wgUser, $wgRequest;
 115+ global $wgCookieExpiration;
117116
118 - $self = $this->getTitle();
 117+ $user = $this->getUser();
119118 if ( !$this->mUserName ) {
120 - $this->mUserName = $wgUser->getName();
 119+ $this->mUserName = $user->getName();
121120 }
122121 $rememberMe = '';
123 - if ( !$wgUser->isLoggedIn() ) {
124 - global $wgCookieExpiration, $wgLang;
 122+ if ( !$user->isLoggedIn() ) {
125123 $rememberMe = '<tr>' .
126124 '<td></td>' .
127125 '<td class="mw-input">' .
128126 Xml::checkLabel(
129 - wfMsgExt( 'remembermypassword', 'parsemag', $wgLang->formatNum( ceil( $wgCookieExpiration / ( 3600 * 24 ) ) ) ),
 127+ wfMsgExt( 'remembermypassword', 'parsemag', $this->getLang()->formatNum( ceil( $wgCookieExpiration / ( 3600 * 24 ) ) ) ),
130128 'wpRemember', 'wpRemember',
131 - $wgRequest->getCheck( 'wpRemember' ) ) .
 129+ $this->getRequest()->getCheck( 'wpRemember' ) ) .
132130 '</td>' .
133131 '</tr>';
134132 $submitMsg = 'resetpass_submit';
@@ -136,17 +134,17 @@
137135 $oldpassMsg = 'oldpassword';
138136 $submitMsg = 'resetpass-submit-loggedin';
139137 }
140 - $wgOut->addHTML(
 138+ $this->getOutput()->addHTML(
141139 Xml::fieldset( wfMsg( 'resetpass_header' ) ) .
142140 Xml::openElement( 'form',
143141 array(
144142 'method' => 'post',
145 - 'action' => $self->getLocalUrl(),
 143+ 'action' => $this->getTitle()->getLocalUrl(),
146144 'id' => 'mw-resetpass-form' ) ) . "\n" .
147 - Html::hidden( 'token', $wgUser->editToken() ) . "\n" .
 145+ Html::hidden( 'token', $user->editToken() ) . "\n" .
148146 Html::hidden( 'wpName', $this->mUserName ) . "\n" .
149147 Html::hidden( 'wpDomain', $this->mDomain ) . "\n" .
150 - Html::hidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) . "\n" .
 148+ Html::hidden( 'returnto', $this->getRequest()->getVal( 'returnto' ) ) . "\n" .
151149 wfMsgExt( 'resetpass_text', array( 'parse' ) ) . "\n" .
152150 Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) ) . "\n" .
153151 $this->pretty( array(

Status & tagging log