Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the landing page of Mediawiki 1.19.1 to directly go to Special:UserLogin

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?

like image 260
Ritesh M Nayak Avatar asked Jun 20 '12 16:06

Ritesh M Nayak


2 Answers

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.)

like image 81
Ilmari Karonen Avatar answered Nov 04 '22 12:11

Ilmari Karonen


As a particularly horrible hack, you could put the login form into the message displayed when login is needed (that should be the loginreqpagetext message). It would be non-trivial due to the anti-CSRF protection, but you can work around that via AJAX. (There are surely much better solutions; this is just the quick and dirty way of doing it.)

like image 20
Tgr Avatar answered Nov 04 '22 11:11

Tgr