Reverting r16861; incompatible change to message texts, breaks a lot of toggle displa...
[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);
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 = Title::makeTitle( NS_SPECIAL, '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 );
240 if ( is_null( $u ) || !User::isCreatableName( $u->getName() ) ) {
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 if ( $wgAccountCreationThrottle ) {
261 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
262 $value = $wgMemc->incr( $key );
263 if ( !$value ) {
264 $wgMemc->set( $key, 1, 86400 );
265 }
266 if ( $value > $wgAccountCreationThrottle ) {
267 $this->throttleHit( $wgAccountCreationThrottle );
268 return false;
269 }
270 }
271
272 $abortError = '';
273 if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
274 // Hook point to add extra creation throttles and blocks
275 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
276 $this->mainLoginForm( $abortError );
277 return false;
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 * @private
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->loadFromDatabase();
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 the rate limiter
411 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
412 $wgOut->rateLimited();
413 return;
414 }
415
416 if ( '' == $this->mName ) {
417 $this->mainLoginForm( wfMsg( 'noname' ) );
418 return;
419 }
420 $u = User::newFromName( $this->mName );
421 if( is_null( $u ) ) {
422 $this->mainLoginForm( wfMsg( 'noname' ) );
423 return;
424 }
425 if ( 0 == $u->getID() ) {
426 $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) );
427 return;
428 }
429
430 $u->loadFromDatabase();
431
432 $result = $this->mailPasswordInternal( $u );
433 if( WikiError::isError( $result ) ) {
434 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
435 } else {
436 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
437 }
438 }
439
440
441 /**
442 * @return mixed true on success, WikiError on failure
443 * @private
444 */
445 function mailPasswordInternal( $u ) {
446 global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
447 global $wgServer, $wgScript;
448
449 if ( '' == $u->getEmail() ) {
450 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
451 }
452
453 $np = $u->randomPassword();
454 $u->setNewpassword( $np );
455
456 setcookie( "{$wgCookiePrefix}Token", '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
457
458 $u->saveSettings();
459
460 $ip = wfGetIP();
461 if ( '' == $ip ) { $ip = '(Unknown)'; }
462
463 $m = wfMsg( 'passwordremindertext', $ip, $u->getName(), $np, $wgServer . $wgScript );
464
465 $result = $u->sendMail( wfMsg( 'passwordremindertitle' ), $m );
466 return $result;
467 }
468
469
470 /**
471 * @param string $msg Message that will be shown on success
472 * @param bool $auto Toggle auto-redirect to main page; default true
473 * @private
474 */
475 function successfulLogin( $msg, $auto = true ) {
476 global $wgUser;
477 global $wgOut;
478
479 # Run any hooks; ignore results
480
481 wfRunHooks('UserLoginComplete', array(&$wgUser));
482
483 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
484 $wgOut->setRobotpolicy( 'noindex,nofollow' );
485 $wgOut->setArticleRelated( false );
486 $wgOut->addWikiText( $msg );
487 if ( !empty( $this->mReturnTo ) ) {
488 $wgOut->returnToMain( $auto, $this->mReturnTo );
489 } else {
490 $wgOut->returnToMain( $auto );
491 }
492 }
493
494 /** */
495 function userNotPrivilegedMessage() {
496 global $wgOut;
497
498 $wgOut->setPageTitle( wfMsg( 'whitelistacctitle' ) );
499 $wgOut->setRobotpolicy( 'noindex,nofollow' );
500 $wgOut->setArticleRelated( false );
501
502 $wgOut->addWikiText( wfMsg( 'whitelistacctext' ) );
503
504 $wgOut->returnToMain( false );
505 }
506
507 /** */
508 function userBlockedMessage() {
509 global $wgOut;
510
511 # Let's be nice about this, it's likely that this feature will be used
512 # for blocking large numbers of innocent people, e.g. range blocks on
513 # schools. Don't blame it on the user. There's a small chance that it
514 # really is the user's fault, i.e. the username is blocked and they
515 # haven't bothered to log out before trying to create an account to
516 # evade it, but we'll leave that to their guilty conscience to figure
517 # out.
518
519 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
520 $wgOut->setRobotpolicy( 'noindex,nofollow' );
521 $wgOut->setArticleRelated( false );
522
523 $ip = wfGetIP();
524 $wgOut->addWikiText( wfMsg( 'cantcreateaccounttext', $ip ) );
525 $wgOut->returnToMain( false );
526 }
527
528 /**
529 * @private
530 */
531 function mainLoginForm( $msg, $msgtype = 'error' ) {
532 global $wgUser, $wgOut, $wgAllowRealName, $wgEnableEmail;
533 global $wgCookiePrefix, $wgAuth, $wgLoginLanguageSelector;
534
535 if ( $this->mType == 'signup' ) {
536 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
537 $this->userNotPrivilegedMessage();
538 return;
539 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
540 $this->userBlockedMessage();
541 return;
542 }
543 }
544
545 if ( '' == $this->mName ) {
546 if ( $wgUser->isLoggedIn() ) {
547 $this->mName = $wgUser->getName();
548 } else {
549 $this->mName = @$_COOKIE[$wgCookiePrefix.'UserName'];
550 }
551 }
552
553 $titleObj = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
554
555 if ( $this->mType == 'signup' ) {
556 $template = new UsercreateTemplate();
557 $q = 'action=submitlogin&type=signup';
558 $linkq = 'type=login';
559 $linkmsg = 'gotaccount';
560 } else {
561 $template = new UserloginTemplate();
562 $q = 'action=submitlogin&type=login';
563 $linkq = 'type=signup';
564 $linkmsg = 'nologin';
565 }
566
567 if ( !empty( $this->mReturnTo ) ) {
568 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo );
569 $q .= $returnto;
570 $linkq .= $returnto;
571 }
572
573 # Pass any language selection on to the mode switch link
574 if( $wgLoginLanguageSelector && $this->mLanguage )
575 $linkq .= '&uselang=' . $this->mLanguage;
576
577 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
578 $link .= wfMsgHtml( $linkmsg . 'link' );
579 $link .= '</a>';
580
581 # Don't show a "create account" link if the user can't
582 if( $this->showCreateOrLoginLink( $wgUser ) )
583 $template->set( 'link', wfMsgHtml( $linkmsg, $link ) );
584 else
585 $template->set( 'link', '' );
586
587 $template->set( 'header', '' );
588 $template->set( 'name', $this->mName );
589 $template->set( 'password', $this->mPassword );
590 $template->set( 'retype', $this->mRetype );
591 $template->set( 'email', $this->mEmail );
592 $template->set( 'realname', $this->mRealName );
593 $template->set( 'domain', $this->mDomain );
594
595 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
596 $template->set( 'message', $msg );
597 $template->set( 'messagetype', $msgtype );
598 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
599 $template->set( 'userealname', $wgAllowRealName );
600 $template->set( 'useemail', $wgEnableEmail );
601 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember );
602
603 # Prepare language selection links as needed
604 if( $wgLoginLanguageSelector ) {
605 $template->set( 'languages', $this->makeLanguageSelector() );
606 if( $this->mLanguage )
607 $template->set( 'uselang', $this->mLanguage );
608 }
609
610 // Give authentication and captcha plugins a chance to modify the form
611 $wgAuth->modifyUITemplate( $template );
612 if ( $this->mType == 'signup' ) {
613 wfRunHooks( 'UserCreateForm', array( &$template ) );
614 } else {
615 wfRunHooks( 'UserLoginForm', array( &$template ) );
616 }
617
618 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
619 $wgOut->setRobotpolicy( 'noindex,nofollow' );
620 $wgOut->setArticleRelated( false );
621 $wgOut->addTemplate( $template );
622 }
623
624 /**
625 * @private
626 */
627 function showCreateOrLoginLink( &$user ) {
628 if( $this->mType == 'signup' ) {
629 return( true );
630 } elseif( $user->isAllowed( 'createaccount' ) ) {
631 return( true );
632 } else {
633 return( false );
634 }
635 }
636
637 /**
638 * @private
639 */
640 function hasSessionCookie() {
641 global $wgDisableCookieCheck;
642 return ( $wgDisableCookieCheck ) ? true : ( isset( $_COOKIE[session_name()] ) );
643 }
644
645 /**
646 * @private
647 */
648 function cookieRedirectCheck( $type ) {
649 global $wgOut;
650
651 $titleObj = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
652 $check = $titleObj->getFullURL( 'wpCookieCheck='.$type );
653
654 return $wgOut->redirect( $check );
655 }
656
657 /**
658 * @private
659 */
660 function onCookieRedirectCheck( $type ) {
661 global $wgUser;
662
663 if ( !$this->hasSessionCookie() ) {
664 if ( $type == 'new' ) {
665 return $this->mainLoginForm( wfMsg( 'nocookiesnew' ) );
666 } else if ( $type == 'login' ) {
667 return $this->mainLoginForm( wfMsg( 'nocookieslogin' ) );
668 } else {
669 # shouldn't happen
670 return $this->mainLoginForm( wfMsg( 'error' ) );
671 }
672 } else {
673 return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) );
674 }
675 }
676
677 /**
678 * @private
679 */
680 function throttleHit( $limit ) {
681 global $wgOut;
682
683 $wgOut->addWikiText( wfMsg( 'acct_creation_throttle_hit', $limit ) );
684 }
685
686 /**
687 * Produce a bar of links which allow the user to select another language
688 * during login/registration but retain "returnto"
689 *
690 * @return string
691 */
692 function makeLanguageSelector() {
693 $msg = wfMsgForContent( 'loginlanguagelinks' );
694 if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
695 $langs = explode( "\n", $msg );
696 $links = array();
697 foreach( $langs as $lang ) {
698 $lang = trim( $lang, '* ' );
699 $parts = explode( '|', $lang );
700 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
701 }
702 return count( $links ) > 0 ? wfMsgHtml( 'loginlanguagelabel', implode( ' | ', $links ) ) : '';
703 } else {
704 return '';
705 }
706 }
707
708 /**
709 * Create a language selector link for a particular language
710 * Links back to this page preserving type and returnto
711 *
712 * @param $text Link text
713 * @param $lang Language code
714 */
715 function makeLanguageSelectorLink( $text, $lang ) {
716 global $wgUser;
717 $self = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
718 $attr[] = 'uselang=' . $lang;
719 if( $this->mType == 'signup' )
720 $attr[] = 'type=signup';
721 if( $this->mReturnTo )
722 $attr[] = 'returnto=' . $this->mReturnTo;
723 $skin =& $wgUser->getSkin();
724 return $skin->makeKnownLinkObj( $self, htmlspecialchars( $text ), implode( '&', $attr ) );
725 }
726
727 }
728 ?>