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

六月ゝ 毕业季﹏ 提交于 2019-12-10 13:22:36

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/11123554/how-can-i-change-the-landing-page-of-mediawiki-1-19-1-to-directly-go-to-special

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!