====== XML-RPC ====== [[:experimental]] [[:DokuWiki]] has an experimental [[wp>XML-RPC]] API which can be used to access/interact with your wiki from other applications. The API implements the [[http://www.jspwiki.org/wiki/WikiRPCInterface2|Wiki RPC Interface 2.0 Specifications]] in the ''wiki.*'' namespace and adds additional DokuWiki specific calls in the ''dokuwiki.*'' namespace. Questions and suggestions to extend and improve the API should be directed to the [[:mailinglist]]. ===== Get It Working ===== - You need at least the 2008-03-31 release of [[:DokuWiki]]. - Enable the XML-RPC interface in the "Advanced Options" section - Set the [[config:xmlrpcuser]] option - For security reasons it's safer to allow access to the XML-RPC over HTTPS only. The ''.htaccess.dist'' in the development version of DokuWiki contains some rewrite rules to do that. ===== Accessing The XML-RPC Interface ===== You can access the XML-RPC interface via the following URL: http:///lib/exe/xmlrpc.php https:///lib/exe/xmlrpc.php ===== Sample XML Requests ===== Here is an example of how to post to the API: POST /RPC2 HTTP/1.0 User-Agent: Frontier/5.1.2 (WinNT) Host: betty.userland.com Content-Type: text/xml Content-length: 181 examples.getStateName 41 dokuwiki.getVersion ===== Available Functions ===== Functions are listed in the following format: ^ Name | The name of the function | ^ Parameters | A list of parameters to pass to the function | ^ Data | The type of the returned data | ^ Description | Short explanation what the function does | ==== dokuwiki.getPagelist ==== ^ Name | ''dokuwiki.getPagelist'' | ^ Parameters | (string) namespace, (array) options | ^ Data | (array) list of page items | ^ Description | Lists all pages within a given namespace. The options are passed directly to [[xref>search_allpages()]]. | ^ Since | 2009-03-06 (1) | ==== dokuwiki.getVersion ==== ^ Name | ''dokuwiki.getVersion'' | ^ Parameters | - | ^ Data | (string) version number | ^ Description | Returns the [[:DokuWiki]] version of the remote Wiki. | ==== dokuwiki.getTime ==== ^ Name | ''dokuwiki.getTime'' | ^ Parameters | - | ^ Data | (int) timestamp | ^ Description | Returns the current time at the remote wiki server as Unix timestamp | ^ Since | 2009-03-06 (1) | ==== dokuwiki.getXMLRPCAPIVersion ==== ^ Name | ''dokuwiki.getXMLRPCAPIVersion'' | ^ Parameters | - | ^ Data | (int) version number | ^ Description | Returns the XML RPC interface version of the remote Wiki. This is DokuWiki implementation specific and independent of the supported standard API version returned by wiki.getRPCVersionSupported | ^ Since | 2009-03-06 (1) | ==== dokuwiki.login ==== ^ Name | ''dokuwiki.login'' | ^ Parameters | (string) user, (string) password | ^ Data | (boolean) login successful | ^ Description | Uses the provided credentials to execute a login and will set cookies. This can be used to make authenticated requests afterwards. Your client needs to support cookie handling. Alternatively use HTTP basic auth credentials. | ^ Since | 2009-03-06 (1) | ==== dokuwiki.search ==== ^ Name | ''dokuwiki.search'' | ^ Parameters | (string) a query string as described on [[:search]] | ^ Data | (array) associative array with matching pages similar to what is returned by ''dokuwiki.getPagelist'', snippets are provided for the first 15 results | ^ Description | Performs a fulltext search | ^ Since | 2010-02-28 (3) | ==== dokuwiki.getTitle ==== ^ Name | ''dokuwiki.getTitle'' | ^ Parameters | - | ^ Data | (string) the title of the wiki | ^ Description | Returns the title of the wiki | ^ Since | 2010-04-18 (4) | ==== dokuwiki.appendPage ==== ^ Name | ''dokuwiki.appendPage '' | ^ Parameters | (string) [[:pagename]], (string) raw Wiki text, (array) attrs\\ Where ''attrs'' can contain the following:\\ $attrs['sum'] = (string) change summary $attrs['minor'] = (boolean) minor | ^ Data | (boolean) | ^ Description | Appends text to a Wiki Page. | ^ Since | 2010-11-20 (5) | ==== dokuwiki.setLocks ==== ^ Name | ''dokuwiki.setLocks'' | ^ Parameters | (array) list of two lists of page ids array('lock'=>array(...), 'unlock'=>array(...)) | ^ Data | (array) array with 4 lists of pageids array('locked'=>array(...), 'lockfail'=>array(...), 'unlocked'=>array(...), 'unlockfail'=>array(...)) | ^ Description | Allows you to lock or unlock a whole bunch of pages at once. Useful when you are about to do a operation over multiple pages | ^ Since | 2009-03-06 (1) | ==== wiki.getRPCVersionSupported ==== ^ Name | ''wiki.getRPCVersionSupported'' | ^ Parameters | - | ^ Data | (string) version number | ^ Description | Returns 2 with the supported RPC API version. | ==== wiki.getPage ==== ^ Name | ''wiki.getPage'' | ^ Parameters | (string) [[:pagename]] | ^ Data | (string) raw Wiki text | ^ Description | Returns the raw Wiki text for a page. | ==== wiki.getPageVersion ==== ^ Name | ''wiki.getPageVersion'' | ^ Parameters | (string) [[:pagename]], (int) Timestamp | ^ Data | (string) raw Wiki text | ^ Description | Returns the raw Wiki text for a specific revision of a Wiki page. | ==== wiki.getPageVersions ==== ^ Name | ''wiki.getPageVersions'' | ^ Parameters | (string) [[:pagename]], (int) offset | ^ Data | (array) each array item holds the following data: \\ \\ $data['user'] = username $data['ip'] = ip address $data['type'] = type of change $data['sum'] = summary $data['modified'] = modification date as UTC timestamp $data['version'] = page version as timestamp | ^ Description | Returns the available versions of a Wiki page. The number of pages in the result is controlled via the [[:config:recent]] configuration setting. The offset can be used to list earlier versions in the history. | ==== wiki.getPageInfo ==== ^ Name | ''wiki.getPageInfo'' | ^ Parameters | (string) [[:pagename]] | ^ Data | (array) an array containing the following data: \\ \\ $data['name'] = [[:pagename]] $data['lastModified'] = modifaction date as UTC timestamp $data['author'] = author of the Wiki page. $data['version'] = page version as timestamp | ^ Description | Returns information about a Wiki page. | ==== wiki.getPageInfoVersion ==== ^ Name | ''wiki.getPageInfoVersion'' | ^ Parameters | (string) [[:pagename]], (int) timestamp | ^ Data | (array) an array containing the following data: \\ \\ $data['name'] = [[:pagename]] $data['lastModified'] = modification date as UTC timestamp $data['author'] = author of the Wiki page. $data['version'] = page version as timestamp | ^ Description | Returns information about a specific version of a Wiki page. | ==== wiki.getPageHTML ==== ^ Name | ''wiki.getPageHTML'' | ^ Parameters | (string) [[:pagename]] | ^ Data | (string) rendered HTML | ^ Description | Returns the rendered XHTML body of a Wiki page. | ==== wiki.getPageHTMLVersion ==== ^ Name | ''wiki.getPageHTMLVersion'' | ^ Parameters | (string) [[:pagename]], (int) timestamp | ^ Data | (string) rendered HTML | ^ Description | Returns the rendered HTML of a specific version of a Wiki page. | ==== wiki.putPage ==== ^ Name | ''wiki.putPage'' | ^ Parameters | (string) [[:pagename]], (string) raw Wiki text, (array) attrs\\ Where ''attrs'' can contain the following:\\ $attrs['sum'] = (string) change summary $attrs['minor'] = (boolean) minor | ^ Data | (boolean) | ^ Description | Saves a Wiki Page. | ==== wiki.listLinks ==== ^ Name | ''wiki.listLinks'' | ^ Parameters | (string) [[:pagename]] | ^ Data | (array) each array item holds the following data: \\ \\ $data['type'] = local/extern $data['page'] = the wiki page (or the complete URL if extern) $data['href'] = the complete URL | ^ Description | Returns a list of all links contained in a Wiki page. | ==== wiki.getAllPages ==== ^ Name | ''wiki.getAllPages'' | ^ Parameters | - | ^ Data | (array) One item for each page, each item containing the following data: \\ \\ $data['id'] = id of the page $data['perms'] = integer denoting the permissions on the page $data['size'] = size in bytes $data['lastModified'] = dateTime object of last modification date | ^ Description | Returns a list of all Wiki pages in the remote Wiki. | ==== wiki.getBackLinks ==== ^ Name | ''wiki.getBackLinks'' | ^ Parameters | (string) [[:pagename]] | ^ Data | (array) | ^ Description | Returns a list of [[:backlinks]] of a Wiki page. | ==== wiki.getRecentChanges ==== ^ Name | ''wiki.getRecentChanges'' | ^ Parameters | (int) timestamp | ^ Data | (array) each array item holds the following data: \\ \\ $data['name'] = page id $data['lastModified'] = modification date as UTC timestamp $data['author'] = author $data['version'] = page version as timestamp | ^ Description | Returns a list of recent changes since given timestamp. | ==== wiki.getAttachments ==== ^ Name | ''wiki.getAttachments'' | ^ Parameters | (String) namespace, (array) options | ^ Data | (array) each array item holds the following data: \\ \\ $data['id'] = media id $data['size'] = size in bytes $data['lastModified'] = modification date as XMLRPC Date object $data['isimg'] = true if file is an image, false otherwise $data['writable'] = true if file is writable, false otherwise $data['perms'] = permissions of file | ^ Description | Returns a list of media files in a given namespace. Available options are: \\ \\ $options['recursive'] = true if also files in subnamespaces are to be included, defaults to false $options['pattern'] = an optional PREG compatible regexp which has to match the file id | ==== wiki.getAttachment ==== ^ Name | ''wiki.getAttachment'' | ^ Parameters | (String) id | ^ Data | (string) the data of the file, encoded in base64 | ^ Description | Returns the binary data of a media file | ==== wiki.getAttachmentInfo ==== ^ Name | ''wiki.getAttachmentInfo'' | ^ Parameters | (String) id | ^ Data | (array) an array containing the following information about the file: \\ \\ $data['size'] = size in bytes $data['lastModified'] = modification date as XMLRPC Date object | ^ Description | Returns information about a media file | ==== wiki.putAttachment ==== ^ Name | ''wiki.putAttachment'' | ^ Parameters | (String) id, (base64) data, (array) params | ^ Data | | ^ Description | Uploads a file as a given media id. Available parameters are: \\ \\ $params['ow'] = true if file is to overwrite an already existing media object of the given id | ==== wiki.deleteAttachment ==== ^ Name | ''wiki.deleteAttachment'' | ^ Parameters | (String) id | ^ Data | | ^ Description | Deletes a file. Fails if the file is still referenced from any page in the wiki. | ===== Sample PHP Client ===== This simple example will pull the version information from the given Dokuwiki. * You need to download and install the library [[http://phpxmlrpc.sourceforge.net/|XML-RPC for PHP]] for this example. * The URL of the DW-Server must be given **without** the procotol (http://). setDebug(1); // create the XML message to send $m = new xmlrpcmsg('dokuwiki.getVersion'); // send the message and wait for response $r = $c->send($m); if($r == false) die('error'); if(!$r->faultCode()){ // seems good. Now do whatever you want with the data $v = php_xmlrpc_decode($r->value()); echo "$v"; } setDebug = 1; $m = new xmlrpcmsg('wiki.putAttachment'); $m->addParam(new xmlrpcval("file.png", "string")); $m->addParam(new xmlrpcval("iVBORw0KGgoAAAANSUhEUgAAADAAAAAwC........", "base64")); $m->addParam(new xmlrpcval(array("ow" => new xmlrpcval(true, "boolean")), "struct")); $r = $c->send($m); if($r == false) die('foo!'); // Output the response object // var_dump($r); $r = $c->send($m); if(!$r->faultCode()) { $v = php_xmlrpc_decode($r->value()); echo $v; } else { echo $r->faultString(); } ?> ---- DokuWiki has it's own XMLRPC library which could also be used. A simple client using that library could look like this: debug = 1; // enable for debugging $ok = $client->query('dokuwiki.login','admin','pass'); if($ok) echo $client->query('wiki.getPage','wiki:syntax'); ===== Sample RubyClient ===== This simple example will pull the version information from the given Dokuwiki. No plugin required(in the Windows default package). require "xmlrpc/client" server = XMLRPC::Client.new( "localhost","/dokuwiki/lib/exe/xmlrpc.php") begin puts server.call("dokuwiki.getVersion") rescue XMLRPC::FaultException => e puts "Error:" puts e.faultCode puts e.faultString end ===== Sample jQuery Client ===== var xml='wiki.getRPCVersionSupported'; $.ajax({ url: "http:///wiki/lib/exe/xmlrpc.php", data: xml, contentType:"text/xml", type:"post" }); ===== Python Module ===== A python module for DokuWikis XML-RPC API can be found at the [[http://pypi.python.org/pypi?name=dokuwikixmlrpc&:action=display|Python package index]]. ===== Sample AutoIt3 Client ===== My AutoIt3 client is mainly a proof of concept: #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.1 Author: Hugo Bossard Script Function: Xmlrpc sample client AutoIt3 script. #ce ---------------------------------------------------------------------------- ; this script uses the UDF WinHttp #include "WinHTTP.au3" ; get the info from page 'wiki:syntax' using wiki.getPageInfo() $Xml = '' $Xml = $Xml & @CRLF & '' $Xml = $Xml & @CRLF & 'wiki.getPageInfo' $Xml = $Xml & @CRLF & '' $Xml = $Xml & @CRLF & '' $Xml = $Xml & @CRLF & '' $Xml = $Xml & @CRLF & 'wiki:syntax' $Xml = $Xml & @CRLF & '' $Xml = $Xml & @CRLF & '' $Xml = $Xml & @CRLF & '' $Xml = $Xml & @CRLF & '' $XmlSize = StringLen($Xml) ; initializes the use of WinHTTP functions and returns a WinHTTP-session handle. $hw_open = _WinHttpOpen() ; creates a HTTP request handle to a lokal DokuWikiStick installation on port 8800 $hw_connect = _WinHttpConnect($hw_open, "localhost", 8800) ; creates a HTTP request handle $h_openRequest = _WinHttpOpenRequest($hw_connect, "POST", "/lib/exe/xmlrpc.php", "/RPC2 HTTP/1.0", "localhost", "text/xml") ; sends the specified request to the HTTP server _WinHttpSendRequest($h_openRequest, "", $Xml, $XmlSize) ; waits to receive the response to a HTTP request initiated by WinHttpSendRequest(). _WinHttpReceiveResponse($h_openRequest) $Data = "" Do ; reads data from a handle opened by the _WinHttpOpenRequest() function. $Data&=_WinHttpReadData($h_openRequest) Until @error ; close connection and clean up _WinHttpCloseHandle($h_openRequest) _WinHttpCloseHandle($hw_connect) _WinHttpCloseHandle($hw_open) ; show error number and resulting data MsgBox(4096,"Error: " & @error, $Data)