convert "::1" and other pseudo-IPv6 addresses that Apache may throw at us to their...
[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
311 return $u;
312 }
313
314 /**
315 * @public
316 */
317
318 function authenticateUserData()
319 {
320 global $wgUser, $wgAuth;
321 if ( '' == $this->mName ) {
322 return self::NO_NAME;
323 }
324 $u = User::newFromName( $this->mName );
325 if( is_null( $u ) || !User::isUsableName( $u->getName() ) ) {
326 return self::ILLEGAL;
327 }
328 if ( 0 == $u->getID() ) {
329 global $wgAuth;
330 /**
331 * If the external authentication plugin allows it,
332 * automatically create a new account for users that
333 * are externally defined but have not yet logged in.
334 */
335 if ( $wgAuth->autoCreate() && $wgAuth->userExists( $u->getName() ) ) {
336 if ( $wgAuth->authenticate( $u->getName(), $this->mPassword ) ) {
337 $u =& $this->initUser( $u );
338 } else {
339 return self::WRONG_PLUGIN_PASS;
340 }
341 } else {
342 return self::NOT_EXISTS;
343 }
344 } else {
345 $u->load();
346 }
347
348 if (!$u->checkPassword( $this->mPassword )) {
349 return '' == $this->mPassword ? self::EMPTY_PASS : self::WRONG_PASS;
350 }
351 else
352 {
353 $wgAuth->updateUser( $u );
354 $wgUser = $u;
355
356 return self::SUCCESS;
357 }
358 }
359
360 function processLogin() {
361 global $wgUser, $wgAuth;
362
363 switch ($this->authenticateUserData())
364 {
365 case self::SUCCESS:
366 # We've verified now, update the real record
367 if( (bool)$this->mRemember != (bool)$wgUser->getOption( 'rememberpassword' ) ) {
368 $wgUser->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
369 $wgUser->saveSettings();
370 } else {
371 $wgUser->invalidateCache();
372 }
373 $wgUser->setCookies();
374
375 if( $this->hasSessionCookie() ) {
376 return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
377 } else {
378 return $this->cookieRedirectCheck( 'login' );
379 }
380 break;
381
382 case self::NO_NAME:
383 case self::ILLEGAL:
384 $this->mainLoginForm( wfMsg( 'noname' ) );
385 break;
386 case self::WRONG_PLUGIN_PASS:
387 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
388 break;
389 case self::NOT_EXISTS:
390 $this->mainLoginForm( wfMsg( 'nosuchuser', htmlspecialchars( $this->mName ) ) );
391 break;
392 case self::WRONG_PASS:
393 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
394 break;
395 case self::EMPTY_PASS:
396 $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
397 break;
398 default:
399 wfDebugDieBacktrace( "Unhandled case value" );
400 }
401 }
402
403 /**
404 * @private
405 */
406 function mailPassword() {
407 global $wgUser, $wgOut;
408
409 # Check against blocked IPs
410 # fixme -- should we not?
411 if( $wgUser->isBlocked() ) {
412 $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
413 return;
414 }
415
416 # Check against the rate limiter
417 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
418 $wgOut->rateLimited();
419 return;
420 }
421
422 if ( '' == $this->mName ) {
423 $this->mainLoginForm( wfMsg( 'noname' ) );
424 return;
425 }
426 $u = User::newFromName( $this->mName );
427 if( is_null( $u ) ) {
428 $this->mainLoginForm( wfMsg( 'noname' ) );
429 return;
430 }
431 if ( 0 == $u->getID() ) {
432 $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) );
433 return;
434 }
435
436 # Check against password throttle
437 if ( $u->isPasswordReminderThrottled() ) {
438 global $wgPasswordReminderResendTime;
439 # Round the time in hours to 3 d.p., in case someone is specifying minutes or seconds.
440 $this->mainLoginForm( wfMsg( 'throttled-mailpassword',
441 round( $wgPasswordReminderResendTime, 3 ) ) );
442 return;
443 }
444
445 $result = $this->mailPasswordInternal( $u, true );
446 if( WikiError::isError( $result ) ) {
447 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
448 } else {
449 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
450 }
451 }
452
453
454 /**
455 * @return mixed true on success, WikiError on failure
456 * @private
457 */
458 function mailPasswordInternal( $u, $throttle = true ) {
459 global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
460 global $wgServer, $wgScript;
461
462 if ( '' == $u->getEmail() ) {
463 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
464 }
465
466 $np = $u->randomPassword();
467 $u->setNewpassword( $np, $throttle );
468
469 setcookie( "{$wgCookiePrefix}Token", '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
470
471 $u->saveSettings();
472
473 $ip = wfGetIP();
474 if ( '' == $ip ) { $ip = '(Unknown)'; }
475
476 $m = wfMsg( 'passwordremindertext', $ip, $u->getName(), $np, $wgServer . $wgScript );
477
478 $result = $u->sendMail( wfMsg( 'passwordremindertitle' ), $m );
479 return $result;
480 }
481
482
483 /**
484 * @param string $msg Message that will be shown on success
485 * @param bool $auto Toggle auto-redirect to main page; default true
486 * @private
487 */
488 function successfulLogin( $msg, $auto = true ) {
489 global $wgUser;
490 global $wgOut;
491
492 # Run any hooks; ignore results
493
494 wfRunHooks('UserLoginComplete', array(&$wgUser));
495
496 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
497 $wgOut->setRobotpolicy( 'noindex,nofollow' );
498 $wgOut->setArticleRelated( false );
499 $wgOut->addWikiText( $msg );
500 if ( !empty( $this->mReturnTo ) ) {
501 $wgOut->returnToMain( $auto, $this->mReturnTo );
502 } else {
503 $wgOut->returnToMain( $auto );
504 }
505 }
506
507 /** */
508 function userNotPrivilegedMessage() {
509 global $wgOut;
510
511 $wgOut->setPageTitle( wfMsg( 'whitelistacctitle' ) );
512 $wgOut->setRobotpolicy( 'noindex,nofollow' );
513 $wgOut->setArticleRelated( false );
514
515 $wgOut->addWikiText( wfMsg( 'whitelistacctext' ) );
516
517 $wgOut->returnToMain( false );
518 }
519
520 /** */
521 function userBlockedMessage() {
522 global $wgOut;
523
524 # Let's be nice about this, it's likely that this feature will be used
525 # for blocking large numbers of innocent people, e.g. range blocks on
526 # schools. Don't blame it on the user. There's a small chance that it
527 # really is the user's fault, i.e. the username is blocked and they
528 # haven't bothered to log out before trying to create an account to
529 # evade it, but we'll leave that to their guilty conscience to figure
530 # out.
531
532 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
533 $wgOut->setRobotpolicy( 'noindex,nofollow' );
534 $wgOut->setArticleRelated( false );
535
536 $ip = wfGetIP();
537 $wgOut->addWikiText( wfMsg( 'cantcreateaccounttext', $ip ) );
538 $wgOut->returnToMain( false );
539 }
540
541 /**
542 * @private
543 */
544 function mainLoginForm( $msg, $msgtype = 'error' ) {
545 global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail;
546 global $wgCookiePrefix, $wgAuth, $wgLoginLanguageSelector;
547
548 if ( $this->mType == 'signup' ) {
549 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
550 $this->userNotPrivilegedMessage();
551 return;
552 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
553 $this->userBlockedMessage();
554 return;
555 }
556 }
557
558 if ( '' == $this->mName ) {
559 if ( $wgUser->isLoggedIn() ) {
560 $this->mName = $wgUser->getName();
561 } else {
562 $this->mName = isset( $_COOKIE[$wgCookiePrefix.'UserName'] ) ? $_COOKIE[$wgCookiePrefix.'UserName'] : null;
563 }
564 }
565
566 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
567
568 if ( $this->mType == 'signup' ) {
569 $template = new UsercreateTemplate();
570 $q = 'action=submitlogin&type=signup';
571 $linkq = 'type=login';
572 $linkmsg = 'gotaccount';
573 } else {
574 $template = new UserloginTemplate();
575 $q = 'action=submitlogin&type=login';
576 $linkq = 'type=signup';
577 $linkmsg = 'nologin';
578 }
579
580 if ( !empty( $this->mReturnTo ) ) {
581 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
582 $q .= $returnto;
583 $linkq .= $returnto;
584 }
585
586 # Pass any language selection on to the mode switch link
587 if( $wgLoginLanguageSelector && $this->mLanguage )
588 $linkq .= '&uselang=' . $this->mLanguage;
589
590 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
591 $link .= wfMsgHtml( $linkmsg . 'link' );
592 $link .= '</a>';
593
594 # Don't show a "create account" link if the user can't
595 if( $this->showCreateOrLoginLink( $wgUser ) )
596 $template->set( 'link', wfMsgHtml( $linkmsg, $link ) );
597 else
598 $template->set( 'link', '' );
599
600 $template->set( 'header', '' );
601 $template->set( 'name', $this->mName );
602 $template->set( 'password', $this->mPassword );
603 $template->set( 'retype', $this->mRetype );
604 $template->set( 'email', $this->mEmail );
605 $template->set( 'realname', $this->mRealName );
606 $template->set( 'domain', $this->mDomain );
607
608 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
609 $template->set( 'message', $msg );
610 $template->set( 'messagetype', $msgtype );
611 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
612 $template->set( 'userealname', $wgAllowRealName );
613 $template->set( 'useemail', $wgEnableEmail );
614 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember );
615
616 # Prepare language selection links as needed
617 if( $wgLoginLanguageSelector ) {
618 $template->set( 'languages', $this->makeLanguageSelector() );
619 if( $this->mLanguage )
620 $template->set( 'uselang', $this->mLanguage );
621 }
622
623 // Give authentication and captcha plugins a chance to modify the form
624 $wgAuth->modifyUITemplate( $template );
625 if ( $this->mType == 'signup' ) {
626 wfRunHooks( 'UserCreateForm', array( &$template ) );
627 } else {
628 wfRunHooks( 'UserLoginForm', array( &$template ) );
629 }
630
631 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
632 $wgOut->setRobotpolicy( 'noindex,nofollow' );
633 $wgOut->setArticleRelated( false );
634 $wgOut->addTemplate( $template );
635 }
636
637 /**
638 * @private
639 */
640 function showCreateOrLoginLink( &$user ) {
641 if( $this->mType == 'signup' ) {
642 return( true );
643 } elseif( $user->isAllowed( 'createaccount' ) ) {
644 return( true );
645 } else {
646 return( false );
647 }
648 }
649
650 /**
651 * @private
652 */
653 function hasSessionCookie() {
654 global $wgDisableCookieCheck;
655 return ( $wgDisableCookieCheck ) ? true : ( isset( $_COOKIE[session_name()] ) );
656 }
657
658 /**
659 * @private
660 */
661 function cookieRedirectCheck( $type ) {
662 global $wgOut;
663
664 $titleObj = SpecialPage::getTitleFor( 'Userlogin' );
665 $check = $titleObj->getFullURL( 'wpCookieCheck='.$type );
666
667 return $wgOut->redirect( $check );
668 }
669
670 /**
671 * @private
672 */
673 function onCookieRedirectCheck( $type ) {
674 global $wgUser;
675
676 if ( !$this->hasSessionCookie() ) {
677 if ( $type == 'new' ) {
678 return $this->mainLoginForm( wfMsg( 'nocookiesnew' ) );
679 } else if ( $type == 'login' ) {
680 return $this->mainLoginForm( wfMsg( 'nocookieslogin' ) );
681 } else {
682 # shouldn't happen
683 return $this->mainLoginForm( wfMsg( 'error' ) );
684 }
685 } else {
686 return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
687 }
688 }
689
690 /**
691 * @private
692 */
693 function throttleHit( $limit ) {
694 global $wgOut;
695
696 $wgOut->addWikiText( wfMsg( 'acct_creation_throttle_hit', $limit ) );
697 }
698
699 /**
700 * Produce a bar of links which allow the user to select another language
701 * during login/registration but retain "returnto"
702 *
703 * @return string
704 */
705 function makeLanguageSelector() {
706 $msg = wfMsgForContent( 'loginlanguagelinks' );
707 if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
708 $langs = explode( "\n", $msg );
709 $links = array();
710 foreach( $langs as $lang ) {
711 $lang = trim( $lang, '* ' );
712 $parts = explode( '|', $lang );
713 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
714 }
715 return count( $links ) > 0 ? wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : '';
716 } else {
717 return '';
718 }
719 }
720
721 /**
722 * Create a language selector link for a particular language
723 * Links back to this page preserving type and returnto
724 *
725 * @param $text Link text
726 * @param $lang Language code
727 */
728 function makeLanguageSelectorLink( $text, $lang ) {
729 global $wgUser;
730 $self = SpecialPage::getTitleFor( 'Userlogin' );
731 $attr[] = 'uselang=' . $lang;
732 if( $this->mType == 'signup' )
733 $attr[] = 'type=signup';
734 if( $this->mReturnTo )
735 $attr[] = 'returnto=' . $this->mReturnTo;
736 $skin =& $wgUser->getSkin();
737 return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );
738 }
739
740 }
741 ?>