Index: branches/wmf/1.17wmf1/includes/specials/SpecialUserlogin.php |
— | — | @@ -22,24 +22,11 @@ |
23 | 23 | */ |
24 | 24 | |
25 | 25 | /** |
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 | | -/** |
39 | 26 | * Implements Special:UserLogin |
40 | 27 | * |
41 | 28 | * @ingroup SpecialPage |
42 | 29 | */ |
43 | | -class LoginForm { |
| 30 | +class LoginForm extends SpecialPage { |
44 | 31 | |
45 | 32 | const SUCCESS = 0; |
46 | 33 | const NO_NAME = 1; |
— | — | @@ -56,23 +43,42 @@ |
57 | 44 | const NEED_TOKEN = 12; |
58 | 45 | const WRONG_TOKEN = 13; |
59 | 46 | |
60 | | - var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted; |
61 | | - var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword; |
| 47 | + var $mUsername, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted; |
| 48 | + var $mAction, $mCreateaccount, $mCreateaccountMail; |
62 | 49 | var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage; |
63 | 50 | var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS; |
| 51 | + var $mType, $mReason, $mRealName; |
| 52 | + var $mAbortLoginErrorMsg = 'login-abort-generic'; |
64 | 53 | |
| 54 | + /** |
| 55 | + * @var ExternalUser |
| 56 | + */ |
65 | 57 | private $mExtUser = null; |
66 | 58 | |
67 | 59 | /** |
68 | | - * Constructor |
69 | | - * @param $request WebRequest: a WebRequest object passed by reference |
70 | | - * @param $par String: subpage parameter |
| 60 | + * @param WebRequest $request |
71 | 61 | */ |
72 | | - function __construct( &$request, $par = '' ) { |
| 62 | + public function __construct( $request = null ) { |
| 63 | + parent::__construct( 'Userlogin' ); |
| 64 | + |
| 65 | + if ( $request === null ) { |
| 66 | + global $wgRequest; |
| 67 | + $this->load( $wgRequest ); |
| 68 | + } else { |
| 69 | + $this->load( $request ); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Loader |
| 75 | + * |
| 76 | + * @param $request WebRequest object |
| 77 | + */ |
| 78 | + function load( $request ) { |
73 | 79 | global $wgAuth, $wgHiddenPrefs, $wgEnableEmail, $wgRedirectOnLogin; |
74 | 80 | |
75 | | - $this->mType = ( $par == 'signup' ) ? $par : $request->getText( 'type' ); # Check for [[Special:Userlogin/signup]] |
76 | | - $this->mName = $request->getText( 'wpName' ); |
| 81 | + $this->mType = $request->getText( 'type' ); |
| 82 | + $this->mUsername = $request->getText( 'wpName' ); |
77 | 83 | $this->mPassword = $request->getText( 'wpPassword' ); |
78 | 84 | $this->mRetype = $request->getText( 'wpRetype' ); |
79 | 85 | $this->mDomain = $request->getText( 'wpDomain' ); |
— | — | @@ -83,9 +89,7 @@ |
84 | 90 | $this->mPosted = $request->wasPosted(); |
85 | 91 | $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' ); |
86 | 92 | $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' ) |
87 | | - && $wgEnableEmail; |
88 | | - $this->mMailmypassword = $request->getCheck( 'wpMailmypassword' ) |
89 | | - && $wgEnableEmail; |
| 93 | + && $wgEnableEmail; |
90 | 94 | $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' ); |
91 | 95 | $this->mAction = $request->getVal( 'action' ); |
92 | 96 | $this->mRemember = $request->getCheck( 'wpRemember' ); |
— | — | @@ -105,9 +109,9 @@ |
106 | 110 | $this->mEmail = ''; |
107 | 111 | } |
108 | 112 | if( !in_array( 'realname', $wgHiddenPrefs ) ) { |
109 | | - $this->mRealName = $request->getText( 'wpRealName' ); |
| 113 | + $this->mRealName = $request->getText( 'wpRealName' ); |
110 | 114 | } else { |
111 | | - $this->mRealName = ''; |
| 115 | + $this->mRealName = ''; |
112 | 116 | } |
113 | 117 | |
114 | 118 | if( !$wgAuth->validDomain( $this->mDomain ) ) { |
— | — | @@ -123,7 +127,15 @@ |
124 | 128 | } |
125 | 129 | } |
126 | 130 | |
127 | | - function execute() { |
| 131 | + public function execute( $par ) { |
| 132 | + if ( session_id() == '' ) { |
| 133 | + wfSetupSession(); |
| 134 | + } |
| 135 | + |
| 136 | + if ( $par == 'signup' ) { # Check for [[Special:Userlogin/signup]] |
| 137 | + $this->mType = 'signup'; |
| 138 | + } |
| 139 | + |
128 | 140 | if ( !is_null( $this->mCookieCheck ) ) { |
129 | 141 | $this->onCookieRedirectCheck( $this->mCookieCheck ); |
130 | 142 | return; |
— | — | @@ -132,8 +144,6 @@ |
133 | 145 | return $this->addNewAccount(); |
134 | 146 | } elseif ( $this->mCreateaccountMail ) { |
135 | 147 | return $this->addNewAccountMailPassword(); |
136 | | - } elseif ( $this->mMailmypassword ) { |
137 | | - return $this->mailPassword(); |
138 | 148 | } elseif ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) { |
139 | 149 | return $this->processLogin(); |
140 | 150 | } |
— | — | @@ -148,7 +158,7 @@ |
149 | 159 | global $wgOut; |
150 | 160 | |
151 | 161 | if ( $this->mEmail == '' ) { |
152 | | - $this->mainLoginForm( wfMsgExt( 'noemail', array( 'parsemag', 'escape' ), $this->mName ) ); |
| 162 | + $this->mainLoginForm( wfMsgExt( 'noemail', array( 'parsemag', 'escape' ), $this->mUsername ) ); |
153 | 163 | return; |
154 | 164 | } |
155 | 165 | |
— | — | @@ -167,8 +177,6 @@ |
168 | 178 | $u->addNewUserLogEntry( true, $this->mReason ); |
169 | 179 | |
170 | 180 | $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) ); |
171 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
172 | | - $wgOut->setArticleRelated( false ); |
173 | 181 | |
174 | 182 | if( !$result->isGood() ) { |
175 | 183 | $this->mainLoginForm( wfMsg( 'mailerror', $result->getWikiText() ) ); |
— | — | @@ -227,9 +235,7 @@ |
228 | 236 | # Confirm that the account was created |
229 | 237 | $self = SpecialPage::getTitleFor( 'Userlogin' ); |
230 | 238 | $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) ); |
231 | | - $wgOut->setArticleRelated( false ); |
232 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
233 | | - $wgOut->addHTML( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) ); |
| 239 | + $wgOut->addWikiMsg( 'accountcreatedtext', $u->getName() ); |
234 | 240 | $wgOut->returnToMain( false, $self ); |
235 | 241 | wfRunHooks( 'AddNewAccount', array( $u, false ) ); |
236 | 242 | $u->addNewUserLogEntry( false, $this->mReason ); |
— | — | @@ -258,7 +264,8 @@ |
259 | 265 | // create a local account and login as any domain user). We only need |
260 | 266 | // to check this for domains that aren't local. |
261 | 267 | if( 'local' != $this->mDomain && $this->mDomain != '' ) { |
262 | | - if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName ) || !$wgAuth->authenticate( $this->mName, $this->mPassword ) ) ) { |
| 268 | + if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mUsername ) |
| 269 | + || !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) ) { |
263 | 270 | $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); |
264 | 271 | return false; |
265 | 272 | } |
— | — | @@ -272,7 +279,7 @@ |
273 | 280 | # Request forgery checks. |
274 | 281 | if ( !self::getCreateaccountToken() ) { |
275 | 282 | self::setCreateaccountToken(); |
276 | | - $this->mainLoginForm( wfMsgExt( 'nocookiesnew', array( 'parseinline' ) ) ); |
| 283 | + $this->mainLoginForm( wfMsgExt( 'nocookiesfornew', array( 'parseinline' ) ) ); |
277 | 284 | return false; |
278 | 285 | } |
279 | 286 | |
— | — | @@ -293,7 +300,7 @@ |
294 | 301 | $wgOut->permissionRequired( 'createaccount' ); |
295 | 302 | return false; |
296 | 303 | } elseif ( $wgUser->isBlockedFromCreateAccount() ) { |
297 | | - $this->userBlockedMessage(); |
| 304 | + $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() ); |
298 | 305 | return false; |
299 | 306 | } |
300 | 307 | |
— | — | @@ -304,7 +311,7 @@ |
305 | 312 | } |
306 | 313 | |
307 | 314 | # Now create a dummy user ($u) and check if it is valid |
308 | | - $name = trim( $this->mName ); |
| 315 | + $name = trim( $this->mUsername ); |
309 | 316 | $u = User::newFromName( $name, 'creatable' ); |
310 | 317 | if ( !is_object( $u ) ) { |
311 | 318 | $this->mainLoginForm( wfMsg( 'noname' ) ); |
— | — | @@ -325,7 +332,14 @@ |
326 | 333 | $valid = $u->getPasswordValidity( $this->mPassword ); |
327 | 334 | if ( $valid !== true ) { |
328 | 335 | if ( !$this->mCreateaccountMail ) { |
329 | | - $this->mainLoginForm( wfMsgExt( $valid, array( 'parsemag' ), $wgMinimalPasswordLength ) ); |
| 336 | + if ( is_array( $valid ) ) { |
| 337 | + $message = array_shift( $valid ); |
| 338 | + $params = $valid; |
| 339 | + } else { |
| 340 | + $message = $valid; |
| 341 | + $params = array( $wgMinimalPasswordLength ); |
| 342 | + } |
| 343 | + $this->mainLoginForm( wfMsgExt( $message, array( 'parsemag' ), $params ) ); |
330 | 344 | return false; |
331 | 345 | } else { |
332 | 346 | # do not force a password for account creation by email |
— | — | @@ -433,7 +447,7 @@ |
434 | 448 | public function authenticateUserData() { |
435 | 449 | global $wgUser, $wgAuth, $wgMemc; |
436 | 450 | |
437 | | - if ( $this->mName == '' ) { |
| 451 | + if ( $this->mUsername == '' ) { |
438 | 452 | return self::NO_NAME; |
439 | 453 | } |
440 | 454 | |
— | — | @@ -456,7 +470,7 @@ |
457 | 471 | |
458 | 472 | $throttleCount = 0; |
459 | 473 | if ( is_array( $wgPasswordAttemptThrottle ) ) { |
460 | | - $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName ) ); |
| 474 | + $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mUsername ) ); |
461 | 475 | $count = $wgPasswordAttemptThrottle['count']; |
462 | 476 | $period = $wgPasswordAttemptThrottle['seconds']; |
463 | 477 | |
— | — | @@ -481,16 +495,16 @@ |
482 | 496 | // creates the user in the database. Until we load $wgUser, checking |
483 | 497 | // for user existence using User::newFromName($name)->getId() below |
484 | 498 | // will effectively be using stale data. |
485 | | - if ( $wgUser->getName() === $this->mName ) { |
486 | | - wfDebug( __METHOD__ . ": already logged in as {$this->mName}\n" ); |
| 499 | + if ( $wgUser->getName() === $this->mUsername ) { |
| 500 | + wfDebug( __METHOD__ . ": already logged in as {$this->mUsername}\n" ); |
487 | 501 | return self::SUCCESS; |
488 | 502 | } |
489 | 503 | |
490 | | - $this->mExtUser = ExternalUser::newFromName( $this->mName ); |
| 504 | + $this->mExtUser = ExternalUser::newFromName( $this->mUsername ); |
491 | 505 | |
492 | 506 | # TODO: Allow some magic here for invalid external names, e.g., let the |
493 | 507 | # user choose a different wiki name. |
494 | | - $u = User::newFromName( $this->mName ); |
| 508 | + $u = User::newFromName( $this->mUsername ); |
495 | 509 | if( !( $u instanceof User ) || !User::isUsableName( $u->getName() ) ) { |
496 | 510 | return self::ILLEGAL; |
497 | 511 | } |
— | — | @@ -518,7 +532,7 @@ |
519 | 533 | |
520 | 534 | // Give general extensions, such as a captcha, a chance to abort logins |
521 | 535 | $abort = self::ABORTED; |
522 | | - if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword, &$abort ) ) ) { |
| 536 | + if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword, &$abort, &$this->mAbortLoginErrorMsg ) ) ) { |
523 | 537 | return $abort; |
524 | 538 | } |
525 | 539 | |
— | — | @@ -579,6 +593,9 @@ |
580 | 594 | /** |
581 | 595 | * Attempt to automatically create a user on login. Only succeeds if there |
582 | 596 | * is an external authentication method which allows it. |
| 597 | + * |
| 598 | + * @param $user User |
| 599 | + * |
583 | 600 | * @return integer Status code |
584 | 601 | */ |
585 | 602 | function attemptAutoCreate( $user ) { |
— | — | @@ -618,6 +635,14 @@ |
619 | 636 | } |
620 | 637 | } |
621 | 638 | |
| 639 | + $abortError = ''; |
| 640 | + if( !wfRunHooks( 'AbortAutoAccount', array( $user, &$abortError ) ) ) { |
| 641 | + // Hook point to add extra creation throttles and blocks |
| 642 | + wfDebug( "LoginForm::attemptAutoCreate: a hook blocked creation: $abortError\n" ); |
| 643 | + $this->mAbortLoginErrorMsg = $abortError; |
| 644 | + return self::ABORTED; |
| 645 | + } |
| 646 | + |
622 | 647 | wfDebug( __METHOD__ . ": creating account\n" ); |
623 | 648 | $this->initUser( $user, true ); |
624 | 649 | return self::SUCCESS; |
— | — | @@ -639,7 +664,7 @@ |
640 | 665 | self::clearLoginToken(); |
641 | 666 | |
642 | 667 | // Reset the throttle |
643 | | - $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName ) ); |
| 668 | + $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mUsername ) ); |
644 | 669 | global $wgMemc; |
645 | 670 | $wgMemc->delete( $key ); |
646 | 671 | |
— | — | @@ -657,7 +682,7 @@ |
658 | 683 | break; |
659 | 684 | |
660 | 685 | case self::NEED_TOKEN: |
661 | | - $this->mainLoginForm( wfMsgExt( 'nocookieslogin', array( 'parseinline' ) ) ); |
| 686 | + $this->mainLoginForm( wfMsgExt( 'nocookiesforlogin', array( 'parseinline' ) ) ); |
662 | 687 | break; |
663 | 688 | case self::WRONG_TOKEN: |
664 | 689 | $this->mainLoginForm( wfMsg( 'sessionfailure' ) ); |
— | — | @@ -671,9 +696,9 @@ |
672 | 697 | break; |
673 | 698 | case self::NOT_EXISTS: |
674 | 699 | if( $wgUser->isAllowed( 'createaccount' ) ) { |
675 | | - $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $this->mName ) ) ); |
| 700 | + $this->mainLoginForm( wfMsgExt( 'nosuchuser', 'parseinline', $this->mUsername ) ); |
676 | 701 | } else { |
677 | | - $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mName ) ) ); |
| 702 | + $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mUsername ) ) ); |
678 | 703 | } |
679 | 704 | break; |
680 | 705 | case self::WRONG_PASS: |
— | — | @@ -693,8 +718,11 @@ |
694 | 719 | break; |
695 | 720 | case self::USER_BLOCKED: |
696 | 721 | $this->mainLoginForm( wfMsgExt( 'login-userblocked', |
697 | | - array( 'parsemag', 'escape' ), $this->mName ) ); |
| 722 | + array( 'parsemag', 'escape' ), $this->mUsername ) ); |
698 | 723 | break; |
| 724 | + case self::ABORTED: |
| 725 | + $this->mainLoginForm( wfMsg( $this->mAbortLoginErrorMsg ) ); |
| 726 | + break; |
699 | 727 | default: |
700 | 728 | throw new MWException( 'Unhandled case value' ); |
701 | 729 | } |
— | — | @@ -703,100 +731,11 @@ |
704 | 732 | function resetLoginForm( $error ) { |
705 | 733 | global $wgOut; |
706 | 734 | $wgOut->addHTML( Xml::element('p', array( 'class' => 'error' ), $error ) ); |
707 | | - $reset = new SpecialResetpass(); |
| 735 | + $reset = new SpecialChangePassword(); |
708 | 736 | $reset->execute( null ); |
709 | 737 | } |
710 | 738 | |
711 | 739 | /** |
712 | | - * @private |
713 | | - */ |
714 | | - function mailPassword() { |
715 | | - global $wgUser, $wgOut, $wgAuth; |
716 | | - |
717 | | - if ( wfReadOnly() ) { |
718 | | - $wgOut->readOnlyPage(); |
719 | | - return false; |
720 | | - } |
721 | | - |
722 | | - if( !$wgAuth->allowPasswordChange() ) { |
723 | | - $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) ); |
724 | | - return; |
725 | | - } |
726 | | - |
727 | | - # Check against blocked IPs so blocked users can't flood admins |
728 | | - # with password resets |
729 | | - if( $wgUser->isBlocked() ) { |
730 | | - $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) ); |
731 | | - return; |
732 | | - } |
733 | | - |
734 | | - # Check for hooks |
735 | | - $error = null; |
736 | | - if ( !wfRunHooks( 'UserLoginMailPassword', array( $this->mName, &$error ) ) ) { |
737 | | - $this->mainLoginForm( $error ); |
738 | | - return; |
739 | | - } |
740 | | - |
741 | | - # If the user doesn't have a login token yet, set one. |
742 | | - if ( !self::getLoginToken() ) { |
743 | | - self::setLoginToken(); |
744 | | - $this->mainLoginForm( wfMsg( 'sessionfailure' ) ); |
745 | | - return; |
746 | | - } |
747 | | - |
748 | | - # If the user didn't pass a login token, tell them we need one |
749 | | - if ( !$this->mToken ) { |
750 | | - $this->mainLoginForm( wfMsg( 'sessionfailure' ) ); |
751 | | - return; |
752 | | - } |
753 | | - |
754 | | - # Check against the rate limiter |
755 | | - if( $wgUser->pingLimiter( 'mailpassword' ) ) { |
756 | | - $wgOut->rateLimited(); |
757 | | - return; |
758 | | - } |
759 | | - |
760 | | - if ( $this->mName == '' ) { |
761 | | - $this->mainLoginForm( wfMsg( 'noname' ) ); |
762 | | - return; |
763 | | - } |
764 | | - $u = User::newFromName( $this->mName ); |
765 | | - if( !$u instanceof User ) { |
766 | | - $this->mainLoginForm( wfMsg( 'noname' ) ); |
767 | | - return; |
768 | | - } |
769 | | - if ( 0 == $u->getID() ) { |
770 | | - $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $u->getName() ) ) ); |
771 | | - return; |
772 | | - } |
773 | | - |
774 | | - # Validate the login token |
775 | | - if ( $this->mToken !== self::getLoginToken() ) { |
776 | | - $this->mainLoginForm( wfMsg( 'sessionfailure' ) ); |
777 | | - return; |
778 | | - } |
779 | | - |
780 | | - # Check against password throttle |
781 | | - if ( $u->isPasswordReminderThrottled() ) { |
782 | | - global $wgPasswordReminderResendTime; |
783 | | - # Round the time in hours to 3 d.p., in case someone is specifying |
784 | | - # minutes or seconds. |
785 | | - $this->mainLoginForm( wfMsgExt( 'throttled-mailpassword', array( 'parsemag' ), |
786 | | - round( $wgPasswordReminderResendTime, 3 ) ) ); |
787 | | - return; |
788 | | - } |
789 | | - |
790 | | - $result = $this->mailPasswordInternal( $u, true, 'passwordremindertitle', 'passwordremindertext' ); |
791 | | - if( $result->isGood() ) { |
792 | | - $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' ); |
793 | | - self::clearLoginToken(); |
794 | | - } else { |
795 | | - $this->mainLoginForm( $result->getWikiText( 'mailerror' ) ); |
796 | | - } |
797 | | - } |
798 | | - |
799 | | - |
800 | | - /** |
801 | 740 | * @param $u User object |
802 | 741 | * @param $throttle Boolean |
803 | 742 | * @param $emailTitle String: message name of email title |
— | — | @@ -872,9 +811,14 @@ |
873 | 812 | global $wgUser; |
874 | 813 | # Run any hooks; display injected HTML |
875 | 814 | $injected_html = ''; |
| 815 | + $welcome_creation_msg = 'welcomecreation'; |
| 816 | + |
876 | 817 | wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) ); |
877 | | - |
878 | | - $this->displaySuccessfulLogin( 'welcomecreation', $injected_html ); |
| 818 | + |
| 819 | + //let any extensions change what message is shown |
| 820 | + wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) ); |
| 821 | + |
| 822 | + $this->displaySuccessfulLogin( $welcome_creation_msg, $injected_html ); |
879 | 823 | } |
880 | 824 | |
881 | 825 | /** |
— | — | @@ -884,9 +828,10 @@ |
885 | 829 | global $wgOut, $wgUser; |
886 | 830 | |
887 | 831 | $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) ); |
888 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
889 | | - $wgOut->setArticleRelated( false ); |
890 | | - $wgOut->addWikiMsg( $msgname, $wgUser->getName() ); |
| 832 | + if( $msgname ){ |
| 833 | + $wgOut->addWikiMsg( $msgname, $wgUser->getName() ); |
| 834 | + } |
| 835 | + |
891 | 836 | $wgOut->addHTML( $injected_html ); |
892 | 837 | |
893 | 838 | if ( !empty( $this->mReturnTo ) ) { |
— | — | @@ -896,9 +841,15 @@ |
897 | 842 | } |
898 | 843 | } |
899 | 844 | |
900 | | - /** */ |
901 | | - function userBlockedMessage() { |
902 | | - global $wgOut, $wgUser; |
| 845 | + /** |
| 846 | + * Output a message that informs the user that they cannot create an account because |
| 847 | + * there is a block on them or their IP which prevents account creation. Note that |
| 848 | + * User::isBlockedFromCreateAccount(), which gets this block, ignores the 'hardblock' |
| 849 | + * setting on blocks (bug 13611). |
| 850 | + * @param $block Block the block causing this error |
| 851 | + */ |
| 852 | + function userBlockedMessage( Block $block ) { |
| 853 | + global $wgOut; |
903 | 854 | |
904 | 855 | # Let's be nice about this, it's likely that this feature will be used |
905 | 856 | # for blocking large numbers of innocent people, e.g. range blocks on |
— | — | @@ -909,17 +860,19 @@ |
910 | 861 | # out. |
911 | 862 | |
912 | 863 | $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) ); |
913 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
914 | | - $wgOut->setArticleRelated( false ); |
915 | 864 | |
916 | | - $ip = wfGetIP(); |
917 | | - $blocker = User::whoIs( $wgUser->mBlock->mBy ); |
918 | | - $block_reason = $wgUser->mBlock->mReason; |
919 | | - |
| 865 | + $block_reason = $block->mReason; |
920 | 866 | if ( strval( $block_reason ) === '' ) { |
921 | 867 | $block_reason = wfMsg( 'blockednoreason' ); |
922 | 868 | } |
923 | | - $wgOut->addWikiMsg( 'cantcreateaccount-text', $ip, $block_reason, $blocker ); |
| 869 | + |
| 870 | + $wgOut->addWikiMsg( |
| 871 | + 'cantcreateaccount-text', |
| 872 | + $block->getTarget(), |
| 873 | + $block_reason, |
| 874 | + $block->getBlocker()->getName() |
| 875 | + ); |
| 876 | + |
924 | 877 | $wgOut->returnToMain( false ); |
925 | 878 | } |
926 | 879 | |
— | — | @@ -927,10 +880,11 @@ |
928 | 881 | * @private |
929 | 882 | */ |
930 | 883 | function mainLoginForm( $msg, $msgtype = 'error' ) { |
931 | | - global $wgUser, $wgOut, $wgHiddenPrefs, $wgEnableEmail; |
| 884 | + global $wgUser, $wgOut, $wgHiddenPrefs; |
| 885 | + global $wgEnableEmail, $wgEnableUserEmail; |
932 | 886 | global $wgRequest, $wgLoginLanguageSelector; |
933 | 887 | global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration; |
934 | | - global $wgSecureLogin; |
| 888 | + global $wgSecureLogin, $wgPasswordResetRoutes; |
935 | 889 | |
936 | 890 | $titleObj = SpecialPage::getTitleFor( 'Userlogin' ); |
937 | 891 | |
— | — | @@ -942,7 +896,7 @@ |
943 | 897 | $wgOut->readOnlyPage(); |
944 | 898 | return; |
945 | 899 | } elseif ( $wgUser->isBlockedFromCreateAccount() ) { |
946 | | - $this->userBlockedMessage(); |
| 900 | + $this->userBlockedMessage( $wgUser->isBlockedFromCreateAccount() ); |
947 | 901 | return; |
948 | 902 | } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) { |
949 | 903 | $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' ); |
— | — | @@ -950,11 +904,11 @@ |
951 | 905 | } |
952 | 906 | } |
953 | 907 | |
954 | | - if ( $this->mName == '' ) { |
| 908 | + if ( $this->mUsername == '' ) { |
955 | 909 | if ( $wgUser->isLoggedIn() ) { |
956 | | - $this->mName = $wgUser->getName(); |
| 910 | + $this->mUsername = $wgUser->getName(); |
957 | 911 | } else { |
958 | | - $this->mName = $wgRequest->getCookie( 'UserName' ); |
| 912 | + $this->mUsername = $wgRequest->getCookie( 'UserName' ); |
959 | 913 | } |
960 | 914 | } |
961 | 915 | |
— | — | @@ -996,8 +950,12 @@ |
997 | 951 | $template->set( 'link', '' ); |
998 | 952 | } |
999 | 953 | |
| 954 | + $resetLink = $this->mType == 'signup' |
| 955 | + ? null |
| 956 | + : is_array( $wgPasswordResetRoutes ) && in_array( true, array_values( $wgPasswordResetRoutes ) ); |
| 957 | + |
1000 | 958 | $template->set( 'header', '' ); |
1001 | | - $template->set( 'name', $this->mName ); |
| 959 | + $template->set( 'name', $this->mUsername ); |
1002 | 960 | $template->set( 'password', $this->mPassword ); |
1003 | 961 | $template->set( 'retype', $this->mRetype ); |
1004 | 962 | $template->set( 'email', $this->mEmail ); |
— | — | @@ -1012,7 +970,9 @@ |
1013 | 971 | $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs ) ); |
1014 | 972 | $template->set( 'useemail', $wgEnableEmail ); |
1015 | 973 | $template->set( 'emailrequired', $wgEmailConfirmToEdit ); |
| 974 | + $template->set( 'emailothers', $wgEnableUserEmail ); |
1016 | 975 | $template->set( 'canreset', $wgAuth->allowPasswordChange() ); |
| 976 | + $template->set( 'resetlink', $resetLink ); |
1017 | 977 | $template->set( 'canremember', ( $wgCookieExpiration > 0 ) ); |
1018 | 978 | $template->set( 'usereason', $wgUser->isLoggedIn() ); |
1019 | 979 | $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) || $this->mRemember ); |
— | — | @@ -1053,22 +1013,24 @@ |
1054 | 1014 | $wgOut->setPageTitle( wfMsg( 'userloginnocreate' ) ); |
1055 | 1015 | } |
1056 | 1016 | |
1057 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
1058 | | - $wgOut->setArticleRelated( false ); |
1059 | 1017 | $wgOut->disallowUserJs(); // just in case... |
1060 | 1018 | $wgOut->addTemplate( $template ); |
1061 | 1019 | } |
1062 | 1020 | |
1063 | 1021 | /** |
1064 | 1022 | * @private |
| 1023 | + * |
| 1024 | + * @param $user User |
| 1025 | + * |
| 1026 | + * @return Boolean |
1065 | 1027 | */ |
1066 | 1028 | function showCreateOrLoginLink( &$user ) { |
1067 | 1029 | if( $this->mType == 'signup' ) { |
1068 | | - return( true ); |
| 1030 | + return true; |
1069 | 1031 | } elseif( $user->isAllowed( 'createaccount' ) ) { |
1070 | | - return( true ); |
| 1032 | + return true; |
1071 | 1033 | } else { |
1072 | | - return( false ); |
| 1034 | + return false; |
1073 | 1035 | } |
1074 | 1036 | } |
1075 | 1037 | |
— | — | @@ -1186,9 +1148,9 @@ |
1187 | 1149 | function makeLanguageSelector() { |
1188 | 1150 | global $wgLang; |
1189 | 1151 | |
1190 | | - $msg = wfMsgForContent( 'loginlanguagelinks' ); |
1191 | | - if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) { |
1192 | | - $langs = explode( "\n", $msg ); |
| 1152 | + $msg = wfMessage( 'loginlanguagelinks' )->inContentLanguage(); |
| 1153 | + if( !$msg->isBlank() ) { |
| 1154 | + $langs = explode( "\n", $msg->text() ); |
1193 | 1155 | $links = array(); |
1194 | 1156 | foreach( $langs as $lang ) { |
1195 | 1157 | $lang = trim( $lang, '* ' ); |