1797c0d11SAndreas Gohr<?php 27aec69d1SGuy Brandif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); 3797c0d11SAndreas Gohr 4797c0d11SAndreas Gohr// fix when '<?xml' isn't on the very first line 5797c0d11SAndreas Gohrif(isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); 6797c0d11SAndreas Gohr 7*445e8084SAndreas Gohr/** 8*445e8084SAndreas Gohr * Increased whenever the API is changed 9*445e8084SAndreas Gohr */ 10*445e8084SAndreas Gohrdefine('DOKU_XMLRPC_API_VERSION',1); 11797c0d11SAndreas Gohr 12797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php'); 13797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/common.php'); 14797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/auth.php'); 15797c0d11SAndreas Gohrsession_write_close(); //close session 16593bf8f6SMichael Klier 17593bf8f6SMichael Klierif(!$conf['xmlrpc']) { 18593bf8f6SMichael Klier die('XML-RPC server not enabled.'); 19593bf8f6SMichael Klier // FIXME check for groups allowed 20593bf8f6SMichael Klier} 21593bf8f6SMichael Klier 22797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/IXR_Library.php'); 23797c0d11SAndreas Gohr 24797c0d11SAndreas Gohr 25797c0d11SAndreas Gohr/** 26797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available 27797c0d11SAndreas Gohr * XMLRPC functions. 28797c0d11SAndreas Gohr */ 29797c0d11SAndreas Gohrclass dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { 30797c0d11SAndreas Gohr var $methods = array(); 31797c0d11SAndreas Gohr 32797c0d11SAndreas Gohr /** 33797c0d11SAndreas Gohr * Constructor. Register methods and run Server 34797c0d11SAndreas Gohr */ 35797c0d11SAndreas Gohr function dokuwiki_xmlrpc_server(){ 36797c0d11SAndreas Gohr $this->IXR_IntrospectionServer(); 37797c0d11SAndreas Gohr 38797c0d11SAndreas Gohr /* DokuWiki's own methods */ 39797c0d11SAndreas Gohr $this->addCallback( 40*445e8084SAndreas Gohr 'dokuwiki.getXMLRPCAPIVersion', 41*445e8084SAndreas Gohr 'this:getAPIVersion', 42*445e8084SAndreas Gohr array('integer'), 43*445e8084SAndreas Gohr 'Returns the XMLRPC API version.' 44*445e8084SAndreas Gohr ); 45*445e8084SAndreas Gohr 46*445e8084SAndreas Gohr $this->addCallback( 47797c0d11SAndreas Gohr 'dokuwiki.getVersion', 48797c0d11SAndreas Gohr 'getVersion', 49797c0d11SAndreas Gohr array('string'), 50fdd2e9d6SMichael Klier 'Returns the running DokuWiki version.' 51797c0d11SAndreas Gohr ); 52797c0d11SAndreas Gohr 531b11c097SAndreas Gohr $this->addCallback( 54*445e8084SAndreas Gohr 'dokuwiki.login', 55*445e8084SAndreas Gohr 'this:login', 56*445e8084SAndreas Gohr array('integer','string','string'), 57*445e8084SAndreas Gohr 'Tries to login with the given credentials and sets auth cookies.' 58*445e8084SAndreas Gohr ); 59*445e8084SAndreas Gohr 60*445e8084SAndreas Gohr $this->addCallback( 611b11c097SAndreas Gohr 'dokuwiki.getPagelist', 621b11c097SAndreas Gohr 'this:readNamespace', 631b11c097SAndreas Gohr array('struct','string','struct'), 641b11c097SAndreas Gohr 'List all pages within the given namespace.' 651b11c097SAndreas Gohr ); 661b11c097SAndreas Gohr 671b11c097SAndreas Gohr $this->addCallback( 681b11c097SAndreas Gohr 'dokuwiki.getTime', 691b11c097SAndreas Gohr 'time', 701b11c097SAndreas Gohr array('int'), 711b11c097SAndreas Gohr 'Return the current time at the wiki server.' 721b11c097SAndreas Gohr ); 731b11c097SAndreas Gohr 7428ec3c76SAndreas Gohr $this->addCallback( 7528ec3c76SAndreas Gohr 'dokuwiki.setLocks', 7628ec3c76SAndreas Gohr 'this:setLocks', 7728ec3c76SAndreas Gohr array('struct','struct'), 7828ec3c76SAndreas Gohr 'Lock or unlock pages.' 7928ec3c76SAndreas Gohr ); 8028ec3c76SAndreas Gohr 81797c0d11SAndreas Gohr /* Wiki API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 */ 82797c0d11SAndreas Gohr $this->addCallback( 83797c0d11SAndreas Gohr 'wiki.getRPCVersionSupported', 84797c0d11SAndreas Gohr 'this:wiki_RPCVersion', 85797c0d11SAndreas Gohr array('int'), 86fdd2e9d6SMichael Klier 'Returns 2 with the supported RPC API version.' 87797c0d11SAndreas Gohr ); 88797c0d11SAndreas Gohr $this->addCallback( 89797c0d11SAndreas Gohr 'wiki.getPage', 90797c0d11SAndreas Gohr 'this:rawPage', 91797c0d11SAndreas Gohr array('string','string'), 92797c0d11SAndreas Gohr 'Get the raw Wiki text of page, latest version.' 93797c0d11SAndreas Gohr ); 94797c0d11SAndreas Gohr $this->addCallback( 95797c0d11SAndreas Gohr 'wiki.getPageVersion', 96797c0d11SAndreas Gohr 'this:rawPage', 97797c0d11SAndreas Gohr array('string','string','int'), 98797c0d11SAndreas Gohr 'Get the raw Wiki text of page.' 99797c0d11SAndreas Gohr ); 100797c0d11SAndreas Gohr $this->addCallback( 101797c0d11SAndreas Gohr 'wiki.getPageHTML', 102797c0d11SAndreas Gohr 'this:htmlPage', 103797c0d11SAndreas Gohr array('string','string'), 104797c0d11SAndreas Gohr 'Return page in rendered HTML, latest version.' 105797c0d11SAndreas Gohr ); 106797c0d11SAndreas Gohr $this->addCallback( 107797c0d11SAndreas Gohr 'wiki.getPageHTMLVersion', 108797c0d11SAndreas Gohr 'this:htmlPage', 109797c0d11SAndreas Gohr array('string','string','int'), 110797c0d11SAndreas Gohr 'Return page in rendered HTML.' 111797c0d11SAndreas Gohr ); 112797c0d11SAndreas Gohr $this->addCallback( 113797c0d11SAndreas Gohr 'wiki.getAllPages', 114797c0d11SAndreas Gohr 'this:listPages', 115797c0d11SAndreas Gohr array('struct'), 116797c0d11SAndreas Gohr 'Returns a list of all pages. The result is an array of utf8 pagenames.' 117797c0d11SAndreas Gohr ); 118797c0d11SAndreas Gohr $this->addCallback( 11926bec61eSMichael Klier 'wiki.getAttachments', 12026bec61eSMichael Klier 'this:listAttachments', 121c63d1645SGina Haeussge array('struct', 'string', 'struct'), 12226bec61eSMichael Klier 'Returns a list of all media files.' 12326bec61eSMichael Klier ); 12426bec61eSMichael Klier $this->addCallback( 125797c0d11SAndreas Gohr 'wiki.getBackLinks', 126797c0d11SAndreas Gohr 'this:listBackLinks', 127797c0d11SAndreas Gohr array('struct','string'), 128797c0d11SAndreas Gohr 'Returns the pages that link to this page.' 129797c0d11SAndreas Gohr ); 130797c0d11SAndreas Gohr $this->addCallback( 131797c0d11SAndreas Gohr 'wiki.getPageInfo', 132797c0d11SAndreas Gohr 'this:pageInfo', 133797c0d11SAndreas Gohr array('struct','string'), 134797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 135797c0d11SAndreas Gohr ); 136797c0d11SAndreas Gohr $this->addCallback( 137797c0d11SAndreas Gohr 'wiki.getPageInfoVersion', 138797c0d11SAndreas Gohr 'this:pageInfo', 139797c0d11SAndreas Gohr array('struct','string','int'), 140797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 141797c0d11SAndreas Gohr ); 1423a1dad2dSDennis Ploeger $this->addCallback( 14373056168SMichael Klier 'wiki.getPageVersions', 14473056168SMichael Klier 'this:pageVersions', 14573056168SMichael Klier array('struct','string','int'), 14673056168SMichael Klier 'Returns the available revisions of the page.' 14773056168SMichael Klier ); 14873056168SMichael Klier $this->addCallback( 1493a1dad2dSDennis Ploeger 'wiki.putPage', 1503a1dad2dSDennis Ploeger 'this:putPage', 151222572bfSMichael Klier array('int', 'string', 'string', 'struct'), 152fdd2e9d6SMichael Klier 'Saves a wiki page.' 1533a1dad2dSDennis Ploeger ); 154beccd742SMichael Klier $this->addCallback( 155beccd742SMichael Klier 'wiki.listLinks', 156beccd742SMichael Klier 'this:listLinks', 157beccd742SMichael Klier array('struct','string'), 158fdd2e9d6SMichael Klier 'Lists all links contained in a wiki page.' 159beccd742SMichael Klier ); 16063dd0d58SMichael Klier $this->addCallback( 16163dd0d58SMichael Klier 'wiki.getRecentChanges', 16263dd0d58SMichael Klier 'this:getRecentChanges', 16363dd0d58SMichael Klier array('struct','int'), 16499c8d7f2Smichael 'Returns a struct about all recent changes since given timestamp.' 16599c8d7f2Smichael ); 16699c8d7f2Smichael $this->addCallback( 16799c8d7f2Smichael 'wiki.getRecentMediaChanges', 16899c8d7f2Smichael 'this:getRecentMediaChanges', 16999c8d7f2Smichael array('struct','int'), 17099c8d7f2Smichael 'Returns a struct about all recent media changes since given timestamp.' 17163dd0d58SMichael Klier ); 172e62b9ea5SMichael Klier $this->addCallback( 173e62b9ea5SMichael Klier 'wiki.aclCheck', 174e62b9ea5SMichael Klier 'this:aclCheck', 175c63d1645SGina Haeussge array('int', 'string'), 176e62b9ea5SMichael Klier 'Returns the permissions of a given wiki page.' 177e62b9ea5SMichael Klier ); 1782aca132fSMichael Klier $this->addCallback( 1792aca132fSMichael Klier 'wiki.putAttachment', 1802aca132fSMichael Klier 'this:putAttachment', 1812aca132fSMichael Klier array('struct', 'string', 'base64', 'struct'), 1822aca132fSMichael Klier 'Upload a file to the wiki.' 1832aca132fSMichael Klier ); 184cfef3001SGina Haeussge $this->addCallback( 185f01ff8c1SGina Haeussge 'wiki.deleteAttachment', 186f01ff8c1SGina Haeussge 'this:deleteAttachment', 187f01ff8c1SGina Haeussge array('int', 'string'), 188f01ff8c1SGina Haeussge 'Delete a file from the wiki.' 189f01ff8c1SGina Haeussge ); 190f01ff8c1SGina Haeussge $this->addCallback( 191cfef3001SGina Haeussge 'wiki.getAttachment', 192cfef3001SGina Haeussge 'this:getAttachment', 193c63d1645SGina Haeussge array('base64', 'string'), 194cfef3001SGina Haeussge 'Download a file from the wiki.' 195cfef3001SGina Haeussge ); 1965672e868SGina Haeussge $this->addCallback( 1975672e868SGina Haeussge 'wiki.getAttachmentInfo', 1985672e868SGina Haeussge 'this:getAttachmentInfo', 199c63d1645SGina Haeussge array('struct', 'string'), 2005672e868SGina Haeussge 'Returns a struct with infos about the attachment.' 2015672e868SGina Haeussge ); 202797c0d11SAndreas Gohr 203bb32615dSMichael Klier /** 204bb32615dSMichael Klier * Trigger XMLRPC_CALLBACK_REGISTER, action plugins can use this event 205bb32615dSMichael Klier * to extend the XMLRPC interface and register their own callbacks. 206bb32615dSMichael Klier * 207bb32615dSMichael Klier * Event data: 208bb32615dSMichael Klier * The XMLRPC server object: 209bb32615dSMichael Klier * 210bb32615dSMichael Klier * $event->data->addCallback() - register a callback, the second 211bb32615dSMichael Klier * paramter has to be of the form "plugin:<pluginname>:<plugin 212bb32615dSMichael Klier * method>" 213bb32615dSMichael Klier * 214bb32615dSMichael Klier * $event->data->callbacks - an array which holds all awaylable 215bb32615dSMichael Klier * callbacks 216bb32615dSMichael Klier */ 217bb32615dSMichael Klier trigger_event('XMLRPC_CALLBACK_REGISTER', $this); 218bb32615dSMichael Klier 219797c0d11SAndreas Gohr $this->serve(); 220797c0d11SAndreas Gohr } 221797c0d11SAndreas Gohr 222797c0d11SAndreas Gohr /** 223797c0d11SAndreas Gohr * Return a raw wiki page 224797c0d11SAndreas Gohr */ 225797c0d11SAndreas Gohr function rawPage($id,$rev=''){ 226797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 227797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 228797c0d11SAndreas Gohr } 2292c176304SMichael Klier $text = rawWiki($id,$rev); 2302c176304SMichael Klier if(!$text) { 2312c176304SMichael Klier $data = array($id); 2322c176304SMichael Klier return trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true); 2332c176304SMichael Klier } else { 2342c176304SMichael Klier return $text; 2352c176304SMichael Klier } 236797c0d11SAndreas Gohr } 237797c0d11SAndreas Gohr 238797c0d11SAndreas Gohr /** 239cfef3001SGina Haeussge * Return a media file encoded in base64 240c63d1645SGina Haeussge * 241c63d1645SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 242cfef3001SGina Haeussge */ 243cfef3001SGina Haeussge function getAttachment($id){ 244c63d1645SGina Haeussge $id = cleanID($id); 245cfef3001SGina Haeussge if (auth_quickaclcheck(getNS($id).':*') < AUTH_READ) 246cfef3001SGina Haeussge return new IXR_Error(1, 'You are not allowed to read this file'); 247cfef3001SGina Haeussge 248cfef3001SGina Haeussge $file = mediaFN($id); 249cfef3001SGina Haeussge if (!@ file_exists($file)) 250cfef3001SGina Haeussge return new IXR_Error(1, 'The requested file does not exist'); 251cfef3001SGina Haeussge 252cfef3001SGina Haeussge $data = io_readFile($file, false); 253cfef3001SGina Haeussge $base64 = base64_encode($data); 254cfef3001SGina Haeussge return $base64; 255cfef3001SGina Haeussge } 256cfef3001SGina Haeussge 257cfef3001SGina Haeussge /** 2585672e868SGina Haeussge * Return info about a media file 2595672e868SGina Haeussge * 2605672e868SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 2615672e868SGina Haeussge */ 2625672e868SGina Haeussge function getAttachmentInfo($id){ 2635672e868SGina Haeussge $id = cleanID($id); 2645672e868SGina Haeussge $info = array( 2655672e868SGina Haeussge 'lastModified' => 0, 2665672e868SGina Haeussge 'size' => 0, 2675672e868SGina Haeussge ); 2685672e868SGina Haeussge 2695672e868SGina Haeussge $file = mediaFN($id); 2705672e868SGina Haeussge if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){ 2715672e868SGina Haeussge $info['lastModified'] = new IXR_Date(filemtime($file)); 2725672e868SGina Haeussge $info['size'] = filesize($file); 2735672e868SGina Haeussge } 2745672e868SGina Haeussge 2755672e868SGina Haeussge return $info; 2765672e868SGina Haeussge } 2775672e868SGina Haeussge 2785672e868SGina Haeussge /** 279797c0d11SAndreas Gohr * Return a wiki page rendered to html 280797c0d11SAndreas Gohr */ 281797c0d11SAndreas Gohr function htmlPage($id,$rev=''){ 282797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 283797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 284797c0d11SAndreas Gohr } 285797c0d11SAndreas Gohr return p_wiki_xhtml($id,$rev,false); 286797c0d11SAndreas Gohr } 287797c0d11SAndreas Gohr 288797c0d11SAndreas Gohr /** 289797c0d11SAndreas Gohr * List all pages - we use the indexer list here 290797c0d11SAndreas Gohr */ 291797c0d11SAndreas Gohr function listPages(){ 292dfd13e55SMichael Klier global $conf; 293dfd13e55SMichael Klier 294dfd13e55SMichael Klier $list = array(); 295dfd13e55SMichael Klier $pages = file($conf['indexdir'] . '/page.idx'); 296dfd13e55SMichael Klier $pages = array_filter($pages, 'isVisiblePage'); 297dfd13e55SMichael Klier 298dfd13e55SMichael Klier foreach(array_keys($pages) as $idx) { 299dfd13e55SMichael Klier if(page_exists($pages[$idx])) { 300dfd13e55SMichael Klier $perm = auth_quickaclcheck($pages[$idx]); 301dfd13e55SMichael Klier if($perm >= AUTH_READ) { 302dfd13e55SMichael Klier $page = array(); 303dfd13e55SMichael Klier $page['id'] = trim($pages[$idx]); 304dfd13e55SMichael Klier $page['perms'] = $perm; 305dfd13e55SMichael Klier $page['size'] = @filesize(wikiFN($pages[$idx])); 306e070c6f3SGina Haeussge $page['lastModified'] = new IXR_Date(@filemtime(wikiFN($pages[$idx]))); 307dfd13e55SMichael Klier $list[] = $page; 308dfd13e55SMichael Klier } 309dfd13e55SMichael Klier } 310dfd13e55SMichael Klier } 311dfd13e55SMichael Klier 312dfd13e55SMichael Klier return $list; 313797c0d11SAndreas Gohr } 314797c0d11SAndreas Gohr 315797c0d11SAndreas Gohr /** 3161b11c097SAndreas Gohr * List all pages in the given namespace (and below) 3171b11c097SAndreas Gohr */ 3181b11c097SAndreas Gohr function readNamespace($ns,$opts){ 3191b11c097SAndreas Gohr global $conf; 3201b11c097SAndreas Gohr 3211b11c097SAndreas Gohr if(!is_array($opts)) $opts=array(); 3221b11c097SAndreas Gohr 3231b11c097SAndreas Gohr $ns = cleanID($ns); 3241b11c097SAndreas Gohr $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 3251b11c097SAndreas Gohrdbglog('ggg'); 3261b11c097SAndreas Gohr $data = array(); 3271b11c097SAndreas Gohr require_once(DOKU_INC.'inc/search.php'); 3281b11c097SAndreas Gohr search($data, $conf['datadir'], 'search_allpages', $opts, $dir); 3291b11c097SAndreas Gohrdbglog($data); 3301b11c097SAndreas Gohr return $data; 3311b11c097SAndreas Gohr } 3321b11c097SAndreas Gohr 3331b11c097SAndreas Gohr /** 33426bec61eSMichael Klier * List all media files. 3353275953aSGina Haeussge * 3363275953aSGina Haeussge * Available options are 'recursive' for also including the subnamespaces 3373275953aSGina Haeussge * in the listing, and 'pattern' for filtering the returned files against 3383275953aSGina Haeussge * a regular expression matching their name. 3393275953aSGina Haeussge * 3403275953aSGina Haeussge * @author Gina Haeussge <osd@foosel.net> 34126bec61eSMichael Klier */ 3423275953aSGina Haeussge function listAttachments($ns, $options = array()) { 34326bec61eSMichael Klier global $conf; 34426bec61eSMichael Klier global $lang; 34526bec61eSMichael Klier 34626bec61eSMichael Klier $ns = cleanID($ns); 34726bec61eSMichael Klier 3483275953aSGina Haeussge if (!is_array($options)) 3493275953aSGina Haeussge $options = array(); 3503275953aSGina Haeussge 3513275953aSGina Haeussge 35226bec61eSMichael Klier if(auth_quickaclcheck($ns.':*') >= AUTH_READ) { 35326bec61eSMichael Klier $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 35426bec61eSMichael Klier 35526bec61eSMichael Klier $data = array(); 35626bec61eSMichael Klier require_once(DOKU_INC.'inc/search.php'); 357224122cfSAndreas Gohr search($data, $conf['mediadir'], 'search_media', $options, $dir); 358224122cfSAndreas Gohr $len = count($data); 359224122cfSAndreas Gohr if(!$len) return array(); 36026bec61eSMichael Klier 361224122cfSAndreas Gohr for($i=0; $i<$len; $i++) { 362224122cfSAndreas Gohr unset($data[$i]['meta']); 363224122cfSAndreas Gohr $data[$i]['lastModified'] = new IXR_Date($data[$i]['mtime']); 36426bec61eSMichael Klier } 365224122cfSAndreas Gohr return $data; 36626bec61eSMichael Klier } else { 36726bec61eSMichael Klier return new IXR_Error(1, 'You are not allowed to list media files.'); 36826bec61eSMichael Klier } 36926bec61eSMichael Klier } 37026bec61eSMichael Klier 37126bec61eSMichael Klier /** 372797c0d11SAndreas Gohr * Return a list of backlinks 373797c0d11SAndreas Gohr */ 374beccd742SMichael Klier function listBackLinks($id){ 375797c0d11SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 376797c0d11SAndreas Gohr return ft_backlinks($id); 377797c0d11SAndreas Gohr } 378797c0d11SAndreas Gohr 379797c0d11SAndreas Gohr /** 38063dd0d58SMichael Klier * Return some basic data about a page 381797c0d11SAndreas Gohr */ 382797c0d11SAndreas Gohr function pageInfo($id,$rev=''){ 383797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 384797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 385797c0d11SAndreas Gohr } 386797c0d11SAndreas Gohr $file = wikiFN($id,$rev); 387797c0d11SAndreas Gohr $time = @filemtime($file); 388797c0d11SAndreas Gohr if(!$time){ 389797c0d11SAndreas Gohr return new IXR_Error(10, 'The requested page does not exist'); 390797c0d11SAndreas Gohr } 391797c0d11SAndreas Gohr 392797c0d11SAndreas Gohr $info = getRevisionInfo($id, $time, 1024); 393797c0d11SAndreas Gohr 394797c0d11SAndreas Gohr $data = array( 395797c0d11SAndreas Gohr 'name' => $id, 396797c0d11SAndreas Gohr 'lastModified' => new IXR_Date($time), 397797c0d11SAndreas Gohr 'author' => (($info['user']) ? $info['user'] : $info['ip']), 398797c0d11SAndreas Gohr 'version' => $time 399797c0d11SAndreas Gohr ); 40063dd0d58SMichael Klier 40163dd0d58SMichael Klier return ($data); 402797c0d11SAndreas Gohr } 403797c0d11SAndreas Gohr 404797c0d11SAndreas Gohr /** 4053a1dad2dSDennis Ploeger * Save a wiki page 406222572bfSMichael Klier * 407222572bfSMichael Klier * @author Michael Klier <chi@chimeric.de> 4083a1dad2dSDennis Ploeger */ 409222572bfSMichael Klier function putPage($id, $text, $params) { 4103a1dad2dSDennis Ploeger global $TEXT; 411a6a229ceSMichael Klier global $lang; 412593bf8f6SMichael Klier global $conf; 4133a1dad2dSDennis Ploeger 414222572bfSMichael Klier $id = cleanID($id); 415222572bfSMichael Klier $TEXT = trim($text); 416222572bfSMichael Klier $sum = $params['sum']; 417222572bfSMichael Klier $minor = $params['minor']; 418222572bfSMichael Klier 419222572bfSMichael Klier if(empty($id)) 420fdd2e9d6SMichael Klier return new IXR_Error(1, 'Empty page ID'); 421222572bfSMichael Klier 42251597811SMichael Klier if(!page_exists($id) && empty($TEXT)) { 42351597811SMichael Klier return new IXR_ERROR(1, 'Refusing to write an empty new wiki page'); 42451597811SMichael Klier } 42551597811SMichael Klier 426055b0144SChris Smith if(auth_quickaclcheck($id) < AUTH_EDIT) 427222572bfSMichael Klier return new IXR_Error(1, 'You are not allowed to edit this page'); 4283a1dad2dSDennis Ploeger 4293a1dad2dSDennis Ploeger // Check, if page is locked 430222572bfSMichael Klier if(checklock($id)) 431222572bfSMichael Klier return new IXR_Error(1, 'The page is currently locked'); 432222572bfSMichael Klier 433a6a229ceSMichael Klier // SPAM check 4343a1dad2dSDennis Ploeger if(checkwordblock()) 435222572bfSMichael Klier return new IXR_Error(1, 'Positive wordblock check'); 4363a1dad2dSDennis Ploeger 437a6a229ceSMichael Klier // autoset summary on new pages 438a6a229ceSMichael Klier if(!page_exists($id) && empty($sum)) { 439a6a229ceSMichael Klier $sum = $lang['created']; 440a6a229ceSMichael Klier } 441a6a229ceSMichael Klier 442a6a229ceSMichael Klier // autoset summary on deleted pages 443a6a229ceSMichael Klier if(page_exists($id) && empty($TEXT) && empty($sum)) { 444a6a229ceSMichael Klier $sum = $lang['deleted']; 445a6a229ceSMichael Klier } 446a6a229ceSMichael Klier 447222572bfSMichael Klier lock($id); 4483a1dad2dSDennis Ploeger 449222572bfSMichael Klier saveWikiText($id,$TEXT,$sum,$minor); 4503a1dad2dSDennis Ploeger 451222572bfSMichael Klier unlock($id); 4523a1dad2dSDennis Ploeger 453593bf8f6SMichael Klier // run the indexer if page wasn't indexed yet 454593bf8f6SMichael Klier if(!@file_exists(metaFN($id, '.indexed'))) { 455593bf8f6SMichael Klier // try to aquire a lock 456593bf8f6SMichael Klier $lock = $conf['lockdir'].'/_indexer.lock'; 457593bf8f6SMichael Klier while(!@mkdir($lock,$conf['dmode'])){ 458593bf8f6SMichael Klier usleep(50); 459593bf8f6SMichael Klier if(time()-@filemtime($lock) > 60*5){ 460593bf8f6SMichael Klier // looks like a stale lock - remove it 461593bf8f6SMichael Klier @rmdir($lock); 462593bf8f6SMichael Klier }else{ 463593bf8f6SMichael Klier return false; 464593bf8f6SMichael Klier } 465593bf8f6SMichael Klier } 466593bf8f6SMichael Klier if($conf['dperm']) chmod($lock, $conf['dperm']); 467593bf8f6SMichael Klier 468593bf8f6SMichael Klier require_once(DOKU_INC.'inc/indexer.php'); 469593bf8f6SMichael Klier 470593bf8f6SMichael Klier // do the work 471593bf8f6SMichael Klier idx_addPage($id); 472593bf8f6SMichael Klier 473593bf8f6SMichael Klier // we're finished - save and free lock 474593bf8f6SMichael Klier io_saveFile(metaFN($id,'.indexed'),INDEXER_VERSION); 475593bf8f6SMichael Klier @rmdir($lock); 476593bf8f6SMichael Klier } 477593bf8f6SMichael Klier 4783a1dad2dSDennis Ploeger return 0; 479beccd742SMichael Klier } 4803a1dad2dSDennis Ploeger 481beccd742SMichael Klier /** 4822aca132fSMichael Klier * Uploads a file to the wiki. 4832aca132fSMichael Klier * 4842aca132fSMichael Klier * Michael Klier <chi@chimeric.de> 4852aca132fSMichael Klier */ 486f01ff8c1SGina Haeussge function putAttachment($id, $file, $params) { 4872aca132fSMichael Klier global $conf; 4882aca132fSMichael Klier global $lang; 4892aca132fSMichael Klier 490f01ff8c1SGina Haeussge $auth = auth_quickaclcheck(getNS($id).':*'); 4912aca132fSMichael Klier if($auth >= AUTH_UPLOAD) { 492f01ff8c1SGina Haeussge if(!isset($id)) { 4932aca132fSMichael Klier return new IXR_ERROR(1, 'Filename not given.'); 4942aca132fSMichael Klier } 4952aca132fSMichael Klier 496f01ff8c1SGina Haeussge $ftmp = $conf['tmpdir'] . '/' . $id; 4972aca132fSMichael Klier 4982aca132fSMichael Klier // save temporary file 4992aca132fSMichael Klier @unlink($ftmp); 5002aca132fSMichael Klier $buff = base64_decode($file); 5012aca132fSMichael Klier io_saveFile($ftmp, $buff); 5022aca132fSMichael Klier 5032aca132fSMichael Klier // get filename 504ecebf3a8SAndreas Gohr list($iext, $imime,$dl) = mimetype($id); 505f01ff8c1SGina Haeussge $id = cleanID($id); 5062aca132fSMichael Klier $fn = mediaFN($id); 5072aca132fSMichael Klier 5082aca132fSMichael Klier // get filetype regexp 5092aca132fSMichael Klier $types = array_keys(getMimeTypes()); 5102aca132fSMichael Klier $types = array_map(create_function('$q','return preg_quote($q,"/");'),$types); 5112aca132fSMichael Klier $regex = join('|',$types); 5122aca132fSMichael Klier 5132aca132fSMichael Klier // because a temp file was created already 5142aca132fSMichael Klier if(preg_match('/\.('.$regex.')$/i',$fn)) { 5152aca132fSMichael Klier //check for overwrite 51699c8d7f2Smichael $overwrite = @file_exists($fn); 51799c8d7f2Smichael if($overwrite && (!$params['ow'] || $auth < AUTH_DELETE)) { 518224122cfSAndreas Gohr return new IXR_ERROR(1, $lang['uploadexist'].'1'); 5192aca132fSMichael Klier } 5202aca132fSMichael Klier // check for valid content 5212aca132fSMichael Klier @require_once(DOKU_INC.'inc/media.php'); 5222aca132fSMichael Klier $ok = media_contentcheck($ftmp, $imime); 5232aca132fSMichael Klier if($ok == -1) { 524224122cfSAndreas Gohr return new IXR_ERROR(1, sprintf($lang['uploadexist'].'2', ".$iext")); 5252aca132fSMichael Klier } elseif($ok == -2) { 5262aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadspam']); 5272aca132fSMichael Klier } elseif($ok == -3) { 5282aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadxss']); 5292aca132fSMichael Klier } 5302aca132fSMichael Klier 5312aca132fSMichael Klier // prepare event data 5322aca132fSMichael Klier $data[0] = $ftmp; 5332aca132fSMichael Klier $data[1] = $fn; 5342aca132fSMichael Klier $data[2] = $id; 5352aca132fSMichael Klier $data[3] = $imime; 53699c8d7f2Smichael $data[4] = $overwrite; 5372aca132fSMichael Klier 5382aca132fSMichael Klier // trigger event 5392aca132fSMichael Klier require_once(DOKU_INC.'inc/events.php'); 5402aca132fSMichael Klier return trigger_event('MEDIA_UPLOAD_FINISH', $data, array($this, '_media_upload_action'), true); 5412aca132fSMichael Klier 5422aca132fSMichael Klier } else { 5432aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadwrong']); 5442aca132fSMichael Klier } 5452aca132fSMichael Klier } else { 5462aca132fSMichael Klier return new IXR_ERROR(1, "You don't have permissions to upload files."); 5472aca132fSMichael Klier } 5482aca132fSMichael Klier } 5492aca132fSMichael Klier 5502aca132fSMichael Klier /** 551f01ff8c1SGina Haeussge * Deletes a file from the wiki. 552f01ff8c1SGina Haeussge * 553f01ff8c1SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 554f01ff8c1SGina Haeussge */ 555f01ff8c1SGina Haeussge function deleteAttachment($id){ 556f01ff8c1SGina Haeussge $auth = auth_quickaclcheck(getNS($id).':*'); 557f01ff8c1SGina Haeussge if($auth < AUTH_DELETE) return new IXR_ERROR(1, "You don't have permissions to delete files."); 558f01ff8c1SGina Haeussge global $conf; 559f01ff8c1SGina Haeussge global $lang; 560f01ff8c1SGina Haeussge 561f01ff8c1SGina Haeussge // check for references if needed 562f01ff8c1SGina Haeussge $mediareferences = array(); 563f01ff8c1SGina Haeussge if($conf['refcheck']){ 564f01ff8c1SGina Haeussge require_once(DOKU_INC.'inc/fulltext.php'); 565f01ff8c1SGina Haeussge $mediareferences = ft_mediause($id,$conf['refshow']); 566f01ff8c1SGina Haeussge } 567f01ff8c1SGina Haeussge 568f01ff8c1SGina Haeussge if(!count($mediareferences)){ 569f01ff8c1SGina Haeussge $file = mediaFN($id); 570f01ff8c1SGina Haeussge if(@unlink($file)){ 57199c8d7f2Smichael require_once(DOKU_INC.'inc/changelog.php'); 57299c8d7f2Smichael addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_DELETE); 573f01ff8c1SGina Haeussge io_sweepNS($id,'mediadir'); 574f01ff8c1SGina Haeussge return 0; 575f01ff8c1SGina Haeussge } 576f01ff8c1SGina Haeussge //something went wrong 577f01ff8c1SGina Haeussge return new IXR_ERROR(1, 'Could not delete file'); 578f01ff8c1SGina Haeussge } else { 579f01ff8c1SGina Haeussge return new IXR_ERROR(1, 'File is still referenced'); 580f01ff8c1SGina Haeussge } 581f01ff8c1SGina Haeussge } 582f01ff8c1SGina Haeussge 583f01ff8c1SGina Haeussge /** 5842aca132fSMichael Klier * Moves the temporary file to its final destination. 5852aca132fSMichael Klier * 5862aca132fSMichael Klier * Michael Klier <chi@chimeric.de> 5872aca132fSMichael Klier */ 5882aca132fSMichael Klier function _media_upload_action($data) { 5892aca132fSMichael Klier global $conf; 5902aca132fSMichael Klier 59199c8d7f2Smichael if(is_array($data) && count($data)===5) { 5922aca132fSMichael Klier io_createNamespace($data[2], 'media'); 5932aca132fSMichael Klier if(rename($data[0], $data[1])) { 5942aca132fSMichael Klier chmod($data[1], $conf['fmode']); 5952aca132fSMichael Klier media_notify($data[2], $data[1], $data[3]); 59699c8d7f2Smichael // add a log entry to the media changelog 59799c8d7f2Smichael require_once(DOKU_INC.'inc/changelog.php'); 59899c8d7f2Smichael if ($data[4]) { 59999c8d7f2Smichael addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_EDIT); 60099c8d7f2Smichael } else { 60199c8d7f2Smichael addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_CREATE); 60299c8d7f2Smichael } 6032aca132fSMichael Klier return $data[2]; 6042aca132fSMichael Klier } else { 6052aca132fSMichael Klier return new IXR_ERROR(1, 'Upload failed.'); 6062aca132fSMichael Klier } 6072aca132fSMichael Klier } else { 6082aca132fSMichael Klier return new IXR_ERROR(1, 'Upload failed.'); 6092aca132fSMichael Klier } 6102aca132fSMichael Klier } 6112aca132fSMichael Klier 6122aca132fSMichael Klier /** 613e62b9ea5SMichael Klier * Returns the permissions of a given wiki page 614e62b9ea5SMichael Klier */ 615e62b9ea5SMichael Klier function aclCheck($id) { 616e62b9ea5SMichael Klier return auth_quickaclcheck($id); 617e62b9ea5SMichael Klier } 618e62b9ea5SMichael Klier 619e62b9ea5SMichael Klier /** 620beccd742SMichael Klier * Lists all links contained in a wiki page 62163dd0d58SMichael Klier * 62263dd0d58SMichael Klier * @author Michael Klier <chi@chimeric.de> 623beccd742SMichael Klier */ 624beccd742SMichael Klier function listLinks($id) { 625beccd742SMichael Klier if(auth_quickaclcheck($id) < AUTH_READ){ 626beccd742SMichael Klier return new IXR_Error(1, 'You are not allowed to read this page'); 627beccd742SMichael Klier } 628beccd742SMichael Klier $links = array(); 629beccd742SMichael Klier 630beccd742SMichael Klier // resolve page instructions 631beccd742SMichael Klier $ins = p_cached_instructions(wikiFN(cleanID($id))); 632beccd742SMichael Klier 633beccd742SMichael Klier // instantiate new Renderer - needed for interwiki links 634beccd742SMichael Klier include(DOKU_INC.'inc/parser/xhtml.php'); 635beccd742SMichael Klier $Renderer = new Doku_Renderer_xhtml(); 636beccd742SMichael Klier $Renderer->interwiki = getInterwiki(); 637beccd742SMichael Klier 638beccd742SMichael Klier // parse parse instructions 639beccd742SMichael Klier foreach($ins as $in) { 640beccd742SMichael Klier $link = array(); 641beccd742SMichael Klier switch($in[0]) { 642beccd742SMichael Klier case 'internallink': 643beccd742SMichael Klier $link['type'] = 'local'; 644beccd742SMichael Klier $link['page'] = $in[1][0]; 645beccd742SMichael Klier $link['href'] = wl($in[1][0]); 646beccd742SMichael Klier array_push($links,$link); 647beccd742SMichael Klier break; 648beccd742SMichael Klier case 'externallink': 649beccd742SMichael Klier $link['type'] = 'extern'; 650beccd742SMichael Klier $link['page'] = $in[1][0]; 651beccd742SMichael Klier $link['href'] = $in[1][0]; 652beccd742SMichael Klier array_push($links,$link); 653beccd742SMichael Klier break; 654beccd742SMichael Klier case 'interwikilink': 655beccd742SMichael Klier $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]); 656beccd742SMichael Klier $link['type'] = 'extern'; 657beccd742SMichael Klier $link['page'] = $url; 658beccd742SMichael Klier $link['href'] = $url; 659beccd742SMichael Klier array_push($links,$link); 660beccd742SMichael Klier break; 661beccd742SMichael Klier } 662beccd742SMichael Klier } 663beccd742SMichael Klier 66463dd0d58SMichael Klier return ($links); 66563dd0d58SMichael Klier } 66663dd0d58SMichael Klier 66763dd0d58SMichael Klier /** 66863dd0d58SMichael Klier * Returns a list of recent changes since give timestamp 66963dd0d58SMichael Klier * 67099c8d7f2Smichael * @author Michael Hamann <michael@content-space.de> 67163dd0d58SMichael Klier * @author Michael Klier <chi@chimeric.de> 67263dd0d58SMichael Klier */ 67363dd0d58SMichael Klier function getRecentChanges($timestamp) { 67463dd0d58SMichael Klier if(strlen($timestamp) != 10) 67563dd0d58SMichael Klier return new IXR_Error(20, 'The provided value is not a valid timestamp'); 67663dd0d58SMichael Klier 67763dd0d58SMichael Klier require_once(DOKU_INC.'inc/changelog.php'); 67863dd0d58SMichael Klier require_once(DOKU_INC.'inc/pageutils.php'); 67963dd0d58SMichael Klier 68099c8d7f2Smichael $recents = getRecentsSince($timestamp); 68163dd0d58SMichael Klier 68299c8d7f2Smichael $changes = array(); 68363dd0d58SMichael Klier 68499c8d7f2Smichael foreach ($recents as $recent) { 68599c8d7f2Smichael $change = array(); 68699c8d7f2Smichael $change['name'] = $recent['id']; 68799c8d7f2Smichael $change['lastModified'] = new IXR_Date($recent['date']); 68899c8d7f2Smichael $change['author'] = $recent['user']; 68999c8d7f2Smichael $change['version'] = $recent['date']; 69099c8d7f2Smichael $change['perms'] = $recent['perms']; 69199c8d7f2Smichael $change['size'] = @filesize(wikiFN($recent['id'])); 69263dd0d58SMichael Klier array_push($changes, $change); 69399c8d7f2Smichael } 69499c8d7f2Smichael 69599c8d7f2Smichael if (!empty($changes)) { 69699c8d7f2Smichael return $changes; 69763dd0d58SMichael Klier } else { 69863dd0d58SMichael Klier // in case we still have nothing at this point 69963dd0d58SMichael Klier return new IXR_Error(30, 'There are no changes in the specified timeframe'); 7003a1dad2dSDennis Ploeger } 70199c8d7f2Smichael } 70299c8d7f2Smichael 70399c8d7f2Smichael /** 70499c8d7f2Smichael * Returns a list of recent media changes since give timestamp 70599c8d7f2Smichael * 70699c8d7f2Smichael * @author Michael Hamann <michael@content-space.de> 70799c8d7f2Smichael * @author Michael Klier <chi@chimeric.de> 70899c8d7f2Smichael */ 70999c8d7f2Smichael function getRecentMediaChanges($timestamp) { 71099c8d7f2Smichael if(strlen($timestamp) != 10) 71199c8d7f2Smichael return new IXR_Error(20, 'The provided value is not a valid timestamp'); 71299c8d7f2Smichael 71399c8d7f2Smichael require_once(DOKU_INC.'inc/changelog.php'); 71499c8d7f2Smichael require_once(DOKU_INC.'inc/pageutils.php'); 71599c8d7f2Smichael 71699c8d7f2Smichael $recents = getRecentsSince($timestamp, null, '', RECENTS_MEDIA_CHANGES); 71799c8d7f2Smichael 71899c8d7f2Smichael $changes = array(); 71999c8d7f2Smichael 72099c8d7f2Smichael foreach ($recents as $recent) { 72199c8d7f2Smichael $change = array(); 72299c8d7f2Smichael $change['name'] = $recent['id']; 72399c8d7f2Smichael $change['lastModified'] = new IXR_Date($recent['date']); 72499c8d7f2Smichael $change['author'] = $recent['user']; 72599c8d7f2Smichael $change['version'] = $recent['date']; 72699c8d7f2Smichael $change['perms'] = $recent['perms']; 727a4da2756Smichael $change['size'] = @filesize(mediaFN($recent['id'])); 72899c8d7f2Smichael array_push($changes, $change); 72999c8d7f2Smichael } 73099c8d7f2Smichael 73199c8d7f2Smichael if (!empty($changes)) { 73299c8d7f2Smichael return $changes; 73399c8d7f2Smichael } else { 73499c8d7f2Smichael // in case we still have nothing at this point 73599c8d7f2Smichael return new IXR_Error(30, 'There are no changes in the specified timeframe'); 73699c8d7f2Smichael } 73799c8d7f2Smichael } 7383a1dad2dSDennis Ploeger 7393a1dad2dSDennis Ploeger /** 74073056168SMichael Klier * Returns a list of available revisions of a given wiki page 74173056168SMichael Klier * 74273056168SMichael Klier * @author Michael Klier <chi@chimeric.de> 74373056168SMichael Klier */ 74473056168SMichael Klier function pageVersions($id, $first) { 74573056168SMichael Klier global $conf; 74673056168SMichael Klier 74773056168SMichael Klier $versions = array(); 74873056168SMichael Klier 74973056168SMichael Klier if(empty($id)) 75073056168SMichael Klier return new IXR_Error(1, 'Empty page ID'); 75173056168SMichael Klier 75273056168SMichael Klier require_once(DOKU_INC.'inc/changelog.php'); 75373056168SMichael Klier 75473056168SMichael Klier $revisions = getRevisions($id, $first, $conf['recent']+1); 75573056168SMichael Klier 75673056168SMichael Klier if(count($revisions)==0 && $first!=0) { 75773056168SMichael Klier $first=0; 75873056168SMichael Klier $revisions = getRevisions($id, $first, $conf['recent']+1); 75973056168SMichael Klier } 76073056168SMichael Klier 76145c63471SMichael Klier if(count($revisions)>0 && $first==0) { 76245c63471SMichael Klier array_unshift($revisions, ''); // include current revision 76345c63471SMichael Klier array_pop($revisions); // remove extra log entry 76445c63471SMichael Klier } 76545c63471SMichael Klier 76673056168SMichael Klier $hasNext = false; 76773056168SMichael Klier if(count($revisions)>$conf['recent']) { 76873056168SMichael Klier $hasNext = true; 76973056168SMichael Klier array_pop($revisions); // remove extra log entry 77073056168SMichael Klier } 77173056168SMichael Klier 77273056168SMichael Klier if(!empty($revisions)) { 77373056168SMichael Klier foreach($revisions as $rev) { 77473056168SMichael Klier $file = wikiFN($id,$rev); 77573056168SMichael Klier $time = @filemtime($file); 77645c63471SMichael Klier // we check if the page actually exists, if this is not the 77745c63471SMichael Klier // case this can lead to less pages being returned than 77845c63471SMichael Klier // specified via $conf['recent'] 77973056168SMichael Klier if($time){ 78073056168SMichael Klier $info = getRevisionInfo($id, $time, 1024); 78173056168SMichael Klier if(!empty($info)) { 78273056168SMichael Klier $data['user'] = $info['user']; 78373056168SMichael Klier $data['ip'] = $info['ip']; 78473056168SMichael Klier $data['type'] = $info['type']; 78573056168SMichael Klier $data['sum'] = $info['sum']; 78673056168SMichael Klier $data['modified'] = new IXR_Date($info['date']); 78773056168SMichael Klier $data['version'] = $info['date']; 78873056168SMichael Klier array_push($versions, $data); 78973056168SMichael Klier } 79073056168SMichael Klier } 79173056168SMichael Klier } 79273056168SMichael Klier return $versions; 79373056168SMichael Klier } else { 79473056168SMichael Klier return array(); 79573056168SMichael Klier } 79673056168SMichael Klier } 79773056168SMichael Klier 79873056168SMichael Klier /** 799797c0d11SAndreas Gohr * The version of Wiki RPC API supported 800797c0d11SAndreas Gohr */ 801797c0d11SAndreas Gohr function wiki_RPCVersion(){ 802797c0d11SAndreas Gohr return 2; 803797c0d11SAndreas Gohr } 8041b11c097SAndreas Gohr 80528ec3c76SAndreas Gohr 80628ec3c76SAndreas Gohr /** 80728ec3c76SAndreas Gohr * Locks or unlocks a given batch of pages 80828ec3c76SAndreas Gohr * 80928ec3c76SAndreas Gohr * Give an associative array with two keys: lock and unlock. Both should contain a 81028ec3c76SAndreas Gohr * list of pages to lock or unlock 81128ec3c76SAndreas Gohr * 81228ec3c76SAndreas Gohr * Returns an associative array with the keys locked, lockfail, unlocked and 81328ec3c76SAndreas Gohr * unlockfail, each containing lists of pages. 81428ec3c76SAndreas Gohr */ 81528ec3c76SAndreas Gohr function setLocks($set){ 81628ec3c76SAndreas Gohr $locked = array(); 81728ec3c76SAndreas Gohr $lockfail = array(); 81828ec3c76SAndreas Gohr $unlocked = array(); 81928ec3c76SAndreas Gohr $unlockfail = array(); 82028ec3c76SAndreas Gohr 82128ec3c76SAndreas Gohr foreach((array) $set['lock'] as $id){ 82228ec3c76SAndreas Gohr if(checklock($id)){ 82328ec3c76SAndreas Gohr $lockfail[] = $id; 82428ec3c76SAndreas Gohr }else{ 82528ec3c76SAndreas Gohr lock($id); 82628ec3c76SAndreas Gohr $locked[] = $id; 82728ec3c76SAndreas Gohr } 82828ec3c76SAndreas Gohr } 82928ec3c76SAndreas Gohr 83028ec3c76SAndreas Gohr foreach((array) $set['unlock'] as $id){ 83128ec3c76SAndreas Gohr if(unlock($id)){ 83228ec3c76SAndreas Gohr $unlocked[] = $id; 83328ec3c76SAndreas Gohr }else{ 83428ec3c76SAndreas Gohr $unlockfail[] = $id; 83528ec3c76SAndreas Gohr } 83628ec3c76SAndreas Gohr } 83728ec3c76SAndreas Gohr 83828ec3c76SAndreas Gohr return array( 83928ec3c76SAndreas Gohr 'locked' => $locked, 84028ec3c76SAndreas Gohr 'lockfail' => $lockfail, 84128ec3c76SAndreas Gohr 'unlocked' => $unlocked, 84228ec3c76SAndreas Gohr 'unlockfail' => $unlockfail, 84328ec3c76SAndreas Gohr ); 84428ec3c76SAndreas Gohr } 84528ec3c76SAndreas Gohr 846*445e8084SAndreas Gohr function getAPIVersion(){ 847*445e8084SAndreas Gohr return DOKU_XMLRPC_API_VERSION; 848*445e8084SAndreas Gohr } 849*445e8084SAndreas Gohr 850*445e8084SAndreas Gohr function login($user,$pass){ 851*445e8084SAndreas Gohr global $conf; 852*445e8084SAndreas Gohr global $auth; 853*445e8084SAndreas Gohr if(!$conf['useacl']) return 0; 854*445e8084SAndreas Gohr if(!$auth) return 0; 855*445e8084SAndreas Gohr if($auth->canDo('external')){ 856*445e8084SAndreas Gohr return $auth->trustExternal($user,$pass,false); 857*445e8084SAndreas Gohr }else{ 858*445e8084SAndreas Gohr return auth_login($user,$pass,false,true); 859*445e8084SAndreas Gohr } 860*445e8084SAndreas Gohr } 861797c0d11SAndreas Gohr} 862797c0d11SAndreas Gohr 863797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server(); 864797c0d11SAndreas Gohr 8652aca132fSMichael Klier// vim:ts=4:sw=4:et:enc=utf-8: 866