[英]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. 我正在尝试设置一个私有的Mediawiki实例,希望用户登录以查看任何内容。 I tried tweaking the $wgWhitelistRead variable in the Localsettings.php file but it still takes me to a page that says, "Login Required".
我尝试在Localsettings.php文件中调整$ wgWhitelistRead变量,但它仍然会将我带到一个页面,上面写着“需要登录”。 I want the wiki to redirect to Special:userLogin if a user is not logged in. How do I do this?
如果用户没有登录,我希望wiki重定向到Special:userLogin。我该怎么办?
I found a similar question on the mwforums but it seems to be for an older version of mediawiki. 我在mwforums上发现了类似的问题,但似乎是旧版本的mediawiki。 Any ideas?
有任何想法吗?
The seemingly natural place to do this would be in OutputPage::showPermissionsErrorPage() . 看似自然的地方是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: 要直接重定向到Special:UserLogin,您可以使用类似这样的(未经测试的!)代码替换它们:
$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.) (或者,您确实可以输出一个登录表单,但实现起来可能比仅重定向到Special:UserLogin有点棘手。乍一看,我找不到任何方便的“outputLoginForm()”方法来调用Special:UserLogin代码 ,虽然实际上并不难自己生成匹配的登录表单,但这意味着对表单的任何后续更改都可能会破坏兼容性。)
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). 作为一个特别可怕的黑客,您可以将登录表单放入需要登录时显示的消息(应该是
loginreqpagetext
消息)。 It would be non-trivial due to the anti-CSRF protection, but you can work around that via AJAX. 由于反CSRF保护,这将是非平凡的,但您可以通过AJAX解决这个问题。 (There are surely much better solutions; this is just the quick and dirty way of doing it.)
(肯定有更好的解决方案;这只是快速而肮脏的方式。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.