* Change behavior of logins using the temporary e-mailed password (as stored
[lhc/web/wiklou.git] / includes / SpecialUserlogin.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * constructor
10 */
11 function wfSpecialUserlogin() {
12 global $wgCommandLineMode;
13 global $wgRequest;
14 if( !$wgCommandLineMode && !isset( $_COOKIE[session_name()] ) ) {
15 wfSetupSession();
16 }
17
18 $form = new LoginForm( $wgRequest );
19 $form->execute();
20 }
21
22 /**
23 *
24 * @package MediaWiki
25 * @subpackage SpecialPage
26 */
27
28 class LoginForm {
29
30 const SUCCESS = 0;
31 const NO_NAME = 1;
32 const ILLEGAL = 2;
33 const WRONG_PLUGIN_PASS = 3;
34 const NOT_EXISTS = 4;
35 const WRONG_PASS = 5;
36 const EMPTY_PASS = 6;
37 const RESET_PASS = 7;
38
39 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
40 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
41 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
42
43 /**
44 * Constructor
45 * @param webrequest $request A webrequest object passed by reference
46 */
47 function LoginForm( &$request ) {
48 global $wgLang, $wgAllowRealName, $wgEnableEmail;
49 global $wgAuth;
50
51 $this->mType = $request->getText( 'type' );
52 $this->mName = $request->getText( 'wpName' );
53 $this->mPassword = $request->getText( 'wpPassword' );
54 $this->mRetype = $request->getText( 'wpRetype' );
55 $this->mDomain = $request->getText( 'wpDomain' );
56 $this->mReturnTo = $request->getVal( 'returnto' );
57 $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
58 $this->mPosted = $request->wasPosted();
59 $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' );
60 $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' )
61 && $wgEnableEmail;
62 $this->mMailmypassword = $request->getCheck( 'wpMailmypassword' )
63 && $wgEnableEmail;
64 $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
65 $this->mAction = $request->getVal( 'action' );
66 $this->mRemember = $request->getCheck( 'wpRemember' );
67 $this->mLanguage = $request->getText( 'uselang' );
68
69 if( $wgEnableEmail ) {
70 $this->mEmail = $request->getText( 'wpEmail' );
71 } else {
72 $this->mEmail = '';
73 }
74 if( $wgAllowRealName ) {
75 $this->mRealName = $request->getText( 'wpRealName' );
76 } else {
77 $this->mRealName = '';
78 }
79
80 if( !$wgAuth->validDomain( $this->mDomain ) ) {
81 $this->mDomain = 'invaliddomain';
82 }
83 $wgAuth->setDomain( $this->mDomain );
84
85 # When switching accounts, it sucks to get automatically logged out
86 if( $this->mReturnTo == $wgLang->specialPage( 'Userlogout' ) ) {
87 $this->mReturnTo = '';
88 }
89 }
90
91 function execute() {
92 if ( !is_null( $this->mCookieCheck ) ) {
93 $this->onCookieRedirectCheck( $this->mCookieCheck );
94 return;
95 } else if( $this->mPosted ) {
96 if( $this->mCreateaccount ) {
97 return $this->addNewAccount();
98 } else if ( $this->mCreateaccountMail ) {
99 return $this->addNewAccountMailPassword();
100 } else if ( $this->mMailmypassword ) {
101 return $this->mailPassword();
102 } else if ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) {
103 return $this->processLogin();
104 }
105 }
106 $this->mainLoginForm( '' );
107 }
108
109 /**
110 * @private
111 */
112 function addNewAccountMailPassword() {
113 global $wgOut;
114
115 if ('' == $this->mEmail) {
116 $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName ) ) );
117 return;
118 }
119
120 $u = $this->addNewaccountInternal();
121
122 if ($u == NULL) {
123 return;
124 }
125
126 $u->saveSettings();
127 $result = $this->mailPasswordInternal( $u, false );
128
129 wfRunHooks( 'AddNewAccount', array( $u ) );
130
131 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
132 $wgOut->setRobotpolicy( 'noindex,nofollow' );
133 $wgOut->setArticleRelated( false );
134
135 if( WikiError::isError( $result ) ) {
136 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
137 } else {
138 $wgOut->addWikiText( wfMsg( 'accmailtext', $u->getName(), $u->getEmail() ) );
139 $wgOut->returnToMain( false );
140 }
141 $u = 0;
142 }
143
144
145 /**
146 * @private
147 */
148 function addNewAccount() {
149 global $wgUser, $wgEmailAuthentication;
150
151 # Create the account and abort if there's a problem doing so
152 $u = $this->addNewAccountInternal();
153 if( $u == NULL )
154 return;
155
156 # If we showed up language selection links, and one was in use, be
157 # smart (and sensible) and save that language as the user's preference
158 global $wgLoginLanguageSelector;
159 if( $wgLoginLanguageSelector && $this->mLanguage )
160 $u->setOption( 'language', $this->mLanguage );
161
162 # Save user settings and send out an email authentication message if needed
163 $u->saveSettings();
164 if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) )
165 $u->sendConfirmationMail();
166
167 # If not logged in, assume the new account as the current one and set session cookies
168 # then show a "welcome" message or a "need cookies" message as needed
169 if( $wgUser->isAnon() ) {
170 $wgUser = $u;
171 $wgUser->setCookies();
172 wfRunHooks( 'AddNewAccount', array( $wgUser ) );
173 if( $this->hasSessionCookie() ) {
174 return $this->successfulLogin( wfMsg( 'welcomecreation', $wgUser->getName() ), false );
175 } else {
176 return $this->cookieRedirectCheck( 'new' );
177 }
178 } else {
179 # Confirm that the account was created
180 global $wgOut;
181 $self = SpecialPage::getTitleFor( 'Userlogin' );
182 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
183 $wgOut->setArticleRelated( false );
184 $wgOut->setRobotPolicy( 'noindex,nofollow' );
185 $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
186 $wgOut->returnToMain( $self->getPrefixedText() );
187 wfRunHooks( 'AddNewAccount', array( $u ) );
188 return true;
189 }
190 }
191
192 /**
193 * @private
194 */
195 function addNewAccountInternal() {
196 global $wgUser, $wgOut;
197 global $wgEnableSorbs, $wgProxyWhitelist;
198 global $wgMemc, $wgAccountCreationThrottle;
199 global $wgAuth, $wgMinimalPasswordLength;
200
201 // If the user passes an invalid domain, something is fishy
202 if( !$wgAuth->validDomain( $this->mDomain ) ) {
203 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
204 return false;
205 }
206
207 // If we are not allowing users to login locally, we should
208 // be checking to see if the user is actually able to
209 // authenticate to the authentication server before they
210 // create an account (otherwise, they can create a local account
211 // and login as any domain user). We only need to check this for
212 // domains that aren't local.
213 if( 'local' != $this->mDomain && '' != $this->mDomain ) {
214 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName ) || !$wgAuth->authenticate( $this->mName, $this->mPassword ) ) ) {
215 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
216 return false;
217 }
218 }
219
220 if ( wfReadOnly() ) {
221 $wgOut->readOnlyPage();
222 return false;
223 }
224
225 if (!$wgUser->isAllowedToCreateAccount()) {
226 $this->userNotPrivilegedMessage();
227 return false;
228 }
229
230 $ip = wfGetIP();
231 if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) &&
232 $wgUser->inSorbsBlacklist( $ip ) )
233 {
234 $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
235 return;
236 }
237
238 $name = trim( $this->mName );
239 $u = User::newFromName( $name, 'creatable' );
240 if ( is_null( $u ) ) {
241 $this->mainLoginForm( wfMsg( 'noname' ) );
242 return false;
243 }
244
245 if ( 0 != $u->idForName() ) {
246 $this->mainLoginForm( wfMsg( 'userexists' ) );
247 return false;
248 }
249
250 if ( 0 != strcmp( $this->mPassword, $this->mRetype ) ) {
251 $this->mainLoginForm( wfMsg( 'badretype' ) );
252 return false;
253 }
254
255 if ( !$wgUser->isValidPassword( $this->mPassword ) ) {
256 $this->mainLoginForm( wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) );
257 return false;
258 }
259
260 $abortError = '';
261 if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
262 // Hook point to add extra creation throttles and blocks
263 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
264 $this->mainLoginForm( $abortError );
265 return false;
266 }
267
268 if ( $wgAccountCreationThrottle ) {
269 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
270 $value = $wgMemc->incr( $key );
271 if ( !$value ) {
272 $wgMemc->set( $key, 1, 86400 );
273 }
274 if ( $value > $wgAccountCreationThrottle ) {
275 $this->throttleHit( $wgAccountCreationThrottle );
276 return false;
277 }
278 }
279
280 if( !$wgAuth->addUser( $u, $this->mPassword ) ) {
281 $this->mainLoginForm( wfMsg( 'externaldberror' ) );
282 return false;
283 }
284
285 # Update user count
286 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
287 $ssUpdate->doUpdate();
288
289 return $this->initUser( $u );
290 }
291
292 /**
293 * Actually add a user to the database.
294 * Give it a User object that has been initialised with a name.
295 *
296 * @param $u User object.
297 * @return User object.
298 * @private
299 */
300 function initUser( $u ) {
301 $u->addToDatabase();
302 $u->setPassword( $this->mPassword );
303 $u->setEmail( $this->mEmail );
304 $u->setRealName( $this->mRealName );
305 $u->setToken();
306
307 global $wgAuth;
308 $wgAuth->initUser( $u );
309
310 $u->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
311 $u->saveSettings();
312
313 return $u;
314 }
315
316 /**
317 * Internally authenticate the login request.
318 *
319 * This may create a local account as a side effect if the
320 * authentication plugin allows transparent local account
321 * creation.
322 *
323 * @public
324 */
325 function authenticateUserData() {
326 global $wgUser, $wgAuth;
327 if ( '' == $this->mName ) {
328 return self::NO_NAME;
329 }
330 $u = User::newFromName( $this->mName );
331 if( is_null( $u ) || !User::isUsableName( $u->getName() ) ) {
332 return self::ILLEGAL;
333 }
334 if ( 0 == $u->getID() ) {
335 global $wgAuth;
336 /**
337 * If the external authentication plugin allows it,
338 * automatically create a new account for users that
339 * are externally defined but have not yet logged in.
340 */
341 if ( $wgAuth->autoCreate() && $wgAuth->userExists( $u->getName() ) ) {
342 if ( $wgAuth->authenticate( $u->getName(), $this->mPassword ) ) {
343 $u = $this->initUser( $u );
344 } else {
345 return self::WRONG_PLUGIN_PASS;
346 }
347 } else {
348 return self::NOT_EXISTS;
349 }
350 } else {
351 $u->load();
352 }
353
354 if (!$u->checkPassword( $this->mPassword )) {
355 if( $u->checkTemporaryPassword( $this->mPassword ) ) {
356 // The e-mailed temporary password should not be used
357 // for actual logins; that's a very sloppy habit,
358 // and insecure if an attacker has a few seconds to
359 // click "search" on someone's open mail reader.
360 //
361 // Allow it to be used only to reset the password
362 // a single time to a new value, which won't be in
363 // the user's e-mail archives.
364 //
365 // For backwards compatibility, we'll still recognize
366 // it at the login form to minimize surprises for
367 // people who have been logging in with a temporary
368 // password for some time.
369 //
370 // At this point we just return an appropriate code
371 // indicating that the UI should show a password
372 // reset form; bot interfaces etc will probably just
373 // fail cleanly here.
374 return self::RESET_PASS;
375 } else {
376 return '' == $this->mPassword ? self::EMPTY_PASS : self::WRONG_PASS;
377 }
378 } else {
379 $wgAuth->updateUser( $u );
380 $wgUser = $u;
381
382 return self::SUCCESS;
383 }
384 }
385
386 function processLogin() {
387 global $wgUser, $wgAuth;
388
389 switch ($this->authenticateUserData())
390 {
391 case self::SUCCESS:
392 # We've verified now, update the real record
393 if( (bool)$this->mRemember != (bool)$wgUser->getOption( 'rememberpassword' ) ) {
394 $wgUser->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
395 $wgUser->saveSettings();
396 } else {
397 $wgUser->invalidateCache();
398 }
399 $wgUser->setCookies();
400
401 if( $this->hasSessionCookie() ) {
402 return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
403 } else {
404 return $this->cookieRedirectCheck( 'login' );
405 }
406 break;
407
408 case self::NO_NAME:
409 case self::ILLEGAL:
410 $this->mainLoginForm( wfMsg( 'noname' ) );
411 break;
412 case self::WRONG_PLUGIN_PASS:
413 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
414 break;
415 case self::NOT_EXISTS:
416 $this->mainLoginForm( wfMsg( 'nosuchuser', htmlspecialchars( $this->mName ) ) );
417 break;
418 case self::WRONG_PASS:
419 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
420 break;
421 case self::EMPTY_PASS:
422 $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
423 break;
424 case self::RESET_PASS:
425 $this->resetLoginForm( wfMsg( 'resetpass_announce' ) );
426 break;
427 default:
428 wfDebugDieBacktrace( "Unhandled case value" );
429 }
430 }
431
432 function resetLoginForm( $error ) {
433 global $wgOut;
434 $wgOut->addWikiText( "<div class=\"errorbox\">$error</div>" );
435 $reset = new PasswordResetForm( $this->mName, $this->mPassword );
436 $reset->execute();
437 }
438
439 /**
440 * @private
441 */
442 function mailPassword() {
443 global $wgUser, $wgOut, $wgAuth;
444
445 if( !$wgAuth->allowPasswordChange() ) {
446 $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
447 return;
448 }
449
450 # Check against blocked IPs
451 # fixme -- should we not?
452 if( $wgUser->isBlocked() ) {
453 $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
454 return;
455 }
456
457 # Check against the rate limiter
458 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
459 $wgOut->rateLimited();
460 return;
461 }
462
463 if ( '' == $this->mName ) {
464 $this->mainLoginForm( wfMsg( 'noname' ) );
465 return;
466 }
467 $u = User::newFromName( $this->mName );
468 if( is_null( $u ) ) {
469 $this->mainLoginForm( wfMsg( 'noname' ) );
470 return;
471 }
472 if ( 0 == $u->getID() ) {
473 $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) );
474 return;
475 }
476
477 # Check against password throttle
478 if ( $u->isPasswordReminderThrottled() ) {
479 global $wgPasswordReminderResendTime;
480 # Round the time in hours to 3 d.p., in case someone is specifying minutes or seconds.
481 $this->mainLoginForm( wfMsg( 'throttled-mailpassword',
482 round( $wgPasswordReminderResendTime, 3 ) ) );
483 return;
484 }
485
486 $result = $this->mailPasswordInternal( $u, true );
487 if( WikiError::isError( $result ) ) {
488 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
489 } else {
490 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
491 }
492 }
493
494
495 /**
496 * @return mixed true on success, WikiError on failure
497 * @private
498 */
499 function mailPasswordInternal( $u, $throttle = true ) {
500 global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
501 global $wgServer, $wgScript;
502
503 if ( '' == $u->getEmail() ) {
504 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
505 }
506
507 $np = $u->randomPassword();
508 $u->setNewpassword( $np, $throttle );
509
510 setcookie( "{$wgCookiePrefix}Token", '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
511
512 $u->saveSettings();
513
514 $ip = wfGetIP();
515 if ( '' == $ip ) { $ip = '(Unknown)'; }
516
517 $m = wfMsg( 'passwordremindertext', $ip, $u->getName(), $np, $wgServer . $wgScript );
518
519 $result = $u->sendMail( wfMsg( 'passwordremindertitle' ), $m );
520 return $result;
521 }
522
523
524 /**
525 * @param string $msg Message that will be shown on success
526 * @param bool $auto Toggle auto-redirect to main page; default true
527 * @private
528 */
529 function successfulLogin( $msg, $auto = true ) {
530 global $wgUser;
531 global $wgOut;
532
533 # Run any hooks; ignore results
534
535 wfRunHooks('UserLoginComplete', array(&$wgUser));
536
537 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
538 $wgOut->setRobotpolicy( 'noindex,nofollow' );
539 $wgOut->setArticleRelated( false );
540 $wgOut->addWikiText( $msg );
541 if ( !empty( $this->mReturnTo ) ) {
542 $wgOut->returnToMain( $auto, $this->mReturnTo );
543 } else {
544 $wgOut->returnToMain( $auto );
545 }
546 }
547
548 /** */
549 function userNotPrivilegedMessage() {
550 global $wgOut;
551
552 $wgOut->setPageTitle( wfMsg( 'whitelistacctitle' ) );
553 $wgOut->setRobotpolicy( 'noindex,nofollow' );
554 $wgOut->setArticleRelated( false );
555
556 $wgOut->addWikiText( wfMsg( 'whitelistacctext' ) );
557
558 $wgOut->returnToMain( false );
559 }
560
561 /** */
562 function userBlockedMessage() {
563 global $wgOut;
564
565 # Let's be nice about this, it's likely that this feature will be used
566 # for blocking large numbers of innocent people, e.g. range blocks on
567 # schools. Don't blame it on the user. There's a small chance that it
568 # really is the user's fault, i.e. the username is blocked and they
569 # haven't bothered to log out before trying to create an account to
570 # evade it, but we'll leave that to their guilty conscience to figure
571 # out.
572
573 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
574 $wgOut->setRobotpolicy( 'noindex,nofollow' );
575 $wgOut->setArticleRelated( false );
576
577 $ip = wfGetIP();
578 $wgOut->addWikiText( wfMsg( 'cantcreateaccounttext', $ip ) );
579 $wgOut->returnToMain( false );
580 }
581
582 /**
583 * @private
584 */
585 function mainLoginForm( $msg, $msgtype = 'error' ) {
586 global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail;
587 global $wgCookiePrefix, $wgAuth, $wgLoginLanguageSelector;
588 global $wgAuth;
589
590 if ( $this->mType == 'signup' ) {
591 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
592 $this->userNotPrivilegedMessage();
593 return;
594 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
595 $this->userBlockedMessage();
596 return;
597 }
598 }
599
600 if ( '' == $this->mName ) {
601 if ( $wgUser->isLoggedIn() ) {
602 $this->mName = $wgUser->getName();
603 } else {
604 $this->mName = isset( $_COOKIE[$wgCookiePrefix.'UserName'] ) ? $_COOKIE[$wgCookiePrefix.'UserName'] : null;
605 }
606 }
607
608 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
609
610 if ( $this->mType == 'signup' ) {
611 $template = new UsercreateTemplate();
612 $q = 'action=submitlogin&type=signup';
613 $linkq = 'type=login';
614 $linkmsg = 'gotaccount';
615 } else {
616 $template = new UserloginTemplate();
617 $q = 'action=submitlogin&type=login';
618 $linkq = 'type=signup';
619 $linkmsg = 'nologin';
620 }
621
622 if ( !empty( $this->mReturnTo ) ) {
623 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
624 $q .= $returnto;
625 $linkq .= $returnto;
626 }
627
628 # Pass any language selection on to the mode switch link
629 if( $wgLoginLanguageSelector && $this->mLanguage )
630 $linkq .= '&uselang=' . $this->mLanguage;
631
632 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
633 $link .= wfMsgHtml( $linkmsg . 'link' );
634 $link .= '</a>';
635
636 # Don't show a "create account" link if the user can't
637 if( $this->showCreateOrLoginLink( $wgUser ) )
638 $template->set( 'link', wfMsgHtml( $linkmsg, $link ) );
639 else
640 $template->set( 'link', '' );
641
642 $template->set( 'header', '' );
643 $template->set( 'name', $this->mName );
644 $template->set( 'password', $this->mPassword );
645 $template->set( 'retype', $this->mRetype );
646 $template->set( 'email', $this->mEmail );
647 $template->set( 'realname', $this->mRealName );
648 $template->set( 'domain', $this->mDomain );
649
650 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
651 $template->set( 'message', $msg );
652 $template->set( 'messagetype', $msgtype );
653 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
654 $template->set( 'userealname', $wgAllowRealName );
655 $template->set( 'useemail', $wgEnableEmail );
656 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
657 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember );
658
659 # Prepare language selection links as needed
660 if( $wgLoginLanguageSelector ) {
661 $template->set( 'languages', $this->makeLanguageSelector() );
662 if( $this->mLanguage )
663 $template->set( 'uselang', $this->mLanguage );
664 }
665
666 // Give authentication and captcha plugins a chance to modify the form
667 $wgAuth->modifyUITemplate( $template );
668 if ( $this->mType == 'signup' ) {
669 wfRunHooks( 'UserCreateForm', array( &$template ) );
670 } else {
671 wfRunHooks( 'UserLoginForm', array( &$template ) );
672 }
673
674 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
675 $wgOut->setRobotpolicy( 'noindex,nofollow' );
676 $wgOut->setArticleRelated( false );
677 $wgOut->addTemplate( $template );
678 }
679
680 /**
681 * @private
682 */
683 function showCreateOrLoginLink( &$user ) {
684 if( $this->mType == 'signup' ) {
685 return( true );
686 } elseif( $user->isAllowed( 'createaccount' ) ) {
687 return( true );
688 } else {
689 return( false );
690 }
691 }
692
693 /**
694 * @private
695 */
696 function hasSessionCookie() {
697 global $wgDisableCookieCheck;
698 return ( $wgDisableCookieCheck ) ? true : ( isset( $_COOKIE[session_name()] ) );
699 }
700
701 /**
702 * @private
703 */
704 function cookieRedirectCheck( $type ) {
705 global $wgOut;
706
707 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
708 $check = $titleObj->getFullURL( 'wpCookieCheck='.$type );
709
710 return $wgOut->redirect( $check );
711 }
712
713 /**
714 * @private
715 */
716 function onCookieRedirectCheck( $type ) {
717 global $wgUser;
718
719 if ( !$this->hasSessionCookie() ) {
720 if ( $type == 'new' ) {
721 return $this->mainLoginForm( wfMsg( 'nocookiesnew' ) );
722 } else if ( $type == 'login' ) {
723 return $this->mainLoginForm( wfMsg( 'nocookieslogin' ) );
724 } else {
725 # shouldn't happen
726 return $this->mainLoginForm( wfMsg( 'error' ) );
727 }
728 } else {
729 return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
730 }
731 }
732
733 /**
734 * @private
735 */
736 function throttleHit( $limit ) {
737 global $wgOut;
738
739 $wgOut->addWikiText( wfMsg( 'acct_creation_throttle_hit', $limit ) );
740 }
741
742 /**
743 * Produce a bar of links which allow the user to select another language
744 * during login/registration but retain "returnto"
745 *
746 * @return string
747 */
748 function makeLanguageSelector() {
749 $msg = wfMsgForContent( 'loginlanguagelinks' );
750 if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
751 $langs = explode( "\n", $msg );
752 $links = array();
753 foreach( $langs as $lang ) {
754 $lang = trim( $lang, '* ' );
755 $parts = explode( '|', $lang );
756 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
757 }
758 return count( $links ) > 0 ? wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : '';
759 } else {
760 return '';
761 }
762 }
763
764 /**
765 * Create a language selector link for a particular language
766 * Links back to this page preserving type and returnto
767 *
768 * @param $text Link text
769 * @param $lang Language code
770 */
771 function makeLanguageSelectorLink( $text, $lang ) {
772 global $wgUser;
773 $self = SpecialPage::getTitleFor( 'Userlogin' );
774 $attr[] = 'uselang=' . $lang;
775 if( $this->mType == 'signup' )
776 $attr[] = 'type=signup';
777 if( $this->mReturnTo )
778 $attr[] = 'returnto=' . $this->mReturnTo;
779 $skin =& $wgUser->getSkin();
780 return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );
781 }
782
783 }
784 ?>