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 7445e8084SAndreas Gohr/** 8445e8084SAndreas Gohr * Increased whenever the API is changed 9445e8084SAndreas Gohr */ 10ba9418bcSHakan Sandelldefine('DOKU_XMLRPC_API_VERSION',5); 11797c0d11SAndreas Gohr 12797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php'); 13797c0d11SAndreas Gohrsession_write_close(); //close session 14593bf8f6SMichael Klier 153ee5b583SAndreas Gohrif(!$conf['xmlrpc']) die('XML-RPC server not enabled.'); 16593bf8f6SMichael Klier 17797c0d11SAndreas Gohr/** 18797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available 19797c0d11SAndreas Gohr * XMLRPC functions. 20797c0d11SAndreas Gohr */ 21797c0d11SAndreas Gohrclass dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { 22797c0d11SAndreas Gohr var $methods = array(); 233ee5b583SAndreas Gohr var $public_methods = array(); 243ee5b583SAndreas Gohr 253ee5b583SAndreas Gohr /** 263ee5b583SAndreas Gohr * Checks if the current user is allowed to execute non anonymous methods 273ee5b583SAndreas Gohr */ 283ee5b583SAndreas Gohr function checkAuth(){ 293ee5b583SAndreas Gohr global $conf; 303ee5b583SAndreas Gohr global $USERINFO; 313ee5b583SAndreas Gohr 323ee5b583SAndreas Gohr if(!$conf['useacl']) return true; //no ACL - then no checks 33992ded5aSAndreas Gohr if(trim($conf['xmlrpcuser']) == '') return true; //no restrictions 343ee5b583SAndreas Gohr 35992ded5aSAndreas Gohr return auth_isMember($conf['xmlrpcuser'],$_SERVER['REMOTE_USER'],(array) $USERINFO['grps']); 363ee5b583SAndreas Gohr } 373ee5b583SAndreas Gohr 383ee5b583SAndreas Gohr /** 393ee5b583SAndreas Gohr * Adds a callback, extends parent method 403ee5b583SAndreas Gohr * 413ee5b583SAndreas Gohr * add another parameter to define if anonymous access to 423ee5b583SAndreas Gohr * this method should be granted. 433ee5b583SAndreas Gohr */ 443ee5b583SAndreas Gohr function addCallback($method, $callback, $args, $help, $public=false){ 453ee5b583SAndreas Gohr if($public) $this->public_methods[] = $method; 463ee5b583SAndreas Gohr return parent::addCallback($method, $callback, $args, $help); 473ee5b583SAndreas Gohr } 483ee5b583SAndreas Gohr 493ee5b583SAndreas Gohr /** 503ee5b583SAndreas Gohr * Execute a call, extends parent method 513ee5b583SAndreas Gohr * 523ee5b583SAndreas Gohr * Checks for authentication first 533ee5b583SAndreas Gohr */ 543ee5b583SAndreas Gohr function call($methodname, $args){ 553ee5b583SAndreas Gohr if(!in_array($methodname,$this->public_methods) && !$this->checkAuth()){ 56*794fc9dbSMichael Hamann if (!isset($_SERVER['REMOTE_USER'])) { 57b760af94SMichael Hamann header('HTTP/1.1 401 Unauthorized'); 58*794fc9dbSMichael Hamann } else { 59*794fc9dbSMichael Hamann header('HTTP/1.1 403 Forbidden'); 60*794fc9dbSMichael Hamann } 613ee5b583SAndreas Gohr return new IXR_Error(-32603, 'server error. not authorized to call method "'.$methodname.'".'); 623ee5b583SAndreas Gohr } 633ee5b583SAndreas Gohr return parent::call($methodname, $args); 643ee5b583SAndreas Gohr } 65797c0d11SAndreas Gohr 66797c0d11SAndreas Gohr /** 67797c0d11SAndreas Gohr * Constructor. Register methods and run Server 68797c0d11SAndreas Gohr */ 69797c0d11SAndreas Gohr function dokuwiki_xmlrpc_server(){ 70797c0d11SAndreas Gohr $this->IXR_IntrospectionServer(); 71797c0d11SAndreas Gohr 72797c0d11SAndreas Gohr /* DokuWiki's own methods */ 73797c0d11SAndreas Gohr $this->addCallback( 74445e8084SAndreas Gohr 'dokuwiki.getXMLRPCAPIVersion', 75445e8084SAndreas Gohr 'this:getAPIVersion', 76445e8084SAndreas Gohr array('integer'), 773ee5b583SAndreas Gohr 'Returns the XMLRPC API version.', 783ee5b583SAndreas Gohr true 79445e8084SAndreas Gohr ); 80445e8084SAndreas Gohr 81445e8084SAndreas Gohr $this->addCallback( 82797c0d11SAndreas Gohr 'dokuwiki.getVersion', 83797c0d11SAndreas Gohr 'getVersion', 84797c0d11SAndreas Gohr array('string'), 853ee5b583SAndreas Gohr 'Returns the running DokuWiki version.', 863ee5b583SAndreas Gohr true 87797c0d11SAndreas Gohr ); 88797c0d11SAndreas Gohr 891b11c097SAndreas Gohr $this->addCallback( 90445e8084SAndreas Gohr 'dokuwiki.login', 91445e8084SAndreas Gohr 'this:login', 92445e8084SAndreas Gohr array('integer','string','string'), 933ee5b583SAndreas Gohr 'Tries to login with the given credentials and sets auth cookies.', 943ee5b583SAndreas Gohr true 95445e8084SAndreas Gohr ); 96445e8084SAndreas Gohr 97445e8084SAndreas Gohr $this->addCallback( 981b11c097SAndreas Gohr 'dokuwiki.getPagelist', 991b11c097SAndreas Gohr 'this:readNamespace', 1001b11c097SAndreas Gohr array('struct','string','struct'), 1011b11c097SAndreas Gohr 'List all pages within the given namespace.' 1021b11c097SAndreas Gohr ); 1031b11c097SAndreas Gohr 1041b11c097SAndreas Gohr $this->addCallback( 105f71f4f53SAndreas Gohr 'dokuwiki.search', 106f71f4f53SAndreas Gohr 'this:search', 107f71f4f53SAndreas Gohr array('struct','string'), 108f71f4f53SAndreas Gohr 'Perform a fulltext search and return a list of matching pages' 109f71f4f53SAndreas Gohr ); 110f71f4f53SAndreas Gohr 111f71f4f53SAndreas Gohr $this->addCallback( 1121b11c097SAndreas Gohr 'dokuwiki.getTime', 1131b11c097SAndreas Gohr 'time', 1141b11c097SAndreas Gohr array('int'), 1151b11c097SAndreas Gohr 'Return the current time at the wiki server.' 1161b11c097SAndreas Gohr ); 1171b11c097SAndreas Gohr 11828ec3c76SAndreas Gohr $this->addCallback( 11928ec3c76SAndreas Gohr 'dokuwiki.setLocks', 12028ec3c76SAndreas Gohr 'this:setLocks', 12128ec3c76SAndreas Gohr array('struct','struct'), 12228ec3c76SAndreas Gohr 'Lock or unlock pages.' 12328ec3c76SAndreas Gohr ); 12428ec3c76SAndreas Gohr 125e6f4c9d4SGeorges-Etienne Legendre 126e6f4c9d4SGeorges-Etienne Legendre $this->addCallback( 127e6f4c9d4SGeorges-Etienne Legendre 'dokuwiki.getTitle', 128e6f4c9d4SGeorges-Etienne Legendre 'this:getTitle', 129e6f4c9d4SGeorges-Etienne Legendre array('string'), 130e6f4c9d4SGeorges-Etienne Legendre 'Returns the wiki title.', 131e6f4c9d4SGeorges-Etienne Legendre true 132e6f4c9d4SGeorges-Etienne Legendre ); 133e6f4c9d4SGeorges-Etienne Legendre 134ba9418bcSHakan Sandell $this->addCallback( 135ba9418bcSHakan Sandell 'dokuwiki.appendPage', 136ba9418bcSHakan Sandell 'this:appendPage', 137ba9418bcSHakan Sandell array('int', 'string', 'string', 'struct'), 138ba9418bcSHakan Sandell 'Append text to a wiki page.' 139ba9418bcSHakan Sandell ); 140ba9418bcSHakan Sandell 141797c0d11SAndreas Gohr /* Wiki API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 */ 142797c0d11SAndreas Gohr $this->addCallback( 143797c0d11SAndreas Gohr 'wiki.getRPCVersionSupported', 144797c0d11SAndreas Gohr 'this:wiki_RPCVersion', 145797c0d11SAndreas Gohr array('int'), 1463ee5b583SAndreas Gohr 'Returns 2 with the supported RPC API version.', 1473ee5b583SAndreas Gohr true 148797c0d11SAndreas Gohr ); 149797c0d11SAndreas Gohr $this->addCallback( 150797c0d11SAndreas Gohr 'wiki.getPage', 151797c0d11SAndreas Gohr 'this:rawPage', 152797c0d11SAndreas Gohr array('string','string'), 153797c0d11SAndreas Gohr 'Get the raw Wiki text of page, latest version.' 154797c0d11SAndreas Gohr ); 155797c0d11SAndreas Gohr $this->addCallback( 156797c0d11SAndreas Gohr 'wiki.getPageVersion', 157797c0d11SAndreas Gohr 'this:rawPage', 158797c0d11SAndreas Gohr array('string','string','int'), 159797c0d11SAndreas Gohr 'Get the raw Wiki text of page.' 160797c0d11SAndreas Gohr ); 161797c0d11SAndreas Gohr $this->addCallback( 162797c0d11SAndreas Gohr 'wiki.getPageHTML', 163797c0d11SAndreas Gohr 'this:htmlPage', 164797c0d11SAndreas Gohr array('string','string'), 165797c0d11SAndreas Gohr 'Return page in rendered HTML, latest version.' 166797c0d11SAndreas Gohr ); 167797c0d11SAndreas Gohr $this->addCallback( 168797c0d11SAndreas Gohr 'wiki.getPageHTMLVersion', 169797c0d11SAndreas Gohr 'this:htmlPage', 170797c0d11SAndreas Gohr array('string','string','int'), 171797c0d11SAndreas Gohr 'Return page in rendered HTML.' 172797c0d11SAndreas Gohr ); 173797c0d11SAndreas Gohr $this->addCallback( 174797c0d11SAndreas Gohr 'wiki.getAllPages', 175797c0d11SAndreas Gohr 'this:listPages', 176797c0d11SAndreas Gohr array('struct'), 177797c0d11SAndreas Gohr 'Returns a list of all pages. The result is an array of utf8 pagenames.' 178797c0d11SAndreas Gohr ); 179797c0d11SAndreas Gohr $this->addCallback( 18026bec61eSMichael Klier 'wiki.getAttachments', 18126bec61eSMichael Klier 'this:listAttachments', 182c63d1645SGina Haeussge array('struct', 'string', 'struct'), 18326bec61eSMichael Klier 'Returns a list of all media files.' 18426bec61eSMichael Klier ); 18526bec61eSMichael Klier $this->addCallback( 186797c0d11SAndreas Gohr 'wiki.getBackLinks', 187797c0d11SAndreas Gohr 'this:listBackLinks', 188797c0d11SAndreas Gohr array('struct','string'), 189797c0d11SAndreas Gohr 'Returns the pages that link to this page.' 190797c0d11SAndreas Gohr ); 191797c0d11SAndreas Gohr $this->addCallback( 192797c0d11SAndreas Gohr 'wiki.getPageInfo', 193797c0d11SAndreas Gohr 'this:pageInfo', 194797c0d11SAndreas Gohr array('struct','string'), 195797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 196797c0d11SAndreas Gohr ); 197797c0d11SAndreas Gohr $this->addCallback( 198797c0d11SAndreas Gohr 'wiki.getPageInfoVersion', 199797c0d11SAndreas Gohr 'this:pageInfo', 200797c0d11SAndreas Gohr array('struct','string','int'), 201797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 202797c0d11SAndreas Gohr ); 2033a1dad2dSDennis Ploeger $this->addCallback( 20473056168SMichael Klier 'wiki.getPageVersions', 20573056168SMichael Klier 'this:pageVersions', 20673056168SMichael Klier array('struct','string','int'), 20773056168SMichael Klier 'Returns the available revisions of the page.' 20873056168SMichael Klier ); 20973056168SMichael Klier $this->addCallback( 2103a1dad2dSDennis Ploeger 'wiki.putPage', 2113a1dad2dSDennis Ploeger 'this:putPage', 212222572bfSMichael Klier array('int', 'string', 'string', 'struct'), 213fdd2e9d6SMichael Klier 'Saves a wiki page.' 2143a1dad2dSDennis Ploeger ); 215beccd742SMichael Klier $this->addCallback( 216beccd742SMichael Klier 'wiki.listLinks', 217beccd742SMichael Klier 'this:listLinks', 218beccd742SMichael Klier array('struct','string'), 219fdd2e9d6SMichael Klier 'Lists all links contained in a wiki page.' 220beccd742SMichael Klier ); 22163dd0d58SMichael Klier $this->addCallback( 22263dd0d58SMichael Klier 'wiki.getRecentChanges', 22363dd0d58SMichael Klier 'this:getRecentChanges', 22463dd0d58SMichael Klier array('struct','int'), 22599c8d7f2Smichael 'Returns a struct about all recent changes since given timestamp.' 22699c8d7f2Smichael ); 22799c8d7f2Smichael $this->addCallback( 22899c8d7f2Smichael 'wiki.getRecentMediaChanges', 22999c8d7f2Smichael 'this:getRecentMediaChanges', 23099c8d7f2Smichael array('struct','int'), 23199c8d7f2Smichael 'Returns a struct about all recent media changes since given timestamp.' 23263dd0d58SMichael Klier ); 233e62b9ea5SMichael Klier $this->addCallback( 234e62b9ea5SMichael Klier 'wiki.aclCheck', 235e62b9ea5SMichael Klier 'this:aclCheck', 236c63d1645SGina Haeussge array('int', 'string'), 237e62b9ea5SMichael Klier 'Returns the permissions of a given wiki page.' 238e62b9ea5SMichael Klier ); 2392aca132fSMichael Klier $this->addCallback( 2402aca132fSMichael Klier 'wiki.putAttachment', 2412aca132fSMichael Klier 'this:putAttachment', 2422aca132fSMichael Klier array('struct', 'string', 'base64', 'struct'), 2432aca132fSMichael Klier 'Upload a file to the wiki.' 2442aca132fSMichael Klier ); 245cfef3001SGina Haeussge $this->addCallback( 246f01ff8c1SGina Haeussge 'wiki.deleteAttachment', 247f01ff8c1SGina Haeussge 'this:deleteAttachment', 248f01ff8c1SGina Haeussge array('int', 'string'), 249f01ff8c1SGina Haeussge 'Delete a file from the wiki.' 250f01ff8c1SGina Haeussge ); 251f01ff8c1SGina Haeussge $this->addCallback( 252cfef3001SGina Haeussge 'wiki.getAttachment', 253cfef3001SGina Haeussge 'this:getAttachment', 254c63d1645SGina Haeussge array('base64', 'string'), 255cfef3001SGina Haeussge 'Download a file from the wiki.' 256cfef3001SGina Haeussge ); 2575672e868SGina Haeussge $this->addCallback( 2585672e868SGina Haeussge 'wiki.getAttachmentInfo', 2595672e868SGina Haeussge 'this:getAttachmentInfo', 260c63d1645SGina Haeussge array('struct', 'string'), 2615672e868SGina Haeussge 'Returns a struct with infos about the attachment.' 2625672e868SGina Haeussge ); 263797c0d11SAndreas Gohr 264bb32615dSMichael Klier /** 265bb32615dSMichael Klier * Trigger XMLRPC_CALLBACK_REGISTER, action plugins can use this event 266bb32615dSMichael Klier * to extend the XMLRPC interface and register their own callbacks. 267bb32615dSMichael Klier * 268bb32615dSMichael Klier * Event data: 269bb32615dSMichael Klier * The XMLRPC server object: 270bb32615dSMichael Klier * 271bb32615dSMichael Klier * $event->data->addCallback() - register a callback, the second 272bb32615dSMichael Klier * paramter has to be of the form "plugin:<pluginname>:<plugin 273bb32615dSMichael Klier * method>" 274bb32615dSMichael Klier * 275bb32615dSMichael Klier * $event->data->callbacks - an array which holds all awaylable 276bb32615dSMichael Klier * callbacks 277bb32615dSMichael Klier */ 278bb32615dSMichael Klier trigger_event('XMLRPC_CALLBACK_REGISTER', $this); 279bb32615dSMichael Klier 280797c0d11SAndreas Gohr $this->serve(); 281797c0d11SAndreas Gohr } 282797c0d11SAndreas Gohr 283797c0d11SAndreas Gohr /** 284797c0d11SAndreas Gohr * Return a raw wiki page 285797c0d11SAndreas Gohr */ 286797c0d11SAndreas Gohr function rawPage($id,$rev=''){ 287eff795acSMichael Hamann $id = cleanID($id); 288797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 289797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 290797c0d11SAndreas Gohr } 2912c176304SMichael Klier $text = rawWiki($id,$rev); 2922c176304SMichael Klier if(!$text) { 293fe17917eSAdrian Lang return pageTemplate($id); 2942c176304SMichael Klier } else { 2952c176304SMichael Klier return $text; 2962c176304SMichael Klier } 297797c0d11SAndreas Gohr } 298797c0d11SAndreas Gohr 299797c0d11SAndreas Gohr /** 300cfef3001SGina Haeussge * Return a media file encoded in base64 301c63d1645SGina Haeussge * 302c63d1645SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 303cfef3001SGina Haeussge */ 304cfef3001SGina Haeussge function getAttachment($id){ 305c63d1645SGina Haeussge $id = cleanID($id); 306cfef3001SGina Haeussge if (auth_quickaclcheck(getNS($id).':*') < AUTH_READ) 307cfef3001SGina Haeussge return new IXR_Error(1, 'You are not allowed to read this file'); 308cfef3001SGina Haeussge 309cfef3001SGina Haeussge $file = mediaFN($id); 310cfef3001SGina Haeussge if (!@ file_exists($file)) 311cfef3001SGina Haeussge return new IXR_Error(1, 'The requested file does not exist'); 312cfef3001SGina Haeussge 313cfef3001SGina Haeussge $data = io_readFile($file, false); 314cfef3001SGina Haeussge $base64 = base64_encode($data); 315cfef3001SGina Haeussge return $base64; 316cfef3001SGina Haeussge } 317cfef3001SGina Haeussge 318cfef3001SGina Haeussge /** 3195672e868SGina Haeussge * Return info about a media file 3205672e868SGina Haeussge * 3215672e868SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 3225672e868SGina Haeussge */ 3235672e868SGina Haeussge function getAttachmentInfo($id){ 3245672e868SGina Haeussge $id = cleanID($id); 3255672e868SGina Haeussge $info = array( 3265672e868SGina Haeussge 'lastModified' => 0, 3275672e868SGina Haeussge 'size' => 0, 3285672e868SGina Haeussge ); 3295672e868SGina Haeussge 3305672e868SGina Haeussge $file = mediaFN($id); 3315672e868SGina Haeussge if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){ 3325672e868SGina Haeussge $info['lastModified'] = new IXR_Date(filemtime($file)); 3335672e868SGina Haeussge $info['size'] = filesize($file); 3345672e868SGina Haeussge } 3355672e868SGina Haeussge 3365672e868SGina Haeussge return $info; 3375672e868SGina Haeussge } 3385672e868SGina Haeussge 3395672e868SGina Haeussge /** 340797c0d11SAndreas Gohr * Return a wiki page rendered to html 341797c0d11SAndreas Gohr */ 342797c0d11SAndreas Gohr function htmlPage($id,$rev=''){ 343eff795acSMichael Hamann $id = cleanID($id); 344797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 345797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 346797c0d11SAndreas Gohr } 347797c0d11SAndreas Gohr return p_wiki_xhtml($id,$rev,false); 348797c0d11SAndreas Gohr } 349797c0d11SAndreas Gohr 350797c0d11SAndreas Gohr /** 351797c0d11SAndreas Gohr * List all pages - we use the indexer list here 352797c0d11SAndreas Gohr */ 353797c0d11SAndreas Gohr function listPages(){ 354dfd13e55SMichael Klier $list = array(); 3559b41be24STom N Harris $pages = idx_get_indexer()->getPages(); 3569b41be24STom N Harris $pages = array_filter(array_filter($pages,'isVisiblePage'),'page_exists'); 357dfd13e55SMichael Klier 358dfd13e55SMichael Klier foreach(array_keys($pages) as $idx) { 359dfd13e55SMichael Klier $perm = auth_quickaclcheck($pages[$idx]); 360a0070b52SAdrian Lang if($perm < AUTH_READ) { 361a0070b52SAdrian Lang continue; 362a0070b52SAdrian Lang } 363dfd13e55SMichael Klier $page = array(); 364dfd13e55SMichael Klier $page['id'] = trim($pages[$idx]); 365dfd13e55SMichael Klier $page['perms'] = $perm; 366dfd13e55SMichael Klier $page['size'] = @filesize(wikiFN($pages[$idx])); 367e070c6f3SGina Haeussge $page['lastModified'] = new IXR_Date(@filemtime(wikiFN($pages[$idx]))); 368dfd13e55SMichael Klier $list[] = $page; 369dfd13e55SMichael Klier } 370dfd13e55SMichael Klier 371dfd13e55SMichael Klier return $list; 372797c0d11SAndreas Gohr } 373797c0d11SAndreas Gohr 374797c0d11SAndreas Gohr /** 3751b11c097SAndreas Gohr * List all pages in the given namespace (and below) 3761b11c097SAndreas Gohr */ 3771b11c097SAndreas Gohr function readNamespace($ns,$opts){ 3781b11c097SAndreas Gohr global $conf; 3791b11c097SAndreas Gohr 3801b11c097SAndreas Gohr if(!is_array($opts)) $opts=array(); 3811b11c097SAndreas Gohr 3821b11c097SAndreas Gohr $ns = cleanID($ns); 3831b11c097SAndreas Gohr $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 3841b11c097SAndreas Gohr $data = array(); 3856fc3aa1aSAndreas Gohr $opts['skipacl'] = 0; // no ACL skipping for XMLRPC 3861b11c097SAndreas Gohr search($data, $conf['datadir'], 'search_allpages', $opts, $dir); 3871b11c097SAndreas Gohr return $data; 3881b11c097SAndreas Gohr } 3891b11c097SAndreas Gohr 3901b11c097SAndreas Gohr /** 391f71f4f53SAndreas Gohr * List all pages in the given namespace (and below) 392f71f4f53SAndreas Gohr */ 393f71f4f53SAndreas Gohr function search($query){ 394f71f4f53SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 395f71f4f53SAndreas Gohr 396f71f4f53SAndreas Gohr $regex = ''; 397f71f4f53SAndreas Gohr $data = ft_pageSearch($query,$regex); 398f71f4f53SAndreas Gohr $pages = array(); 399f71f4f53SAndreas Gohr 400f71f4f53SAndreas Gohr // prepare additional data 401f71f4f53SAndreas Gohr $idx = 0; 402f71f4f53SAndreas Gohr foreach($data as $id => $score){ 403f71f4f53SAndreas Gohr $file = wikiFN($id); 404f71f4f53SAndreas Gohr 405f71f4f53SAndreas Gohr if($idx < FT_SNIPPET_NUMBER){ 406f71f4f53SAndreas Gohr $snippet = ft_snippet($id,$regex); 407f71f4f53SAndreas Gohr $idx++; 408f71f4f53SAndreas Gohr }else{ 409f71f4f53SAndreas Gohr $snippet = ''; 410f71f4f53SAndreas Gohr } 411f71f4f53SAndreas Gohr 412f71f4f53SAndreas Gohr $pages[] = array( 413f71f4f53SAndreas Gohr 'id' => $id, 414f71f4f53SAndreas Gohr 'score' => $score, 415f71f4f53SAndreas Gohr 'rev' => filemtime($file), 416f71f4f53SAndreas Gohr 'mtime' => filemtime($file), 417f71f4f53SAndreas Gohr 'size' => filesize($file), 418f71f4f53SAndreas Gohr 'snippet' => $snippet, 419f71f4f53SAndreas Gohr ); 420f71f4f53SAndreas Gohr } 421ac1ffddeSGeorges-Etienne Legendre return $pages; 422f71f4f53SAndreas Gohr } 423f71f4f53SAndreas Gohr 424e6f4c9d4SGeorges-Etienne Legendre /** 425e6f4c9d4SGeorges-Etienne Legendre * Returns the wiki title. 426e6f4c9d4SGeorges-Etienne Legendre */ 427e6f4c9d4SGeorges-Etienne Legendre function getTitle(){ 428e6f4c9d4SGeorges-Etienne Legendre global $conf; 429e6f4c9d4SGeorges-Etienne Legendre return $conf['title']; 430e6f4c9d4SGeorges-Etienne Legendre } 431f71f4f53SAndreas Gohr 432f71f4f53SAndreas Gohr /** 43326bec61eSMichael Klier * List all media files. 4343275953aSGina Haeussge * 4353275953aSGina Haeussge * Available options are 'recursive' for also including the subnamespaces 4363275953aSGina Haeussge * in the listing, and 'pattern' for filtering the returned files against 4373275953aSGina Haeussge * a regular expression matching their name. 4383275953aSGina Haeussge * 4393275953aSGina Haeussge * @author Gina Haeussge <osd@foosel.net> 44026bec61eSMichael Klier */ 4413275953aSGina Haeussge function listAttachments($ns, $options = array()) { 44226bec61eSMichael Klier global $conf; 44326bec61eSMichael Klier global $lang; 44426bec61eSMichael Klier 44526bec61eSMichael Klier $ns = cleanID($ns); 44626bec61eSMichael Klier 4476fc3aa1aSAndreas Gohr if (!is_array($options)) $options = array(); 4486fc3aa1aSAndreas Gohr $options['skipacl'] = 0; // no ACL skipping for XMLRPC 4493275953aSGina Haeussge 4503275953aSGina Haeussge 45126bec61eSMichael Klier if(auth_quickaclcheck($ns.':*') >= AUTH_READ) { 45226bec61eSMichael Klier $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 45326bec61eSMichael Klier 45426bec61eSMichael Klier $data = array(); 455224122cfSAndreas Gohr search($data, $conf['mediadir'], 'search_media', $options, $dir); 456224122cfSAndreas Gohr $len = count($data); 457224122cfSAndreas Gohr if(!$len) return array(); 45826bec61eSMichael Klier 459224122cfSAndreas Gohr for($i=0; $i<$len; $i++) { 460224122cfSAndreas Gohr unset($data[$i]['meta']); 461224122cfSAndreas Gohr $data[$i]['lastModified'] = new IXR_Date($data[$i]['mtime']); 46226bec61eSMichael Klier } 463224122cfSAndreas Gohr return $data; 46426bec61eSMichael Klier } else { 46526bec61eSMichael Klier return new IXR_Error(1, 'You are not allowed to list media files.'); 46626bec61eSMichael Klier } 46726bec61eSMichael Klier } 46826bec61eSMichael Klier 46926bec61eSMichael Klier /** 470797c0d11SAndreas Gohr * Return a list of backlinks 471797c0d11SAndreas Gohr */ 472beccd742SMichael Klier function listBackLinks($id){ 47386228f10SDominik Eckelmann return ft_backlinks(cleanID($id)); 474797c0d11SAndreas Gohr } 475797c0d11SAndreas Gohr 476797c0d11SAndreas Gohr /** 47763dd0d58SMichael Klier * Return some basic data about a page 478797c0d11SAndreas Gohr */ 479797c0d11SAndreas Gohr function pageInfo($id,$rev=''){ 480eff795acSMichael Hamann $id = cleanID($id); 481797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 482797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 483797c0d11SAndreas Gohr } 484797c0d11SAndreas Gohr $file = wikiFN($id,$rev); 485797c0d11SAndreas Gohr $time = @filemtime($file); 486797c0d11SAndreas Gohr if(!$time){ 487797c0d11SAndreas Gohr return new IXR_Error(10, 'The requested page does not exist'); 488797c0d11SAndreas Gohr } 489797c0d11SAndreas Gohr 490797c0d11SAndreas Gohr $info = getRevisionInfo($id, $time, 1024); 491797c0d11SAndreas Gohr 492797c0d11SAndreas Gohr $data = array( 493797c0d11SAndreas Gohr 'name' => $id, 494797c0d11SAndreas Gohr 'lastModified' => new IXR_Date($time), 495797c0d11SAndreas Gohr 'author' => (($info['user']) ? $info['user'] : $info['ip']), 496797c0d11SAndreas Gohr 'version' => $time 497797c0d11SAndreas Gohr ); 49863dd0d58SMichael Klier 49963dd0d58SMichael Klier return ($data); 500797c0d11SAndreas Gohr } 501797c0d11SAndreas Gohr 502797c0d11SAndreas Gohr /** 5033a1dad2dSDennis Ploeger * Save a wiki page 504222572bfSMichael Klier * 505222572bfSMichael Klier * @author Michael Klier <chi@chimeric.de> 5063a1dad2dSDennis Ploeger */ 507222572bfSMichael Klier function putPage($id, $text, $params) { 5083a1dad2dSDennis Ploeger global $TEXT; 509a6a229ceSMichael Klier global $lang; 510593bf8f6SMichael Klier global $conf; 5113a1dad2dSDennis Ploeger 512222572bfSMichael Klier $id = cleanID($id); 51356523eecSAndreas Gohr $TEXT = cleanText($text); 514222572bfSMichael Klier $sum = $params['sum']; 515222572bfSMichael Klier $minor = $params['minor']; 516222572bfSMichael Klier 517222572bfSMichael Klier if(empty($id)) 518fdd2e9d6SMichael Klier return new IXR_Error(1, 'Empty page ID'); 519222572bfSMichael Klier 52056523eecSAndreas Gohr if(!page_exists($id) && trim($TEXT) == '' ) { 52151597811SMichael Klier return new IXR_ERROR(1, 'Refusing to write an empty new wiki page'); 52251597811SMichael Klier } 52351597811SMichael Klier 524055b0144SChris Smith if(auth_quickaclcheck($id) < AUTH_EDIT) 525222572bfSMichael Klier return new IXR_Error(1, 'You are not allowed to edit this page'); 5263a1dad2dSDennis Ploeger 5273a1dad2dSDennis Ploeger // Check, if page is locked 528222572bfSMichael Klier if(checklock($id)) 529222572bfSMichael Klier return new IXR_Error(1, 'The page is currently locked'); 530222572bfSMichael Klier 531a6a229ceSMichael Klier // SPAM check 5323a1dad2dSDennis Ploeger if(checkwordblock()) 533222572bfSMichael Klier return new IXR_Error(1, 'Positive wordblock check'); 5343a1dad2dSDennis Ploeger 535a6a229ceSMichael Klier // autoset summary on new pages 536a6a229ceSMichael Klier if(!page_exists($id) && empty($sum)) { 537a6a229ceSMichael Klier $sum = $lang['created']; 538a6a229ceSMichael Klier } 539a6a229ceSMichael Klier 540a6a229ceSMichael Klier // autoset summary on deleted pages 541a6a229ceSMichael Klier if(page_exists($id) && empty($TEXT) && empty($sum)) { 542a6a229ceSMichael Klier $sum = $lang['deleted']; 543a6a229ceSMichael Klier } 544a6a229ceSMichael Klier 545222572bfSMichael Klier lock($id); 5463a1dad2dSDennis Ploeger 547222572bfSMichael Klier saveWikiText($id,$TEXT,$sum,$minor); 5483a1dad2dSDennis Ploeger 549222572bfSMichael Klier unlock($id); 5503a1dad2dSDennis Ploeger 551593bf8f6SMichael Klier // run the indexer if page wasn't indexed yet 552593bf8f6SMichael Klier idx_addPage($id); 553593bf8f6SMichael Klier 5543a1dad2dSDennis Ploeger return 0; 555beccd742SMichael Klier } 5563a1dad2dSDennis Ploeger 557beccd742SMichael Klier /** 558ba9418bcSHakan Sandell * Appends text to a wiki page. 559ba9418bcSHakan Sandell */ 560ba9418bcSHakan Sandell function appendPage($id, $text, $params) { 561ba9418bcSHakan Sandell $currentpage = $this->rawPage($id); 562ba9418bcSHakan Sandell if (!is_string($currentpage)) { 563ba9418bcSHakan Sandell return $currentpage; 564ba9418bcSHakan Sandell } 565ba9418bcSHakan Sandell return $this->putPage($id, $currentpage.$text, $params); 566ba9418bcSHakan Sandell } 567ba9418bcSHakan Sandell 568ba9418bcSHakan Sandell /** 5692aca132fSMichael Klier * Uploads a file to the wiki. 5702aca132fSMichael Klier * 5712aca132fSMichael Klier * Michael Klier <chi@chimeric.de> 5722aca132fSMichael Klier */ 573f01ff8c1SGina Haeussge function putAttachment($id, $file, $params) { 574eff795acSMichael Hamann $id = cleanID($id); 575f01ff8c1SGina Haeussge $auth = auth_quickaclcheck(getNS($id).':*'); 576ffb291f2SAdrian Lang 577f01ff8c1SGina Haeussge if(!isset($id)) { 5782aca132fSMichael Klier return new IXR_ERROR(1, 'Filename not given.'); 5792aca132fSMichael Klier } 5802aca132fSMichael Klier 581ffb291f2SAdrian Lang global $conf; 582ffb291f2SAdrian Lang 583c77fa67bSMichael Hamann $ftmp = $conf['tmpdir'] . '/' . md5($id.clientIP()); 5842aca132fSMichael Klier 5852aca132fSMichael Klier // save temporary file 5862aca132fSMichael Klier @unlink($ftmp); 5872aca132fSMichael Klier $buff = base64_decode($file); 5882aca132fSMichael Klier io_saveFile($ftmp, $buff); 5892aca132fSMichael Klier 590ffb291f2SAdrian Lang $res = media_save(array('name' => $ftmp), $id, $params['ow'], $auth, 'rename'); 591ffb291f2SAdrian Lang if (is_array($res)) { 592ffb291f2SAdrian Lang return new IXR_ERROR(-$res[1], $res[0]); 5932aca132fSMichael Klier } else { 594ffb291f2SAdrian Lang return $res; 5952aca132fSMichael Klier } 5962aca132fSMichael Klier } 5972aca132fSMichael Klier 5982aca132fSMichael Klier /** 599f01ff8c1SGina Haeussge * Deletes a file from the wiki. 600f01ff8c1SGina Haeussge * 601f01ff8c1SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 602f01ff8c1SGina Haeussge */ 603f01ff8c1SGina Haeussge function deleteAttachment($id){ 604eff795acSMichael Hamann $id = cleanID($id); 605f01ff8c1SGina Haeussge $auth = auth_quickaclcheck(getNS($id).':*'); 60687229c84SAdrian Lang $res = media_delete($id, $auth); 60787229c84SAdrian Lang if ($res & DOKU_MEDIA_DELETED) { 608f01ff8c1SGina Haeussge return 0; 60987229c84SAdrian Lang } elseif ($res & DOKU_MEDIA_NOT_AUTH) { 61087229c84SAdrian Lang return new IXR_ERROR(1, "You don't have permissions to delete files."); 61187229c84SAdrian Lang } elseif ($res & DOKU_MEDIA_INUSE) { 612f01ff8c1SGina Haeussge return new IXR_ERROR(1, 'File is still referenced'); 61399c8d7f2Smichael } else { 61487229c84SAdrian Lang return new IXR_ERROR(1, 'Could not delete file'); 6152aca132fSMichael Klier } 6162aca132fSMichael Klier } 6172aca132fSMichael Klier 6182aca132fSMichael Klier /** 619e62b9ea5SMichael Klier * Returns the permissions of a given wiki page 620e62b9ea5SMichael Klier */ 621e62b9ea5SMichael Klier function aclCheck($id) { 622eff795acSMichael Hamann $id = cleanID($id); 623e62b9ea5SMichael Klier return auth_quickaclcheck($id); 624e62b9ea5SMichael Klier } 625e62b9ea5SMichael Klier 626e62b9ea5SMichael Klier /** 627beccd742SMichael Klier * Lists all links contained in a wiki page 62863dd0d58SMichael Klier * 62963dd0d58SMichael Klier * @author Michael Klier <chi@chimeric.de> 630beccd742SMichael Klier */ 631beccd742SMichael Klier function listLinks($id) { 632eff795acSMichael Hamann $id = cleanID($id); 633beccd742SMichael Klier if(auth_quickaclcheck($id) < AUTH_READ){ 634beccd742SMichael Klier return new IXR_Error(1, 'You are not allowed to read this page'); 635beccd742SMichael Klier } 636beccd742SMichael Klier $links = array(); 637beccd742SMichael Klier 638beccd742SMichael Klier // resolve page instructions 639eff795acSMichael Hamann $ins = p_cached_instructions(wikiFN($id)); 640beccd742SMichael Klier 641beccd742SMichael Klier // instantiate new Renderer - needed for interwiki links 642beccd742SMichael Klier include(DOKU_INC.'inc/parser/xhtml.php'); 643beccd742SMichael Klier $Renderer = new Doku_Renderer_xhtml(); 644beccd742SMichael Klier $Renderer->interwiki = getInterwiki(); 645beccd742SMichael Klier 646beccd742SMichael Klier // parse parse instructions 647beccd742SMichael Klier foreach($ins as $in) { 648beccd742SMichael Klier $link = array(); 649beccd742SMichael Klier switch($in[0]) { 650beccd742SMichael Klier case 'internallink': 651beccd742SMichael Klier $link['type'] = 'local'; 652beccd742SMichael Klier $link['page'] = $in[1][0]; 653beccd742SMichael Klier $link['href'] = wl($in[1][0]); 654beccd742SMichael Klier array_push($links,$link); 655beccd742SMichael Klier break; 656beccd742SMichael Klier case 'externallink': 657beccd742SMichael Klier $link['type'] = 'extern'; 658beccd742SMichael Klier $link['page'] = $in[1][0]; 659beccd742SMichael Klier $link['href'] = $in[1][0]; 660beccd742SMichael Klier array_push($links,$link); 661beccd742SMichael Klier break; 662beccd742SMichael Klier case 'interwikilink': 663beccd742SMichael Klier $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]); 664beccd742SMichael Klier $link['type'] = 'extern'; 665beccd742SMichael Klier $link['page'] = $url; 666beccd742SMichael Klier $link['href'] = $url; 667beccd742SMichael Klier array_push($links,$link); 668beccd742SMichael Klier break; 669beccd742SMichael Klier } 670beccd742SMichael Klier } 671beccd742SMichael Klier 67263dd0d58SMichael Klier return ($links); 67363dd0d58SMichael Klier } 67463dd0d58SMichael Klier 67563dd0d58SMichael Klier /** 67663dd0d58SMichael Klier * Returns a list of recent changes since give timestamp 67763dd0d58SMichael Klier * 67899c8d7f2Smichael * @author Michael Hamann <michael@content-space.de> 67963dd0d58SMichael Klier * @author Michael Klier <chi@chimeric.de> 68063dd0d58SMichael Klier */ 68163dd0d58SMichael Klier function getRecentChanges($timestamp) { 68263dd0d58SMichael Klier if(strlen($timestamp) != 10) 68363dd0d58SMichael Klier return new IXR_Error(20, 'The provided value is not a valid timestamp'); 68463dd0d58SMichael Klier 68599c8d7f2Smichael $recents = getRecentsSince($timestamp); 68663dd0d58SMichael Klier 68799c8d7f2Smichael $changes = array(); 68863dd0d58SMichael Klier 68999c8d7f2Smichael foreach ($recents as $recent) { 69099c8d7f2Smichael $change = array(); 69199c8d7f2Smichael $change['name'] = $recent['id']; 69299c8d7f2Smichael $change['lastModified'] = new IXR_Date($recent['date']); 69399c8d7f2Smichael $change['author'] = $recent['user']; 69499c8d7f2Smichael $change['version'] = $recent['date']; 69599c8d7f2Smichael $change['perms'] = $recent['perms']; 69699c8d7f2Smichael $change['size'] = @filesize(wikiFN($recent['id'])); 69763dd0d58SMichael Klier array_push($changes, $change); 69899c8d7f2Smichael } 69999c8d7f2Smichael 70099c8d7f2Smichael if (!empty($changes)) { 70199c8d7f2Smichael return $changes; 70263dd0d58SMichael Klier } else { 70363dd0d58SMichael Klier // in case we still have nothing at this point 70463dd0d58SMichael Klier return new IXR_Error(30, 'There are no changes in the specified timeframe'); 7053a1dad2dSDennis Ploeger } 70699c8d7f2Smichael } 70799c8d7f2Smichael 70899c8d7f2Smichael /** 70999c8d7f2Smichael * Returns a list of recent media changes since give timestamp 71099c8d7f2Smichael * 71199c8d7f2Smichael * @author Michael Hamann <michael@content-space.de> 71299c8d7f2Smichael * @author Michael Klier <chi@chimeric.de> 71399c8d7f2Smichael */ 71499c8d7f2Smichael function getRecentMediaChanges($timestamp) { 71599c8d7f2Smichael if(strlen($timestamp) != 10) 71699c8d7f2Smichael return new IXR_Error(20, 'The provided value is not a valid timestamp'); 71799c8d7f2Smichael 71899c8d7f2Smichael $recents = getRecentsSince($timestamp, null, '', RECENTS_MEDIA_CHANGES); 71999c8d7f2Smichael 72099c8d7f2Smichael $changes = array(); 72199c8d7f2Smichael 72299c8d7f2Smichael foreach ($recents as $recent) { 72399c8d7f2Smichael $change = array(); 72499c8d7f2Smichael $change['name'] = $recent['id']; 72599c8d7f2Smichael $change['lastModified'] = new IXR_Date($recent['date']); 72699c8d7f2Smichael $change['author'] = $recent['user']; 72799c8d7f2Smichael $change['version'] = $recent['date']; 72899c8d7f2Smichael $change['perms'] = $recent['perms']; 729a4da2756Smichael $change['size'] = @filesize(mediaFN($recent['id'])); 73099c8d7f2Smichael array_push($changes, $change); 73199c8d7f2Smichael } 73299c8d7f2Smichael 73399c8d7f2Smichael if (!empty($changes)) { 73499c8d7f2Smichael return $changes; 73599c8d7f2Smichael } else { 73699c8d7f2Smichael // in case we still have nothing at this point 73799c8d7f2Smichael return new IXR_Error(30, 'There are no changes in the specified timeframe'); 73899c8d7f2Smichael } 73999c8d7f2Smichael } 7403a1dad2dSDennis Ploeger 7413a1dad2dSDennis Ploeger /** 74273056168SMichael Klier * Returns a list of available revisions of a given wiki page 74373056168SMichael Klier * 74473056168SMichael Klier * @author Michael Klier <chi@chimeric.de> 74573056168SMichael Klier */ 74673056168SMichael Klier function pageVersions($id, $first) { 747eff795acSMichael Hamann $id = cleanID($id); 748eff795acSMichael Hamann if(auth_quickaclcheck($id) < AUTH_READ){ 749eff795acSMichael Hamann return new IXR_Error(1, 'You are not allowed to read this page'); 750eff795acSMichael Hamann } 75173056168SMichael Klier global $conf; 75273056168SMichael Klier 75373056168SMichael Klier $versions = array(); 75473056168SMichael Klier 75573056168SMichael Klier if(empty($id)) 75673056168SMichael Klier return new IXR_Error(1, 'Empty page ID'); 75773056168SMichael Klier 75873056168SMichael Klier $revisions = getRevisions($id, $first, $conf['recent']+1); 75973056168SMichael Klier 76073056168SMichael Klier if(count($revisions)==0 && $first!=0) { 76173056168SMichael Klier $first=0; 76273056168SMichael Klier $revisions = getRevisions($id, $first, $conf['recent']+1); 76373056168SMichael Klier } 76473056168SMichael Klier 76545c63471SMichael Klier if(count($revisions)>0 && $first==0) { 76645c63471SMichael Klier array_unshift($revisions, ''); // include current revision 76745c63471SMichael Klier array_pop($revisions); // remove extra log entry 76845c63471SMichael Klier } 76945c63471SMichael Klier 77073056168SMichael Klier $hasNext = false; 77173056168SMichael Klier if(count($revisions)>$conf['recent']) { 77273056168SMichael Klier $hasNext = true; 77373056168SMichael Klier array_pop($revisions); // remove extra log entry 77473056168SMichael Klier } 77573056168SMichael Klier 77673056168SMichael Klier if(!empty($revisions)) { 77773056168SMichael Klier foreach($revisions as $rev) { 77873056168SMichael Klier $file = wikiFN($id,$rev); 77973056168SMichael Klier $time = @filemtime($file); 78045c63471SMichael Klier // we check if the page actually exists, if this is not the 78145c63471SMichael Klier // case this can lead to less pages being returned than 78245c63471SMichael Klier // specified via $conf['recent'] 78373056168SMichael Klier if($time){ 78473056168SMichael Klier $info = getRevisionInfo($id, $time, 1024); 78573056168SMichael Klier if(!empty($info)) { 78673056168SMichael Klier $data['user'] = $info['user']; 78773056168SMichael Klier $data['ip'] = $info['ip']; 78873056168SMichael Klier $data['type'] = $info['type']; 78973056168SMichael Klier $data['sum'] = $info['sum']; 79073056168SMichael Klier $data['modified'] = new IXR_Date($info['date']); 79173056168SMichael Klier $data['version'] = $info['date']; 79273056168SMichael Klier array_push($versions, $data); 79373056168SMichael Klier } 79473056168SMichael Klier } 79573056168SMichael Klier } 79673056168SMichael Klier return $versions; 79773056168SMichael Klier } else { 79873056168SMichael Klier return array(); 79973056168SMichael Klier } 80073056168SMichael Klier } 80173056168SMichael Klier 80273056168SMichael Klier /** 803797c0d11SAndreas Gohr * The version of Wiki RPC API supported 804797c0d11SAndreas Gohr */ 805797c0d11SAndreas Gohr function wiki_RPCVersion(){ 806797c0d11SAndreas Gohr return 2; 807797c0d11SAndreas Gohr } 8081b11c097SAndreas Gohr 80928ec3c76SAndreas Gohr 81028ec3c76SAndreas Gohr /** 81128ec3c76SAndreas Gohr * Locks or unlocks a given batch of pages 81228ec3c76SAndreas Gohr * 81328ec3c76SAndreas Gohr * Give an associative array with two keys: lock and unlock. Both should contain a 81428ec3c76SAndreas Gohr * list of pages to lock or unlock 81528ec3c76SAndreas Gohr * 81628ec3c76SAndreas Gohr * Returns an associative array with the keys locked, lockfail, unlocked and 81728ec3c76SAndreas Gohr * unlockfail, each containing lists of pages. 81828ec3c76SAndreas Gohr */ 81928ec3c76SAndreas Gohr function setLocks($set){ 82028ec3c76SAndreas Gohr $locked = array(); 82128ec3c76SAndreas Gohr $lockfail = array(); 82228ec3c76SAndreas Gohr $unlocked = array(); 82328ec3c76SAndreas Gohr $unlockfail = array(); 82428ec3c76SAndreas Gohr 82528ec3c76SAndreas Gohr foreach((array) $set['lock'] as $id){ 826eff795acSMichael Hamann $id = cleanID($id); 827eff795acSMichael Hamann if(auth_quickaclcheck($id) < AUTH_EDIT || checklock($id)){ 82828ec3c76SAndreas Gohr $lockfail[] = $id; 82928ec3c76SAndreas Gohr }else{ 83028ec3c76SAndreas Gohr lock($id); 83128ec3c76SAndreas Gohr $locked[] = $id; 83228ec3c76SAndreas Gohr } 83328ec3c76SAndreas Gohr } 83428ec3c76SAndreas Gohr 83528ec3c76SAndreas Gohr foreach((array) $set['unlock'] as $id){ 836eff795acSMichael Hamann $id = cleanID($id); 837eff795acSMichael Hamann if(auth_quickaclcheck($id) < AUTH_EDIT || !unlock($id)){ 83828ec3c76SAndreas Gohr $unlockfail[] = $id; 839eff795acSMichael Hamann }else{ 840eff795acSMichael Hamann $unlocked[] = $id; 84128ec3c76SAndreas Gohr } 84228ec3c76SAndreas Gohr } 84328ec3c76SAndreas Gohr 84428ec3c76SAndreas Gohr return array( 84528ec3c76SAndreas Gohr 'locked' => $locked, 84628ec3c76SAndreas Gohr 'lockfail' => $lockfail, 84728ec3c76SAndreas Gohr 'unlocked' => $unlocked, 84828ec3c76SAndreas Gohr 'unlockfail' => $unlockfail, 84928ec3c76SAndreas Gohr ); 85028ec3c76SAndreas Gohr } 85128ec3c76SAndreas Gohr 852445e8084SAndreas Gohr function getAPIVersion(){ 853445e8084SAndreas Gohr return DOKU_XMLRPC_API_VERSION; 854445e8084SAndreas Gohr } 855445e8084SAndreas Gohr 856445e8084SAndreas Gohr function login($user,$pass){ 857445e8084SAndreas Gohr global $conf; 858445e8084SAndreas Gohr global $auth; 859445e8084SAndreas Gohr if(!$conf['useacl']) return 0; 860445e8084SAndreas Gohr if(!$auth) return 0; 861445e8084SAndreas Gohr if($auth->canDo('external')){ 862445e8084SAndreas Gohr return $auth->trustExternal($user,$pass,false); 863445e8084SAndreas Gohr }else{ 864445e8084SAndreas Gohr return auth_login($user,$pass,false,true); 865445e8084SAndreas Gohr } 866445e8084SAndreas Gohr } 8673ee5b583SAndreas Gohr 8683ee5b583SAndreas Gohr 869797c0d11SAndreas Gohr} 870797c0d11SAndreas Gohr 871797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server(); 872797c0d11SAndreas Gohr 873e3776c06SMichael Hamann// vim:ts=4:sw=4:et: 874