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