与Bot用户一起从MediaWiki中的受保护页面读取内容

时间:2019-06-02 02:44:20

标签: mediawiki mediawiki-api

使用管理员用户,我创建了一个专用用户来拥有机器人。我将此机器人添加到“机器人”组。我使用该用户登录并为我的应用创建了BotPassword

我在LocalSettings.php

中定义了以下配置选项
$wgGroupPermissions['*']['read'] = false;
$wgGroupPermissions['bot']['read'] = true;

从我的应用程序中,我可以在获得令牌后使用Login API成功登录:

登录

{
    "login": {
        "result":"Success",
        "lguserid":11,
        "lgusername":"botuser@example.org"
    }
}

但是,使用以下参数查询页面:

ArrayList<BasicNameValuePair> queryParameters = new ArrayList<>();
queryParameters.add(new BasicNameValuePair("action", "query"));
queryParameters.add(new BasicNameValuePair("prop", "revisions"));
queryParameters.add(new BasicNameValuePair("rvprop", "content"));
queryParameters.add(new BasicNameValuePair("format", "json"));
queryParameters.add(new BasicNameValuePair("formatversion", "2"));
queryParameters.add(new BasicNameValuePair("rvslots", "main"));
queryParameters.add(new BasicNameValuePair("titles", pageName));

我得到了错误:

{
    "error": {
        "code":"readapidenied",
        "info":"You need read permission to use this module.",
        "docref":"See https://wiki.example.org/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes."
    }
}

如果我在LocalSettings中授予全局读取权限,

$wgGroupPermissions['*']['read'] = true;

我的应用程序正常运行,没有错误,我可以下载页面-

如何授予该机器人权限,以便我可以查询页面内容而不会出现 readapidenied 错误,同时仍保持我的Wiki私有? BotPassword帐户与主要用户位于不同的组中吗?如果是这样,如何更改机器人的组?

1 个答案:

答案 0 :(得分:1)

您需要在Special:BotPasswords中设置机器人可以访问的权限。这样做的想法是,与实际密码(可能包含在某些共享服务器上的某些bot配置文件中)相比,您的bot密码存储的安全性较差,因此您将希望限制其用途。

相关问题