r78224 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78223‎ | r78224 | r78225 >
Date:17:44, 11 December 2010
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
* Converted Special:Userlogin to subclass SpecialPage
* Removed useless calls to $wgOut->setArticleRelated() and $wgOut->setRobotPolicy(), they are already handled by SpecialPage::setHeaders()
Modified paths:
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialResetpass.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -22,24 +22,11 @@
2323 */
2424
2525 /**
26 - * Constructor
27 - */
28 -function wfSpecialUserlogin( $par = '' ) {
29 - global $wgRequest;
30 - if( session_id() == '' ) {
31 - wfSetupSession();
32 - }
33 -
34 - $form = new LoginForm( $wgRequest, $par );
35 - $form->execute();
36 -}
37 -
38 -/**
3926 * Implements Special:UserLogin
4027 *
4128 * @ingroup SpecialPage
4229 */
43 -class LoginForm {
 30+class LoginForm extends SpecialPage {
4431
4532 const SUCCESS = 0;
4633 const NO_NAME = 1;
@@ -59,40 +46,51 @@
6047 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
6148 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
6249 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
63 - var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS;
 50+ var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS, $mRequest;
6451
6552 private $mExtUser = null;
6653
 54+ public function __construct( $request = null ) {
 55+ if ( $request === null ) {
 56+ global $wgRequest;
 57+ $this->mRequest = $wgRequest;
 58+ } else {
 59+ $this->mRequest = $request;
 60+ }
 61+
 62+ parent::__construct( 'Userlogin' );
 63+ }
 64+
6765 /**
68 - * Constructor
69 - * @param $request WebRequest: a WebRequest object passed by reference
 66+ * Loader
 67+ *
7068 * @param $par String: subpage parameter
7169 */
72 - function __construct( &$request, $par = '' ) {
 70+ function load( $par ) {
7371 global $wgAuth, $wgHiddenPrefs, $wgEnableEmail, $wgRedirectOnLogin;
7472
75 - $this->mType = ( $par == 'signup' ) ? $par : $request->getText( 'type' ); # Check for [[Special:Userlogin/signup]]
76 - $this->mName = $request->getText( 'wpName' );
77 - $this->mPassword = $request->getText( 'wpPassword' );
78 - $this->mRetype = $request->getText( 'wpRetype' );
79 - $this->mDomain = $request->getText( 'wpDomain' );
80 - $this->mReason = $request->getText( 'wpReason' );
81 - $this->mReturnTo = $request->getVal( 'returnto' );
82 - $this->mReturnToQuery = $request->getVal( 'returntoquery' );
83 - $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
84 - $this->mPosted = $request->wasPosted();
85 - $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' );
86 - $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' )
 73+ $this->mType = ( $par == 'signup' ) ? $par : $this->mRequest->getText( 'type' ); # Check for [[Special:Userlogin/signup]]
 74+ $this->mName = $this->mRequest->getText( 'wpName' );
 75+ $this->mPassword = $this->mRequest->getText( 'wpPassword' );
 76+ $this->mRetype = $this->mRequest->getText( 'wpRetype' );
 77+ $this->mDomain = $this->mRequest->getText( 'wpDomain' );
 78+ $this->mReason = $this->mRequest->getText( 'wpReason' );
 79+ $this->mReturnTo = $this->mRequest->getVal( 'returnto' );
 80+ $this->mReturnToQuery = $this->mRequest->getVal( 'returntoquery' );
 81+ $this->mCookieCheck = $this->mRequest->getVal( 'wpCookieCheck' );
 82+ $this->mPosted = $this->mRequest->wasPosted();
 83+ $this->mCreateaccount = $this->mRequest->getCheck( 'wpCreateaccount' );
 84+ $this->mCreateaccountMail = $this->mRequest->getCheck( 'wpCreateaccountMail' )
8785 && $wgEnableEmail;
88 - $this->mMailmypassword = $request->getCheck( 'wpMailmypassword' )
 86+ $this->mMailmypassword = $this->mRequest->getCheck( 'wpMailmypassword' )
8987 && $wgEnableEmail;
90 - $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
91 - $this->mAction = $request->getVal( 'action' );
92 - $this->mRemember = $request->getCheck( 'wpRemember' );
93 - $this->mStickHTTPS = $request->getCheck( 'wpStickHTTPS' );
94 - $this->mLanguage = $request->getText( 'uselang' );
95 - $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
96 - $this->mToken = ( $this->mType == 'signup' ) ? $request->getVal( 'wpCreateaccountToken' ) : $request->getVal( 'wpLoginToken' );
 88+ $this->mLoginattempt = $this->mRequest->getCheck( 'wpLoginattempt' );
 89+ $this->mAction = $this->mRequest->getVal( 'action' );
 90+ $this->mRemember = $this->mRequest->getCheck( 'wpRemember' );
 91+ $this->mStickHTTPS = $this->mRequest->getCheck( 'wpStickHTTPS' );
 92+ $this->mLanguage = $this->mRequest->getText( 'uselang' );
 93+ $this->mSkipCookieCheck = $this->mRequest->getCheck( 'wpSkipCookieCheck' );
 94+ $this->mToken = ( $this->mType == 'signup' ) ? $this->mRequest->getVal( 'wpCreateaccountToken' ) : $this->mRequest->getVal( 'wpLoginToken' );
9795
9896 if ( $wgRedirectOnLogin ) {
9997 $this->mReturnTo = $wgRedirectOnLogin;
@@ -100,12 +98,12 @@
10199 }
102100
103101 if( $wgEnableEmail ) {
104 - $this->mEmail = $request->getText( 'wpEmail' );
 102+ $this->mEmail = $this->mRequest->getText( 'wpEmail' );
105103 } else {
106104 $this->mEmail = '';
107105 }
108106 if( !in_array( 'realname', $wgHiddenPrefs ) ) {
109 - $this->mRealName = $request->getText( 'wpRealName' );
 107+ $this->mRealName = $this->mRequest->getText( 'wpRealName' );
110108 } else {
111109 $this->mRealName = '';
112110 }
@@ -123,7 +121,13 @@
124122 }
125123 }
126124
127 - function execute() {
 125+ public function execute( $par ) {
 126+ if ( session_id() == '' ) {
 127+ wfSetupSession();
 128+ }
 129+
 130+ $this->load( $par );
 131+
128132 if ( !is_null( $this->mCookieCheck ) ) {
129133 $this->onCookieRedirectCheck( $this->mCookieCheck );
130134 return;
@@ -167,8 +171,6 @@
168172 $u->addNewUserLogEntry( true, $this->mReason );
169173
170174 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
171 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
172 - $wgOut->setArticleRelated( false );
173175
174176 if( !$result->isGood() ) {
175177 $this->mainLoginForm( wfMsg( 'mailerror', $result->getWikiText() ) );
@@ -227,8 +229,6 @@
228230 # Confirm that the account was created
229231 $self = SpecialPage::getTitleFor( 'Userlogin' );
230232 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
231 - $wgOut->setArticleRelated( false );
232 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
233233 $wgOut->addHTML( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
234234 $wgOut->returnToMain( false, $self );
235235 wfRunHooks( 'AddNewAccount', array( $u, false ) );
@@ -884,8 +884,6 @@
885885 global $wgOut, $wgUser;
886886
887887 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
888 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
889 - $wgOut->setArticleRelated( false );
890888 $wgOut->addWikiMsg( $msgname, $wgUser->getName() );
891889 $wgOut->addHTML( $injected_html );
892890
@@ -909,8 +907,6 @@
910908 # out.
911909
912910 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
913 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
914 - $wgOut->setArticleRelated( false );
915911
916912 $ip = wfGetIP();
917913 $blocker = User::whoIs( $wgUser->mBlock->mBy );
@@ -1057,8 +1053,6 @@
10581054 $wgOut->setPageTitle( wfMsg( 'userloginnocreate' ) );
10591055 }
10601056
1061 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
1062 - $wgOut->setArticleRelated( false );
10631057 $wgOut->disallowUserJs(); // just in case...
10641058 $wgOut->addTemplate( $template );
10651059 }
Index: trunk/phase3/includes/specials/SpecialResetpass.php
@@ -81,7 +81,7 @@
8282 $data['wpRemember'] = 1;
8383 }
8484 $login = new LoginForm( new FauxRequest( $data, true ) );
85 - $login->execute();
 85+ $login->execute( null );
8686 }
8787 $this->doReturnTo();
8888 } catch( PasswordError $e ) {
Index: trunk/phase3/includes/SpecialPage.php
@@ -116,7 +116,7 @@
117117 'Listredirects' => array( 'SpecialPage', 'Listredirects' ),
118118
119119 # Login/create account
120 - 'Userlogin' => array( 'SpecialPage', 'Userlogin' ),
 120+ 'Userlogin' => 'LoginForm',
121121 'CreateAccount' => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
122122
123123 # Users and rights

Follow-up revisions

RevisionCommit summaryAuthorDate
r78227* Per Ilmari Karonen, fix for r78224: make it work correctly with API...ialex20:07, 11 December 2010

Comments

#Comment by Ilmari Karonen (talk | contribs)   19:32, 11 December 2010

This seems to have broken API login.

#Comment by IAlex (talk | contribs)   20:08, 11 December 2010

Fixed in r78227.

Status & tagging log