I want to load / save data from / to my DokuWiki using the XMLRPC scripting object. So far I’m able to request data from the wiki and load it into a draft, but the content always is HTML escaped. I can easily fix that by running the returned text through HTML.unescape()
, but I can’t do that when sending the draft back to the server.
Something like <box>My content</box>
will end up as <box>My content</box>
on the actual wiki page.
EDIT: Actually, the text looks like this: <box>My content</box>
. Only the opending brackets are escaped in DokuWiki. Here is my test page: http://www.helmholtz-it.de/testseite
Is this the expected behavior for the xmlrpc api or am I missing something? I would have thought, that the XMLRPC object would handle any escaping for me.
Here is the code and an example action:
function get_credentials() {
const c =
Credential
.createWithHostUsernamePassword(
'DokuWiki default',
'Enter credentials for accessing your DokuWiki instance.'
);
c.authorize();
return {
username: c.getValue('username'),
password: c.getValue('password'),
host: c.getValue('host')
}
}
function login() {
const cred = get_credentials();
const url = `${cred.host}/lib/exe/xmlrpc.php`;
let response = XMLRPC.request(
url,
'dokuwiki.login',
[cred.username, cred.password]
);
if (!response.success) {
alert(response.error);
context.fail();
return false;
} else {
return response.params[0];
}
}
function load_page(id) {
const cred = get_credentials();
const url = `${cred.host}/lib/exe/xmlrpc.php`;
let response = XMLRPC.request(
url,
'wiki.getPage',
[id]
);
if (response.success) {
//draft.content = HTML.unescape(response.params[0]);
draft.content = response.params[0];
draft.update();
retry = false;
} else {
alert(response.error);
context.fail();
}
}
function save_page(id) {
const cred = get_credentials(id);
const url = `${cred.host}/lib/exe/xmlrpc.php`;
let response = XMLRPC.request(
url,
'wiki.putPage',
[id, draft.content, []]
);
if (!response.success) {
alert(response.error);
context.fail();
}
}
login();
load_page('testseite');
// sace_page('testseite');