10 function wfSpecialUserlogin( $par = '' ) {
12 if( session_id() == '' ) {
16 $form = new LoginForm( $wgRequest, $par );
21 * implements Special:Login
22 * @ingroup SpecialPage
29 const WRONG_PLUGIN_PASS
= 3;
35 const CREATE_BLOCKED
= 9;
37 const USER_BLOCKED
= 11;
39 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
40 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
41 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
42 var $mSkipCookieCheck, $mReturnToQuery;
44 private $mExtUser = null;
48 * @param $request WebRequest: a WebRequest object passed by reference
49 * @param $par String: subpage parameter
51 function LoginForm( &$request, $par = '' ) {
52 global $wgAuth, $wgHiddenPrefs, $wgEnableEmail, $wgRedirectOnLogin;
54 $this->mType
= ( $par == 'signup' ) ?
$par : $request->getText( 'type' ); # Check for [[Special:Userlogin/signup]]
55 $this->mName
= $request->getText( 'wpName' );
56 $this->mPassword
= $request->getText( 'wpPassword' );
57 $this->mRetype
= $request->getText( 'wpRetype' );
58 $this->mDomain
= $request->getText( 'wpDomain' );
59 $this->mReturnTo
= $request->getVal( 'returnto' );
60 $this->mReturnToQuery
= $request->getVal( 'returntoquery' );
61 $this->mCookieCheck
= $request->getVal( 'wpCookieCheck' );
62 $this->mPosted
= $request->wasPosted();
63 $this->mCreateaccount
= $request->getCheck( 'wpCreateaccount' );
64 $this->mCreateaccountMail
= $request->getCheck( 'wpCreateaccountMail' )
66 $this->mMailmypassword
= $request->getCheck( 'wpMailmypassword' )
68 $this->mLoginattempt
= $request->getCheck( 'wpLoginattempt' );
69 $this->mAction
= $request->getVal( 'action' );
70 $this->mRemember
= $request->getCheck( 'wpRemember' );
71 $this->mLanguage
= $request->getText( 'uselang' );
72 $this->mSkipCookieCheck
= $request->getCheck( 'wpSkipCookieCheck' );
74 if ( $wgRedirectOnLogin ) {
75 $this->mReturnTo
= $wgRedirectOnLogin;
76 $this->mReturnToQuery
= '';
79 if( $wgEnableEmail ) {
80 $this->mEmail
= $request->getText( 'wpEmail' );
84 if( !in_array( 'realname', $wgHiddenPrefs ) ) {
85 $this->mRealName
= $request->getText( 'wpRealName' );
87 $this->mRealName
= '';
90 if( !$wgAuth->validDomain( $this->mDomain
) ) {
91 $this->mDomain
= 'invaliddomain';
93 $wgAuth->setDomain( $this->mDomain
);
95 # When switching accounts, it sucks to get automatically logged out
96 $returnToTitle = Title
::newFromText( $this->mReturnTo
);
97 if( is_object( $returnToTitle ) && $returnToTitle->isSpecial( 'Userlogout' ) ) {
98 $this->mReturnTo
= '';
99 $this->mReturnToQuery
= '';
104 if ( !is_null( $this->mCookieCheck
) ) {
105 $this->onCookieRedirectCheck( $this->mCookieCheck
);
107 } else if( $this->mPosted
) {
108 if( $this->mCreateaccount
) {
109 return $this->addNewAccount();
110 } else if ( $this->mCreateaccountMail
) {
111 return $this->addNewAccountMailPassword();
112 } else if ( $this->mMailmypassword
) {
113 return $this->mailPassword();
114 } else if ( ( 'submitlogin' == $this->mAction
) ||
$this->mLoginattempt
) {
115 return $this->processLogin();
118 $this->mainLoginForm( '' );
124 function addNewAccountMailPassword() {
127 if ( $this->mEmail
== '' ) {
128 $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName
) ) );
132 $u = $this->addNewaccountInternal();
138 // Wipe the initial password and mail a temporary one
139 $u->setPassword( null );
141 $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
143 wfRunHooks( 'AddNewAccount', array( $u, true ) );
144 $u->addNewUserLogEntry();
146 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
147 $wgOut->setRobotPolicy( 'noindex,nofollow' );
148 $wgOut->setArticleRelated( false );
150 if( WikiError
::isError( $result ) ) {
151 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
153 $wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
154 $wgOut->returnToMain( false );
163 function addNewAccount() {
164 global $wgUser, $wgEmailAuthentication;
166 # Create the account and abort if there's a problem doing so
167 $u = $this->addNewAccountInternal();
171 # If we showed up language selection links, and one was in use, be
172 # smart (and sensible) and save that language as the user's preference
173 global $wgLoginLanguageSelector;
174 if( $wgLoginLanguageSelector && $this->mLanguage
)
175 $u->setOption( 'language', $this->mLanguage
);
177 # Send out an email authentication message if needed
178 if( $wgEmailAuthentication && User
::isValidEmailAddr( $u->getEmail() ) ) {
180 $error = $u->sendConfirmationMail();
181 if( WikiError
::isError( $error ) ) {
182 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $error->getMessage() );
184 $wgOut->addWikiMsg( 'confirmemail_oncreate' );
188 # Save settings (including confirmation token)
191 # If not logged in, assume the new account as the current one and set
192 # session cookies then show a "welcome" message or a "need cookies"
194 if( $wgUser->isAnon() ) {
196 $wgUser->setCookies();
197 wfRunHooks( 'AddNewAccount', array( $wgUser, false ) );
198 $wgUser->addNewUserLogEntry();
199 if( $this->hasSessionCookie() ) {
200 return $this->successfulCreation();
202 return $this->cookieRedirectCheck( 'new' );
205 # Confirm that the account was created
207 $self = SpecialPage
::getTitleFor( 'Userlogin' );
208 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
209 $wgOut->setArticleRelated( false );
210 $wgOut->setRobotPolicy( 'noindex,nofollow' );
211 $wgOut->addHTML( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
212 $wgOut->returnToMain( false, $self );
213 wfRunHooks( 'AddNewAccount', array( $u, false ) );
214 $u->addNewUserLogEntry();
222 function addNewAccountInternal() {
223 global $wgUser, $wgOut;
224 global $wgMemc, $wgAccountCreationThrottle;
225 global $wgAuth, $wgMinimalPasswordLength;
226 global $wgEmailConfirmToEdit;
228 // If the user passes an invalid domain, something is fishy
229 if( !$wgAuth->validDomain( $this->mDomain
) ) {
230 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
234 // If we are not allowing users to login locally, we should be checking
235 // to see if the user is actually able to authenticate to the authenti-
236 // cation server before they create an account (otherwise, they can
237 // create a local account and login as any domain user). We only need
238 // to check this for domains that aren't local.
239 if( 'local' != $this->mDomain
&& $this->mDomain
!= '' ) {
240 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName
) ||
!$wgAuth->authenticate( $this->mName
, $this->mPassword
) ) ) {
241 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
246 if ( wfReadOnly() ) {
247 $wgOut->readOnlyPage();
252 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
253 $this->userNotPrivilegedMessage();
255 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
256 $this->userBlockedMessage();
261 if ( $wgUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) {
262 $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
266 # Now create a dummy user ($u) and check if it is valid
267 $name = trim( $this->mName
);
268 $u = User
::newFromName( $name, 'creatable' );
269 if ( !is_object( $u ) ) {
270 $this->mainLoginForm( wfMsg( 'noname' ) );
274 if ( 0 != $u->idForName() ) {
275 $this->mainLoginForm( wfMsg( 'userexists' ) );
279 if ( 0 != strcmp( $this->mPassword
, $this->mRetype
) ) {
280 $this->mainLoginForm( wfMsg( 'badretype' ) );
284 # check for minimal password length
285 $valid = $u->getPasswordValidity( $this->mPassword
);
286 if ( $valid !== true ) {
287 if ( !$this->mCreateaccountMail
) {
288 $this->mainLoginForm( wfMsgExt( $valid, array( 'parsemag' ), $wgMinimalPasswordLength ) );
291 # do not force a password for account creation by email
292 # set invalid password, it will be replaced later by a random generated password
293 $this->mPassword
= null;
297 # if you need a confirmed email address to edit, then obviously you
298 # need an email address.
299 if ( $wgEmailConfirmToEdit && empty( $this->mEmail
) ) {
300 $this->mainLoginForm( wfMsg( 'noemailtitle' ) );
304 if( !empty( $this->mEmail
) && !User
::isValidEmailAddr( $this->mEmail
) ) {
305 $this->mainLoginForm( wfMsg( 'invalidemailaddress' ) );
309 # Set some additional data so the AbortNewAccount hook can be used for
310 # more than just username validation
311 $u->setEmail( $this->mEmail
);
312 $u->setRealName( $this->mRealName
);
315 if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
316 // Hook point to add extra creation throttles and blocks
317 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
318 $this->mainLoginForm( $abortError );
322 if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) {
323 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
324 $value = $wgMemc->get( $key );
326 $wgMemc->set( $key, 0, 86400 );
328 if ( $value >= $wgAccountCreationThrottle ) {
329 $this->throttleHit( $wgAccountCreationThrottle );
332 $wgMemc->incr( $key );
335 if( !$wgAuth->addUser( $u, $this->mPassword
, $this->mEmail
, $this->mRealName
) ) {
336 $this->mainLoginForm( wfMsg( 'externaldberror' ) );
340 return $this->initUser( $u, false );
344 * Actually add a user to the database.
345 * Give it a User object that has been initialised with a name.
347 * @param $u User object.
348 * @param $autocreate boolean -- true if this is an autocreation via auth plugin
349 * @return User object.
352 function initUser( $u, $autocreate ) {
357 if ( $wgAuth->allowPasswordChange() ) {
358 $u->setPassword( $this->mPassword
);
361 $u->setEmail( $this->mEmail
);
362 $u->setRealName( $this->mRealName
);
365 $wgAuth->initUser( $u, $autocreate );
367 if ( $this->mExtUser
) {
368 $this->mExtUser
->linkToLocal( $u->getId() );
369 $email = $this->mExtUser
->getPref( 'emailaddress' );
370 if ( $email && !$this->mEmail
) {
371 $u->setEmail( $email );
375 $u->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
379 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
380 $ssUpdate->doUpdate();
386 * Internally authenticate the login request.
388 * This may create a local account as a side effect if the
389 * authentication plugin allows transparent local account
392 public function authenticateUserData() {
393 global $wgUser, $wgAuth;
394 if ( $this->mName
== '' ) {
395 return self
::NO_NAME
;
398 global $wgPasswordAttemptThrottle;
401 if ( is_array( $wgPasswordAttemptThrottle ) ) {
402 $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName
) );
403 $count = $wgPasswordAttemptThrottle['count'];
404 $period = $wgPasswordAttemptThrottle['seconds'];
407 $throttleCount = $wgMemc->get( $throttleKey );
408 if ( !$throttleCount ) {
409 $wgMemc->add( $throttleKey, 1, $period ); // start counter
410 } else if ( $throttleCount < $count ) {
411 $wgMemc->incr($throttleKey);
412 } else if ( $throttleCount >= $count ) {
413 return self
::THROTTLED
;
417 // Load $wgUser now, and check to see if we're logging in as the same
418 // name. This is necessary because loading $wgUser (say by calling
419 // getName()) calls the UserLoadFromSession hook, which potentially
420 // creates the user in the database. Until we load $wgUser, checking
421 // for user existence using User::newFromName($name)->getId() below
422 // will effectively be using stale data.
423 if ( $wgUser->getName() === $this->mName
) {
424 wfDebug( __METHOD__
.": already logged in as {$this->mName}\n" );
425 return self
::SUCCESS
;
428 $this->mExtUser
= ExternalUser
::newFromName( $this->mName
);
430 # TODO: Allow some magic here for invalid external names, e.g., let the
431 # user choose a different wiki name.
432 $u = User
::newFromName( $this->mName
);
433 if( is_null( $u ) ||
!User
::isUsableName( $u->getName() ) ) {
434 return self
::ILLEGAL
;
437 $isAutoCreated = false;
438 if ( 0 == $u->getID() ) {
439 $status = $this->attemptAutoCreate( $u );
440 if ( $status !== self
::SUCCESS
) {
443 $isAutoCreated = true;
446 global $wgExternalAuthType, $wgAutocreatePolicy;
447 if ( $wgExternalAuthType && $wgAutocreatePolicy != 'never'
448 && is_object( $this->mExtUser
)
449 && $this->mExtUser
->authenticate( $this->mPassword
) ) {
450 # The external user and local user have the same name and
451 # password, so we assume they're the same.
452 $this->mExtUser
->linkToLocal( $u->getID() );
458 // Give general extensions, such as a captcha, a chance to abort logins
459 $abort = self
::ABORTED
;
460 if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword
, &$abort ) ) ) {
464 global $wgBlockDisablesLogin;
465 if (!$u->checkPassword( $this->mPassword
)) {
466 if( $u->checkTemporaryPassword( $this->mPassword
) ) {
467 // The e-mailed temporary password should not be used for actu-
468 // al logins; that's a very sloppy habit, and insecure if an
469 // attacker has a few seconds to click "search" on someone's o-
472 // Allow it to be used only to reset the password a single time
473 // to a new value, which won't be in the user's e-mail ar-
476 // For backwards compatibility, we'll still recognize it at the
477 // login form to minimize surprises for people who have been
478 // logging in with a temporary password for some time.
480 // As a side-effect, we can authenticate the user's e-mail ad-
481 // dress if it's not already done, since the temporary password
482 // was sent via e-mail.
483 if( !$u->isEmailConfirmed() ) {
488 // At this point we just return an appropriate code/ indicating
489 // that the UI should show a password reset form; bot inter-
490 // faces etc will probably just fail cleanly here.
491 $retval = self
::RESET_PASS
;
493 $retval = ($this->mPassword
== '') ? self
::EMPTY_PASS
: self
::WRONG_PASS
;
495 } elseif ( $wgBlockDisablesLogin && $u->isBlocked() ) {
496 // If we've enabled it, make it so that a blocked user cannot login
497 $retval = self
::USER_BLOCKED
;
499 $wgAuth->updateUser( $u );
502 // Please reset throttle for successful logins, thanks!
504 $wgMemc->delete($throttleKey);
507 if ( $isAutoCreated ) {
508 // Must be run after $wgUser is set, for correct new user log
509 wfRunHooks( 'AuthPluginAutoCreate', array( $wgUser ) );
512 $retval = self
::SUCCESS
;
514 wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword
, $retval ) );
519 * Attempt to automatically create a user on login. Only succeeds if there
520 * is an external authentication method which allows it.
521 * @return integer Status code
523 function attemptAutoCreate( $user ) {
524 global $wgAuth, $wgUser, $wgAutocreatePolicy;
526 if ( $wgUser->isBlockedFromCreateAccount() ) {
527 wfDebug( __METHOD__
.": user is blocked from account creation\n" );
528 return self
::CREATE_BLOCKED
;
532 * If the external authentication plugin allows it, automatically cre-
533 * ate a new account for users that are externally defined but have not
536 if ( $this->mExtUser
) {
537 # mExtUser is neither null nor false, so use the new ExternalAuth
539 if ( $wgAutocreatePolicy == 'never' ) {
540 return self
::NOT_EXISTS
;
542 if ( !$this->mExtUser
->authenticate( $this->mPassword
) ) {
543 return self
::WRONG_PLUGIN_PASS
;
547 if ( !$wgAuth->autoCreate() ) {
548 return self
::NOT_EXISTS
;
550 if ( !$wgAuth->userExists( $user->getName() ) ) {
551 wfDebug( __METHOD__
.": user does not exist\n" );
552 return self
::NOT_EXISTS
;
554 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword
) ) {
555 wfDebug( __METHOD__
.": \$wgAuth->authenticate() returned false, aborting\n" );
556 return self
::WRONG_PLUGIN_PASS
;
560 wfDebug( __METHOD__
.": creating account\n" );
561 $user = $this->initUser( $user, true );
562 return self
::SUCCESS
;
565 function processLogin() {
566 global $wgUser, $wgAuth;
568 switch ( $this->authenticateUserData() ) {
570 # We've verified now, update the real record
571 if( (bool)$this->mRemember
!= (bool)$wgUser->getOption( 'rememberpassword' ) ) {
572 $wgUser->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
573 $wgUser->saveSettings();
575 $wgUser->invalidateCache();
577 $wgUser->setCookies();
579 // Reset the throttle
580 $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName
) );
582 $wgMemc->delete( $key );
584 if( $this->hasSessionCookie() ||
$this->mSkipCookieCheck
) {
585 /* Replace the language object to provide user interface in
586 * correct language immediately on this first page load.
588 global $wgLang, $wgRequest;
589 $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
590 $wgLang = Language
::factory( $code );
591 return $this->successfulLogin();
593 return $this->cookieRedirectCheck( 'login' );
599 $this->mainLoginForm( wfMsg( 'noname' ) );
601 case self
::WRONG_PLUGIN_PASS
:
602 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
604 case self
::NOT_EXISTS
:
605 if( $wgUser->isAllowed( 'createaccount' ) ){
606 $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $this->mName
) ) );
608 $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mName
) ) );
611 case self
::WRONG_PASS
:
612 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
614 case self
::EMPTY_PASS
:
615 $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
617 case self
::RESET_PASS
:
618 $this->resetLoginForm( wfMsg( 'resetpass_announce' ) );
620 case self
::CREATE_BLOCKED
:
621 $this->userBlockedMessage();
623 case self
::THROTTLED
:
624 $this->mainLoginForm( wfMsg( 'login-throttled' ) );
626 case self
::USER_BLOCKED
:
627 $this->mainLoginForm( wfMsgExt( 'login-userblocked',
628 array( 'parsemag', 'escape' ), $this->mName
) );
631 throw new MWException( "Unhandled case value" );
635 function resetLoginForm( $error ) {
637 $wgOut->addHTML( Xml
::element('p', array( 'class' => 'error' ), $error ) );
638 $reset = new SpecialResetpass();
639 $reset->execute( null );
645 function mailPassword() {
646 global $wgUser, $wgOut, $wgAuth;
648 if ( wfReadOnly() ) {
649 $wgOut->readOnlyPage();
653 if( !$wgAuth->allowPasswordChange() ) {
654 $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
658 # Check against blocked IPs
659 # fixme -- should we not?
660 if( $wgUser->isBlocked() ) {
661 $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
667 if ( ! wfRunHooks( 'UserLoginMailPassword', array( $this->mName
, &$error ) ) ) {
668 $this->mainLoginForm( $error );
672 # Check against the rate limiter
673 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
674 $wgOut->rateLimited();
678 if ( $this->mName
== '' ) {
679 $this->mainLoginForm( wfMsg( 'noname' ) );
682 $u = User
::newFromName( $this->mName
);
683 if( is_null( $u ) ) {
684 $this->mainLoginForm( wfMsg( 'noname' ) );
687 if ( 0 == $u->getID() ) {
688 $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $u->getName() ) ) );
692 # Check against password throttle
693 if ( $u->isPasswordReminderThrottled() ) {
694 global $wgPasswordReminderResendTime;
695 # Round the time in hours to 3 d.p., in case someone is specifying
696 # minutes or seconds.
697 $this->mainLoginForm( wfMsgExt( 'throttled-mailpassword', array( 'parsemag' ),
698 round( $wgPasswordReminderResendTime, 3 ) ) );
702 $result = $this->mailPasswordInternal( $u, true, 'passwordremindertitle', 'passwordremindertext' );
703 if( WikiError
::isError( $result ) ) {
704 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
706 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
712 * @param $u User object
713 * @param $throttle Boolean
714 * @param $emailTitle String: message name of email title
715 * @param $emailText String: message name of email text
716 * @return Mixed: true on success, WikiError on failure
719 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
720 global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry;
722 if ( $u->getEmail() == '' ) {
723 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
727 return new WikiError( wfMsg( 'badipaddress' ) );
730 wfRunHooks( 'User::mailPasswordInternal', array(&$wgUser, &$ip, &$u) );
732 $np = $u->randomPassword();
733 $u->setNewpassword( $np, $throttle );
735 $userLanguage = $u->getOption( 'language' );
736 $m = wfMsgExt( $emailText, array( 'parsemag', 'language' => $userLanguage ), $ip, $u->getName(), $np,
737 $wgServer . $wgScript, round( $wgNewPasswordExpiry / 86400 ) );
738 $result = $u->sendMail( wfMsgExt( $emailTitle, array( 'parsemag', 'language' => $userLanguage ) ), $m );
745 * Run any hooks registered for logins, then HTTP redirect to
746 * $this->mReturnTo (or Main Page if that's undefined). Formerly we had a
747 * nice message here, but that's really not as useful as just being sent to
748 * wherever you logged in from. It should be clear that the action was
749 * successful, given the lack of error messages plus the appearance of your
750 * name in the upper right.
754 function successfulLogin() {
755 global $wgUser, $wgOut;
757 # Run any hooks; display injected HTML if any, else redirect
759 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
761 if( $injected_html !== '' ) {
762 $this->displaySuccessfulLogin( 'loginsuccess', $injected_html );
764 $titleObj = Title
::newFromText( $this->mReturnTo
);
765 if ( !$titleObj instanceof Title
) {
766 $titleObj = Title
::newMainPage();
768 $wgOut->redirect( $titleObj->getFullURL( $this->mReturnToQuery
) );
773 * Run any hooks registered for logins, then display a message welcoming
778 function successfulCreation() {
779 global $wgUser, $wgOut;
781 # Run any hooks; display injected HTML
783 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
785 $this->displaySuccessfulLogin( 'welcomecreation', $injected_html );
789 * Display a "login successful" page.
791 private function displaySuccessfulLogin( $msgname, $injected_html ) {
792 global $wgOut, $wgUser;
794 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
795 $wgOut->setRobotPolicy( 'noindex,nofollow' );
796 $wgOut->setArticleRelated( false );
797 $wgOut->addWikiMsg( $msgname, $wgUser->getName() );
798 $wgOut->addHTML( $injected_html );
800 if ( !empty( $this->mReturnTo
) ) {
801 $wgOut->returnToMain( null, $this->mReturnTo
, $this->mReturnToQuery
);
803 $wgOut->returnToMain( null );
808 function userNotPrivilegedMessage($errors) {
811 $wgOut->setPageTitle( wfMsg( 'permissionserrors' ) );
812 $wgOut->setRobotPolicy( 'noindex,nofollow' );
813 $wgOut->setArticleRelated( false );
815 $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
816 // Stuff that might want to be added at the end. For example, instruc-
818 $wgOut->addWikiMsg( 'cantcreateaccount-nonblock-text' );
820 $wgOut->returnToMain( false );
824 function userBlockedMessage() {
825 global $wgOut, $wgUser;
827 # Let's be nice about this, it's likely that this feature will be used
828 # for blocking large numbers of innocent people, e.g. range blocks on
829 # schools. Don't blame it on the user. There's a small chance that it
830 # really is the user's fault, i.e. the username is blocked and they
831 # haven't bothered to log out before trying to create an account to
832 # evade it, but we'll leave that to their guilty conscience to figure
835 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
836 $wgOut->setRobotPolicy( 'noindex,nofollow' );
837 $wgOut->setArticleRelated( false );
840 $blocker = User
::whoIs( $wgUser->mBlock
->mBy
);
841 $block_reason = $wgUser->mBlock
->mReason
;
843 if ( strval( $block_reason ) === '' ) {
844 $block_reason = wfMsg( 'blockednoreason' );
846 $wgOut->addWikiMsg( 'cantcreateaccount-text', $ip, $block_reason, $blocker );
847 $wgOut->returnToMain( false );
853 function mainLoginForm( $msg, $msgtype = 'error' ) {
854 global $wgUser, $wgOut, $wgHiddenPrefs, $wgEnableEmail;
855 global $wgCookiePrefix, $wgLoginLanguageSelector;
856 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
858 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
860 if ( $this->mType
== 'signup' ) {
861 // Block signup here if in readonly. Keeps user from
862 // going through the process (filling out data, etc)
863 // and being informed later.
864 if ( wfReadOnly() ) {
865 $wgOut->readOnlyPage();
867 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
868 $this->userBlockedMessage();
870 } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) {
871 $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' );
876 if ( $this->mName
== '' ) {
877 if ( $wgUser->isLoggedIn() ) {
878 $this->mName
= $wgUser->getName();
880 $this->mName
= isset( $_COOKIE[$wgCookiePrefix.'UserName'] ) ?
$_COOKIE[$wgCookiePrefix.'UserName'] : null;
884 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
886 if ( $this->mType
== 'signup' ) {
887 $template = new UsercreateTemplate();
888 $q = 'action=submitlogin&type=signup';
889 $linkq = 'type=login';
890 $linkmsg = 'gotaccount';
892 $template = new UserloginTemplate();
893 $q = 'action=submitlogin&type=login';
894 $linkq = 'type=signup';
895 $linkmsg = 'nologin';
898 if ( !empty( $this->mReturnTo
) ) {
899 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
900 if ( !empty( $this->mReturnToQuery
) )
901 $returnto .= '&returntoquery=' .
902 wfUrlencode( $this->mReturnToQuery
);
907 # Pass any language selection on to the mode switch link
908 if( $wgLoginLanguageSelector && $this->mLanguage
)
909 $linkq .= '&uselang=' . $this->mLanguage
;
911 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
912 $link .= wfMsgHtml( $linkmsg . 'link' ); # Calling either 'gotaccountlink' or 'nologinlink'
915 # Don't show a "create account" link if the user can't
916 if( $this->showCreateOrLoginLink( $wgUser ) )
917 $template->set( 'link', wfMsgWikiHtml( $linkmsg, $link ) );
919 $template->set( 'link', '' );
921 $template->set( 'header', '' );
922 $template->set( 'name', $this->mName
);
923 $template->set( 'password', $this->mPassword
);
924 $template->set( 'retype', $this->mRetype
);
925 $template->set( 'email', $this->mEmail
);
926 $template->set( 'realname', $this->mRealName
);
927 $template->set( 'domain', $this->mDomain
);
929 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
930 $template->set( 'message', $msg );
931 $template->set( 'messagetype', $msgtype );
932 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
933 $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs ) );
934 $template->set( 'useemail', $wgEnableEmail );
935 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
936 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
937 $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
938 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember
);
940 # Prepare language selection links as needed
941 if( $wgLoginLanguageSelector ) {
942 $template->set( 'languages', $this->makeLanguageSelector() );
943 if( $this->mLanguage
)
944 $template->set( 'uselang', $this->mLanguage
);
947 // Give authentication and captcha plugins a chance to modify the form
948 $wgAuth->modifyUITemplate( $template, $this->mType
);
949 if ( $this->mType
== 'signup' ) {
950 wfRunHooks( 'UserCreateForm', array( &$template ) );
952 wfRunHooks( 'UserLoginForm', array( &$template ) );
955 //Changes the title depending on permissions for creating account
956 if ( $wgUser->isAllowed( 'createaccount' ) ) {
957 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
959 $wgOut->setPageTitle( wfMsg( 'userloginnocreate' ) );
962 $wgOut->setRobotPolicy( 'noindex,nofollow' );
963 $wgOut->setArticleRelated( false );
964 $wgOut->disallowUserJs(); // just in case...
965 $wgOut->addTemplate( $template );
971 function showCreateOrLoginLink( &$user ) {
972 if( $this->mType
== 'signup' ) {
974 } elseif( $user->isAllowed( 'createaccount' ) ) {
982 * Check if a session cookie is present.
984 * This will not pick up a cookie set during _this_ request, but is meant
985 * to ensure that the client is returning the cookie which was set on a
986 * previous pass through the system.
990 function hasSessionCookie() {
991 global $wgDisableCookieCheck, $wgRequest;
992 return $wgDisableCookieCheck ?
true : $wgRequest->checkSessionCookie();
998 function cookieRedirectCheck( $type ) {
1001 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
1002 $query = array( 'wpCookieCheck' => $type );
1003 if ( $this->mReturnTo
) $query['returnto'] = $this->mReturnTo
;
1004 $check = $titleObj->getFullURL( $query );
1006 return $wgOut->redirect( $check );
1012 function onCookieRedirectCheck( $type ) {
1013 if ( !$this->hasSessionCookie() ) {
1014 if ( $type == 'new' ) {
1015 return $this->mainLoginForm( wfMsgExt( 'nocookiesnew', array( 'parseinline' ) ) );
1016 } else if ( $type == 'login' ) {
1017 return $this->mainLoginForm( wfMsgExt( 'nocookieslogin', array( 'parseinline' ) ) );
1020 return $this->mainLoginForm( wfMsg( 'error' ) );
1023 return $this->successfulLogin();
1030 function throttleHit( $limit ) {
1031 $this->mainLoginForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $limit ) );
1035 * Produce a bar of links which allow the user to select another language
1036 * during login/registration but retain "returnto"
1040 function makeLanguageSelector() {
1043 $msg = wfMsgForContent( 'loginlanguagelinks' );
1044 if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
1045 $langs = explode( "\n", $msg );
1047 foreach( $langs as $lang ) {
1048 $lang = trim( $lang, '* ' );
1049 $parts = explode( '|', $lang );
1050 if (count($parts) >= 2) {
1051 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
1054 return count( $links ) > 0 ?
wfMsgHtml( 'loginlanguagelabel', $wgLang->pipeList( $links ) ) : '';
1061 * Create a language selector link for a particular language
1062 * Links back to this page preserving type and returnto
1064 * @param $text Link text
1065 * @param $lang Language code
1067 function makeLanguageSelectorLink( $text, $lang ) {
1069 $self = SpecialPage
::getTitleFor( 'Userlogin' );
1070 $attr = array( 'uselang' => $lang );
1071 if( $this->mType
== 'signup' )
1072 $attr['type'] = 'signup';
1073 if( $this->mReturnTo
)
1074 $attr['returnto'] = $this->mReturnTo
;
1075 $skin = $wgUser->getSkin();
1076 return $skin->linkKnown(
1078 htmlspecialchars( $text ),