Pergunta

I'm trying to use the gwtwiki Java library to interact with a private wiki (MediaWiki 1.19.5 on Mint Linux) and I'm having difficulty creating a new wiki page.

The wiki runs fine, I can connect and edit an existing page fine but creation fails with the error:

info.bliki.api.UnexpectedAnswerException: The specified page was not found

My code:

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();
}

It appears that the problem is in the library, as it does a query (which returns a null pageid before the edit command is issued. The line is in the edit(....) method in Connector.java:

if (pages != null && pages.size() == 1 && pages.get(0).getPageid() != null) {
...

Using the debugger to force it to pass the null pageid check allows my page creation to succeed.

So, what am I doing wrong? Does gwtwiki support page creation? If so, how do I do it?

Foi útil?

Solução

As a workaround, rather than a full answer, I subclassed the Connector class to allow me to override the edit method to remove the pageId null check that was causing the problem.

I've not fully tested it so there may be other implications but this has solved the problem as far as I require at the moment. Will update if I discover a better, more general, approach.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top