Action

Load from DokuWiki

Posted by jneug, Last update over 3 years ago - Unlisted

Loading pages content from a DokuWIki instance with the xmlrpc api enabled.

Steps

  • script

    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 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');
    //save_page('testseite');

Options

  • After Success Nothing
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.