我正在尝试使用gwtwiki Java 库与私有 wiki(Mint Linux 上的 MediaWiki 1.19.5)进行交互,但我在创建新的 wiki 页面时遇到了困难。
wiki 运行良好,我可以正常连接和编辑现有页面,但创建失败并出现错误:
info.bliki.api.UnexpectedAnswerException: The specified page was not found
我的代码:
Connector connection = new Connector();
User user = new User("username", "password", "http://xxxx/mediawiki/api.php");
connection.login(user);
StringBuilder page = new StringBuilder();
page.append("== Test page ==\r\n");
page.append("Some page text");
String title = Encoder.encodeTitleToUrl("Test page", true);
Edit newPage = Edit.create()
.title(title)
.text(page.toString());
try {
connection.edit(user, newPage);
} catch (UnexpectedAnswerException e) {
e.printStackTrace();
}
似乎问题出在库中,因为它在发出命令之前query
返回 null 。该行在Connector.java的方法中:pageid
edit
edit(....)
if (pages != null && pages.size() == 1 && pages.get(0).getPageid() != null) {
...
使用调试器强制它通过 null pageid 检查允许我的页面创建成功。
那么,我做错了什么?gwtwiki 是否支持页面创建?如果是这样,我该怎么做?