I am trying to setup a private Mediawiki instance which expects users to login to see any content. I tried tweaking the $wgWhitelistRead variable in the Localsettings.php file but it still takes me to a page that says, "Login Required". I want the wiki to redirect to Special:userLogin if a user is not logged in. How do I do this?
I found a similar question on the mwforums but it seems to be for an older version of mediawiki. Any ideas?
The seemingly natural place to do this would be in OutputPage::showPermissionsErrorPage(). Specifically, the actual error message is displayed in the following two lines:
$this->prepareErrorPage( $this->msg( 'loginreqtitle' ) ); $this->addHTML( $this->msg( $msg )->rawParams( $loginLink )->parse() );
To redirect directly to Special:UserLogin, you could replace them with something like this (untested!) code:
$this->redirect( SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( $query ) );
Alas, there doesn't seem to be any convenient hook in place that would let you do this from an extension, so it looks like you'll have to resort to patching the code. This does look like a natural place for a hook, so it might not be a bad idea to file a feature request asking that such a hook be added.
(Alternatively, you could indeed output a login form in place, but that might be a bit trickier to implement than just redirecting to Special:UserLogin. At a glance, I couldn't find any convenient "outputLoginForm()" method to call in the Special:UserLogin code, and while it's not actually hard to generate a matching login form yourself, that would mean that any later changes to the form might break compatibility.)