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