*
* @file
*/
+
+use MediaWiki\Auth\AuthManager;
use MediaWiki\MediaWikiServices;
/**
$title = $this->getTitle();
$request = $this->getRequest();
$pageurl = $title->getLocalURL();
+ $authManager = AuthManager::singleton();
/* set up the default links for the personal toolbar */
$personal_urls = [];
'href' => $href,
'active' => $active
];
- $personal_urls['logout'] = [
- 'text' => $this->msg( 'pt-userlogout' )->text(),
- 'href' => self::makeSpecialUrl( 'Userlogout',
- // userlogout link must always contain an & character, otherwise we might not be able
- // to detect a buggy precaching proxy (bug 17790)
- $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto
- ),
- 'active' => false
- ];
+
+ // if we can't set the user, we can't unset it either
+ if ( $request->getSession()->canSetUser() ) {
+ $personal_urls['logout'] = [
+ 'text' => $this->msg( 'pt-userlogout' )->text(),
+ 'href' => self::makeSpecialUrl( 'Userlogout',
+ // userlogout link must always contain an & character, otherwise we might not be able
+ // to detect a buggy precaching proxy (bug 17790)
+ $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto ),
+ 'active' => false
+ ];
+ }
} else {
$useCombinedLoginLink = $this->useCombinedLoginLink();
+ if ( !$authManager->canCreateAccounts() || !$authManager->canAuthenticateNow() ) {
+ // don't show combined login/signup link if one of those is actually not available
+ $useCombinedLoginLink = false;
+ }
+
$loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
? 'nav-login-createaccount'
: 'pt-login';
];
}
- if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
+ if (
+ $authManager->canCreateAccounts()
+ && $this->getUser()->isAllowed( 'createaccount' )
+ && !$useCombinedLoginLink
+ ) {
$personal_urls['createaccount'] = $createaccount_url;
}
- $personal_urls['login'] = $login_url;
+ if ( $authManager->canAuthenticateNow() ) {
+ $personal_urls['login'] = $login_url;
+ }
}
Hooks::run( 'PersonalUrls', [ &$personal_urls, &$title, $this ] );
$this->setHeaders();
$this->checkPermissions();
- // Make sure it's possible to log in
- if ( !$this->isSignup() && !$session->canSetUser() ) {
- throw new ErrorPageError( 'cannotloginnow-title', 'cannotloginnow-text', [
+ // Make sure the system configuration allows log in / sign up
+ if ( !$this->isSignup() && !$authManager->canAuthenticateNow() ) {
+ if ( !$session->canSetUser() ) {
+ throw new ErrorPageError( 'cannotloginnow-title', 'cannotloginnow-text', [
$session->getProvider()->describe( RequestContext::getMain()->getLanguage() )
] );
+ }
+ throw new ErrorPageError( 'cannotlogin-title', 'cannotlogin-text' );
+ } elseif ( $this->isSignup() && !$authManager->canCreateAccounts() ) {
+ throw new ErrorPageError( 'cannotcreateaccount-title', 'cannotcreateaccount-text' );
}
/*
"createacct-yourpasswordagain-ph": "Enter password again",
"userlogin-remembermypassword": "Keep me logged in",
"userlogin-signwithsecure": "Use secure connection",
+ "cannotlogin-title": "Cannot log in",
+ "cannotlogin-text": "Logging in is not possible.",
"cannotloginnow-title": "Cannot log in now",
"cannotloginnow-text": "Logging in is not possible when using $1.",
+ "cannotcreateaccount-title": "Cannot create accounts",
+ "cannotcreateaccount-text": "Direct account creation is not enabled on this wiki.",
"yourdomainname": "Your domain:",
"password-change-forbidden": "You cannot change passwords on this wiki.",
"externaldberror": "There was either an authentication database error or you are not allowed to update your external account.",
"createacct-yourpasswordagain-ph": "Placeholder text in create account form for re-enter password field.\n\nSee example: [{{canonicalurl:Special:UserLogin|type=signup}} Special:UserLogin?type=signup]",
"userlogin-remembermypassword": "Used as checkbox label in [[Special:UserLogin]]. Parameters:\n* $1 - number of days the login session will be active if checked (Unused but used on-wiki)\n",
"userlogin-signwithsecure": "Text of link to HTTPS login form.\n\nSee example: [[Special:UserLogin]]",
- "cannotloginnow-title": "Error page title shown when logging in is not possible.",
- "cannotloginnow-text": "Error page text shown when logging in is not possible. Parameters:\n* $1 - Session type in use that makes it not possible to log in, from a message like {{msg-mw|sessionprovider-mediawiki-session-cookiesessionprovider}}.",
+ "cannotlogin-title": "Error page title shown when logging in is not possible. This is a catch-all when a more specific reason is not available.",
+ "cannotlogin-text": "Error page text shown when logging in is not possible. This is a catch-all when a more specific reason is not available.",
+ "cannotloginnow-title": "Error page title shown when logging in is not possible becuse the session provider in use does the user authentication itself.",
+ "cannotloginnow-text": "Error page text shown when logging in is not possible becuse the session provider in use does the user authentication itself. Parameters:\n* $1 - Session type in use that makes it not possible to log in, from a message like {{msg-mw|sessionprovider-mediawiki-session-cookiesessionprovider}}.",
+ "cannotcreateaccount-title": "Error page title shown when manual account creation is not possible. That probably means the wiki supports some other account creation method, e.g. autocreation by the session provider. (When account creation is possible but the current user does not have permission to do it, a more specific error message is displayed.)",
+ "cannotcreateaccount-text": "Error page text shown when manual account creation is not possible. That probably means the wiki supports some other account creation method, e.g. autocreation by the session provider. (When account creation is possible but the current user does not have permission to do it, a more specific error message is displayed.)",
"yourdomainname": "Used as label for listbox.",
"password-change-forbidden": "Error message shown when an external authentication source does not allow the password to be changed.",
"externaldberror": "This message is thrown when a valid attempt to change the wiki password for a user fails because of a database error or an error from an external system.",