* Separated login code from UI rendering code to allow non-UI login. Submitted by...
[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 define("AuthSuccess", 0);
29 define("AuthNoName", 1);
30 define("AuthIllegal", 2);
31 define("AuthWrongPluginPass", 3);
32 define("AuthNotExists", 4);
33 define("AuthWrongPass", 5);
34 define("AuthEmptyPass", 6);
35
36 class LoginForm {
37 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
38 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
39 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
40
41 /**
42 * Constructor
43 * @param webrequest $request A webrequest object passed by reference
44 */
45 function LoginForm( &$request ) {
46 global $wgLang, $wgAllowRealName, $wgEnableEmail;
47 global $wgAuth;
48
49 $this->mType = $request->getText( 'type' );
50 $this->mName = $request->getText( 'wpName' );
51 $this->mPassword = $request->getText( 'wpPassword' );
52 $this->mRetype = $request->getText( 'wpRetype' );
53 $this->mDomain = $request->getText( 'wpDomain' );
54 $this->mReturnTo = $request->getVal( 'returnto' );
55 $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
56 $this->mPosted = $request->wasPosted();
57 $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' );
58 $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' )
59 && $wgEnableEmail;
60 $this->mMailmypassword = $request->getCheck( 'wpMailmypassword' )
61 && $wgEnableEmail;
62 $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
63 $this->mAction = $request->getVal( 'action' );
64 $this->mRemember = $request->getCheck( 'wpRemember' );
65 $this->mLanguage = $request->getText( 'uselang' );
66
67 if( $wgEnableEmail ) {
68 $this->mEmail = $request->getText( 'wpEmail' );
69 } else {
70 $this->mEmail = '';
71 }
72 if( $wgAllowRealName ) {
73 $this->mRealName = $request->getText( 'wpRealName' );
74 } else {
75 $this->mRealName = '';
76 }
77
78 if( !$wgAuth->validDomain( $this->mDomain ) ) {
79 $this->mDomain = 'invaliddomain';
80 }
81 $wgAuth->setDomain( $this->mDomain );
82
83 # When switching accounts, it sucks to get automatically logged out
84 if( $this->mReturnTo == $wgLang->specialPage( 'Userlogout' ) ) {
85 $this->mReturnTo = '';
86 }
87 }
88
89 function execute() {
90 if ( !is_null( $this->mCookieCheck ) ) {
91 $this->onCookieRedirectCheck( $this->mCookieCheck );
92 return;
93 } else if( $this->mPosted ) {
94 if( $this->mCreateaccount ) {
95 return $this->addNewAccount();
96 } else if ( $this->mCreateaccountMail ) {
97 return $this->addNewAccountMailPassword();
98 } else if ( $this->mMailmypassword ) {
99 return $this->mailPassword();
100 } else if ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) {
101 return $this->processLogin();
102 }
103 }
104 $this->mainLoginForm( '' );
105 }
106
107 /**
108 * @private
109 */
110 function addNewAccountMailPassword() {
111 global $wgOut;
112
113 if ('' == $this->mEmail) {
114 $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName ) ) );
115 return;
116 }
117
118 $u = $this->addNewaccountInternal();
119
120 if ($u == NULL) {
121 return;
122 }
123
124 $u->saveSettings();
125 $result = $this->mailPasswordInternal($u);
126
127 wfRunHooks( 'AddNewAccount', array( $u ) );
128
129 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
130 $wgOut->setRobotpolicy( 'noindex,nofollow' );
131 $wgOut->setArticleRelated( false );
132
133 if( WikiError::isError( $result ) ) {
134 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
135 } else {
136 $wgOut->addWikiText( wfMsg( 'accmailtext', $u->getName(), $u->getEmail() ) );
137 $wgOut->returnToMain( false );
138 }
139 $u = 0;
140 }
141
142
143 /**
144 * @private
145 */
146 function addNewAccount() {
147 global $wgUser, $wgEmailAuthentication;
148
149 # Create the account and abort if there's a problem doing so
150 $u = $this->addNewAccountInternal();
151 if( $u == NULL )
152 return;
153
154 # If we showed up language selection links, and one was in use, be
155 # smart (and sensible) and save that language as the user's preference
156 global $wgLoginLanguageSelector;
157 if( $wgLoginLanguageSelector && $this->mLanguage )
158 $u->setOption( 'language', $this->mLanguage );
159
160 # Save user settings and send out an email authentication message if needed
161 $u->saveSettings();
162 if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) )
163 $u->sendConfirmationMail();
164
165 # If not logged in, assume the new account as the current one and set session cookies
166 # then show a "welcome" message or a "need cookies" message as needed
167 if( $wgUser->isAnon() ) {
168 $wgUser = $u;
169 $wgUser->setCookies();
170 wfRunHooks( 'AddNewAccount', array( $wgUser ) );
171 if( $this->hasSessionCookie() ) {
172 return $this->successfulLogin( wfMsg( 'welcomecreation', $wgUser->getName() ), false );
173 } else {
174 return $this->cookieRedirectCheck( 'new' );
175 }
176 } else {
177 # Confirm that the account was created
178 global $wgOut;
179 $skin = $wgUser->getSkin();
180 $self = Title::makeTitle( NS_SPECIAL, '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, $wgDBname;
198 global $wgAuth, $wgMinimalPasswordLength, $wgReservedUsernames;
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 );
239 if ( is_null( $u ) || in_array( $u->getName(), $wgReservedUsernames ) ) {
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 if ( $wgAccountCreationThrottle ) {
260 $key = $wgDBname.':acctcreate:ip:'.$ip;
261 $value = $wgMemc->incr( $key );
262 if ( !$value ) {
263 $wgMemc->set( $key, 1, 86400 );
264 }
265 if ( $value > $wgAccountCreationThrottle ) {
266 $this->throttleHit( $wgAccountCreationThrottle );
267 return false;
268 }
269 }
270
271 $abortError = '';
272 if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
273 // Hook point to add extra creation throttles and blocks
274 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
275 $this->mainLoginForm( $abortError );
276 return false;
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 * @private
316 */
317
318 function authenticateUserData()
319 {
320 global $wgUser, $wgAuth, $wgReservedUsernames;
321 if ( '' == $this->mName ) {
322 return AuthNoName;
323 }
324 $u = User::newFromName( $this->mName );
325 if( is_null( $u ) || in_array( $u->getName(), $wgReservedUsernames ) ) {
326 return AuthIllegal;
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 AuthPluginPass;
340 }
341 } else {
342 return AuthNotExists;
343 }
344 } else {
345 $u->loadFromDatabase();
346 }
347
348 if (!$u->checkPassword( $this->mPassword )) {
349 return '' == $this->mPassword ? AuthEmptyPass : AuthWrongPass;
350 }
351 else
352 {
353 $wgAuth->updateUser( $u );
354 $wgUser = $u;
355 return AuthSuccess;
356 }
357 }
358
359 function processLogin() {
360 global $wgUser, $wgAuth, $wgReservedUsernames;
361
362 switch ($this->authenticateUserData())
363 {
364 case (AuthSuccess):
365 # We've verified now, update the real record
366 #
367 $wgUser->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
368 $wgUser->setCookies();
369 $wgUser->saveSettings();
370
371 if( $this->hasSessionCookie() ) {
372 return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
373 } else {
374 return $this->cookieRedirectCheck( 'login' );
375 }
376 break;
377
378 case (AuthNoName):
379 case (AuthIllegal):
380 $this->mainLoginForm( wfMsg( 'noname' ) );
381 break;
382 case (AuthWrongPluginPass):
383 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
384 break;
385 case (AuthNotExists):
386 $this->mainLoginForm( wfMsg( 'nosuchuser', htmlspecialchars( $this->mName ) ) );
387 break;
388 case (AuthWrongPass):
389 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
390 break;
391 case (AuthEmptyPass):
392 $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
393 break;
394 default:
395 wfDebugDieBacktrace( "Unhandled case value" );
396 }
397 }
398
399 /**
400 * @private
401 */
402 function mailPassword() {
403 global $wgUser, $wgOut;
404
405 # Check against the rate limiter
406 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
407 $wgOut->rateLimited();
408 return;
409 }
410
411 if ( '' == $this->mName ) {
412 $this->mainLoginForm( wfMsg( 'noname' ) );
413 return;
414 }
415 $u = User::newFromName( $this->mName );
416 if( is_null( $u ) ) {
417 $this->mainLoginForm( wfMsg( 'noname' ) );
418 return;
419 }
420 if ( 0 == $u->getID() ) {
421 $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) );
422 return;
423 }
424
425 $u->loadFromDatabase();
426
427 $result = $this->mailPasswordInternal( $u );
428 if( WikiError::isError( $result ) ) {
429 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
430 } else {
431 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
432 }
433 }
434
435
436 /**
437 * @return mixed true on success, WikiError on failure
438 * @private
439 */
440 function mailPasswordInternal( $u ) {
441 global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
442 global $wgServer, $wgScript;
443
444 if ( '' == $u->getEmail() ) {
445 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
446 }
447
448 $np = $u->randomPassword();
449 $u->setNewpassword( $np );
450
451 setcookie( "{$wgCookiePrefix}Token", '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
452
453 $u->saveSettings();
454
455 $ip = wfGetIP();
456 if ( '' == $ip ) { $ip = '(Unknown)'; }
457
458 $m = wfMsg( 'passwordremindertext', $ip, $u->getName(), $np, $wgServer . $wgScript );
459
460 $result = $u->sendMail( wfMsg( 'passwordremindertitle' ), $m );
461 return $result;
462 }
463
464
465 /**
466 * @param string $msg Message that will be shown on success
467 * @param bool $auto Toggle auto-redirect to main page; default true
468 * @private
469 */
470 function successfulLogin( $msg, $auto = true ) {
471 global $wgUser;
472 global $wgOut;
473
474 # Run any hooks; ignore results
475
476 wfRunHooks('UserLoginComplete', array(&$wgUser));
477
478 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
479 $wgOut->setRobotpolicy( 'noindex,nofollow' );
480 $wgOut->setArticleRelated( false );
481 $wgOut->addWikiText( $msg );
482 if ( !empty( $this->mReturnTo ) ) {
483 $wgOut->returnToMain( $auto, $this->mReturnTo );
484 } else {
485 $wgOut->returnToMain( $auto );
486 }
487 }
488
489 /** */
490 function userNotPrivilegedMessage() {
491 global $wgOut;
492
493 $wgOut->setPageTitle( wfMsg( 'whitelistacctitle' ) );
494 $wgOut->setRobotpolicy( 'noindex,nofollow' );
495 $wgOut->setArticleRelated( false );
496
497 $wgOut->addWikiText( wfMsg( 'whitelistacctext' ) );
498
499 $wgOut->returnToMain( false );
500 }
501
502 /** */
503 function userBlockedMessage() {
504 global $wgOut;
505
506 # Let's be nice about this, it's likely that this feature will be used
507 # for blocking large numbers of innocent people, e.g. range blocks on
508 # schools. Don't blame it on the user. There's a small chance that it
509 # really is the user's fault, i.e. the username is blocked and they
510 # haven't bothered to log out before trying to create an account to
511 # evade it, but we'll leave that to their guilty conscience to figure
512 # out.
513
514 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
515 $wgOut->setRobotpolicy( 'noindex,nofollow' );
516 $wgOut->setArticleRelated( false );
517
518 $ip = wfGetIP();
519 $wgOut->addWikiText( wfMsg( 'cantcreateaccounttext', $ip ) );
520 $wgOut->returnToMain( false );
521 }
522
523 /**
524 * @private
525 */
526 function mainLoginForm( $msg, $msgtype = 'error' ) {
527 global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail;
528 global $wgCookiePrefix, $wgAuth, $wgLoginLanguageSelector;
529
530 if ( $this->mType == 'signup' ) {
531 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
532 $this->userNotPrivilegedMessage();
533 return;
534 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
535 $this->userBlockedMessage();
536 return;
537 }
538 }
539
540 if ( '' == $this->mName ) {
541 if ( $wgUser->isLoggedIn() ) {
542 $this->mName = $wgUser->getName();
543 } else {
544 $this->mName = @$_COOKIE[$wgCookiePrefix.'UserName'];
545 }
546 }
547
548 $titleObj = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
549
550 if ( $this->mType == 'signup' ) {
551 $template = new UsercreateTemplate();
552 $q = 'action=submitlogin&type=signup';
553 $linkq = 'type=login';
554 $linkmsg = 'gotaccount';
555 } else {
556 $template = new UserloginTemplate();
557 $q = 'action=submitlogin&type=login';
558 $linkq = 'type=signup';
559 $linkmsg = 'nologin';
560 }
561
562 if ( !empty( $this->mReturnTo ) ) {
563 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
564 $q .= $returnto;
565 $linkq .= $returnto;
566 }
567
568 # Pass any language selection on to the mode switch link
569 if( $wgLoginLanguageSelector && $this->mLanguage )
570 $linkq .= '&uselang=' . $this->mLanguage;
571
572 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
573 $link .= wfMsgHtml( $linkmsg . 'link' );
574 $link .= '</a>';
575
576 # Don't show a "create account" link if the user can't
577 if( $this->showCreateOrLoginLink( $wgUser ) )
578 $template->set( 'link', wfMsgHtml( $linkmsg, $link ) );
579 else
580 $template->set( 'link', '' );
581
582 $template->set( 'header', '' );
583 $template->set( 'name', $this->mName );
584 $template->set( 'password', $this->mPassword );
585 $template->set( 'retype', $this->mRetype );
586 $template->set( 'email', $this->mEmail );
587 $template->set( 'realname', $this->mRealName );
588 $template->set( 'domain', $this->mDomain );
589
590 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
591 $template->set( 'message', $msg );
592 $template->set( 'messagetype', $msgtype );
593 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
594 $template->set( 'userealname', $wgAllowRealName );
595 $template->set( 'useemail', $wgEnableEmail );
596 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember );
597
598 # Prepare language selection links as needed
599 if( $wgLoginLanguageSelector ) {
600 $template->set( 'languages', $this->makeLanguageSelector() );
601 if( $this->mLanguage )
602 $template->set( 'uselang', $this->mLanguage );
603 }
604
605 // Give authentication and captcha plugins a chance to modify the form
606 $wgAuth->modifyUITemplate( $template );
607 if ( $this->mType == 'signup' ) {
608 wfRunHooks( 'UserCreateForm', array( &$template ) );
609 } else {
610 wfRunHooks( 'UserLoginForm', array( &$template ) );
611 }
612
613 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
614 $wgOut->setRobotpolicy( 'noindex,nofollow' );
615 $wgOut->setArticleRelated( false );
616 $wgOut->addTemplate( $template );
617 }
618
619 /**
620 * @private
621 */
622 function showCreateOrLoginLink( &$user ) {
623 if( $this->mType == 'signup' ) {
624 return( true );
625 } elseif( $user->isAllowed( 'createaccount' ) ) {
626 return( true );
627 } else {
628 return( false );
629 }
630 }
631
632 /**
633 * @private
634 */
635 function hasSessionCookie() {
636 global $wgDisableCookieCheck;
637 return ( $wgDisableCookieCheck ) ? true : ( isset( $_COOKIE[session_name()] ) );
638 }
639
640 /**
641 * @private
642 */
643 function cookieRedirectCheck( $type ) {
644 global $wgOut;
645
646 $titleObj = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
647 $check = $titleObj->getFullURL( 'wpCookieCheck='.$type );
648
649 return $wgOut->redirect( $check );
650 }
651
652 /**
653 * @private
654 */
655 function onCookieRedirectCheck( $type ) {
656 global $wgUser;
657
658 if ( !$this->hasSessionCookie() ) {
659 if ( $type == 'new' ) {
660 return $this->mainLoginForm( wfMsg( 'nocookiesnew' ) );
661 } else if ( $type == 'login' ) {
662 return $this->mainLoginForm( wfMsg( 'nocookieslogin' ) );
663 } else {
664 # shouldn't happen
665 return $this->mainLoginForm( wfMsg( 'error' ) );
666 }
667 } else {
668 return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
669 }
670 }
671
672 /**
673 * @private
674 */
675 function throttleHit( $limit ) {
676 global $wgOut;
677
678 $wgOut->addWikiText( wfMsg( 'acct_creation_throttle_hit', $limit ) );
679 }
680
681 /**
682 * Produce a bar of links which allow the user to select another language
683 * during login/registration but retain "returnto"
684 *
685 * @return string
686 */
687 function makeLanguageSelector() {
688 $msg = wfMsgForContent( 'loginlanguagelinks' );
689 if( $msg != '' && $msg != '&lt;loginlanguagelinks&gt;' ) {
690 $langs = explode( "\n", $msg );
691 $links = array();
692 foreach( $langs as $lang ) {
693 $lang = trim( $lang, '* ' );
694 $parts = explode( '|', $lang );
695 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
696 }
697 return count( $links ) > 0 ? wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : '';
698 } else {
699 return '';
700 }
701 }
702
703 /**
704 * Create a language selector link for a particular language
705 * Links back to this page preserving type and returnto
706 *
707 * @param $text Link text
708 * @param $lang Language code
709 */
710 function makeLanguageSelectorLink( $text, $lang ) {
711 global $wgUser;
712 $self = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
713 $attr[] = 'uselang=' . $lang;
714 if( $this->mType == 'signup' )
715 $attr[] = 'type=signup';
716 if( $this->mReturnTo )
717 $attr[] = 'returnto=' . $this->mReturnTo;
718 $skin =& $wgUser->getSkin();
719 return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );
720 }
721
722 }
723 ?>