1<?php 2if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); 3 4// fix when '<?xml' isn't on the very first line 5if(isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); 6 7/** 8 * Increased whenever the API is changed 9 */ 10define('DOKU_XMLRPC_API_VERSION',5); 11 12require_once(DOKU_INC.'inc/init.php'); 13session_write_close(); //close session 14 15if(!$conf['xmlrpc']) die('XML-RPC server not enabled.'); 16 17/** 18 * Contains needed wrapper functions and registers all available 19 * XMLRPC functions. 20 */ 21class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { 22 var $methods = array(); 23 var $public_methods = array(); 24 25 /** 26 * Checks if the current user is allowed to execute non anonymous methods 27 */ 28 function checkAuth(){ 29 global $conf; 30 global $USERINFO; 31 32 if(!$conf['useacl']) return true; //no ACL - then no checks 33 34 $allowed = explode(',',$conf['xmlrpcuser']); 35 $allowed = array_map('trim', $allowed); 36 $allowed = array_unique($allowed); 37 $allowed = array_filter($allowed); 38 39 if(!count($allowed)) return true; //no restrictions 40 41 $user = $_SERVER['REMOTE_USER']; 42 $groups = (array) $USERINFO['grps']; 43 44 if(in_array($user,$allowed)) return true; //user explicitly mentioned 45 46 //check group memberships 47 foreach($groups as $group){ 48 if(in_array('@'.$group,$allowed)) return true; 49 } 50 51 //still here? no access! 52 return false; 53 } 54 55 /** 56 * Adds a callback, extends parent method 57 * 58 * add another parameter to define if anonymous access to 59 * this method should be granted. 60 */ 61 function addCallback($method, $callback, $args, $help, $public=false){ 62 if($public) $this->public_methods[] = $method; 63 return parent::addCallback($method, $callback, $args, $help); 64 } 65 66 /** 67 * Execute a call, extends parent method 68 * 69 * Checks for authentication first 70 */ 71 function call($methodname, $args){ 72 if(!in_array($methodname,$this->public_methods) && !$this->checkAuth()){ 73 return new IXR_Error(-32603, 'server error. not authorized to call method "'.$methodname.'".'); 74 } 75 return parent::call($methodname, $args); 76 } 77 78 /** 79 * Constructor. Register methods and run Server 80 */ 81 function dokuwiki_xmlrpc_server(){ 82 $this->IXR_IntrospectionServer(); 83 84 /* DokuWiki's own methods */ 85 $this->addCallback( 86 'dokuwiki.getXMLRPCAPIVersion', 87 'this:getAPIVersion', 88 array('integer'), 89 'Returns the XMLRPC API version.', 90 true 91 ); 92 93 $this->addCallback( 94 'dokuwiki.getVersion', 95 'getVersion', 96 array('string'), 97 'Returns the running DokuWiki version.', 98 true 99 ); 100 101 $this->addCallback( 102 'dokuwiki.login', 103 'this:login', 104 array('integer','string','string'), 105 'Tries to login with the given credentials and sets auth cookies.', 106 true 107 ); 108 109 $this->addCallback( 110 'dokuwiki.getPagelist', 111 'this:readNamespace', 112 array('struct','string','struct'), 113 'List all pages within the given namespace.' 114 ); 115 116 $this->addCallback( 117 'dokuwiki.search', 118 'this:search', 119 array('struct','string'), 120 'Perform a fulltext search and return a list of matching pages' 121 ); 122 123 $this->addCallback( 124 'dokuwiki.getTime', 125 'time', 126 array('int'), 127 'Return the current time at the wiki server.' 128 ); 129 130 $this->addCallback( 131 'dokuwiki.setLocks', 132 'this:setLocks', 133 array('struct','struct'), 134 'Lock or unlock pages.' 135 ); 136 137 138 $this->addCallback( 139 'dokuwiki.getTitle', 140 'this:getTitle', 141 array('string'), 142 'Returns the wiki title.', 143 true 144 ); 145 146 $this->addCallback( 147 'dokuwiki.appendPage', 148 'this:appendPage', 149 array('int', 'string', 'string', 'struct'), 150 'Append text to a wiki page.' 151 ); 152 153 /* Wiki API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 */ 154 $this->addCallback( 155 'wiki.getRPCVersionSupported', 156 'this:wiki_RPCVersion', 157 array('int'), 158 'Returns 2 with the supported RPC API version.', 159 true 160 ); 161 $this->addCallback( 162 'wiki.getPage', 163 'this:rawPage', 164 array('string','string'), 165 'Get the raw Wiki text of page, latest version.' 166 ); 167 $this->addCallback( 168 'wiki.getPageVersion', 169 'this:rawPage', 170 array('string','string','int'), 171 'Get the raw Wiki text of page.' 172 ); 173 $this->addCallback( 174 'wiki.getPageHTML', 175 'this:htmlPage', 176 array('string','string'), 177 'Return page in rendered HTML, latest version.' 178 ); 179 $this->addCallback( 180 'wiki.getPageHTMLVersion', 181 'this:htmlPage', 182 array('string','string','int'), 183 'Return page in rendered HTML.' 184 ); 185 $this->addCallback( 186 'wiki.getAllPages', 187 'this:listPages', 188 array('struct'), 189 'Returns a list of all pages. The result is an array of utf8 pagenames.' 190 ); 191 $this->addCallback( 192 'wiki.getAttachments', 193 'this:listAttachments', 194 array('struct', 'string', 'struct'), 195 'Returns a list of all media files.' 196 ); 197 $this->addCallback( 198 'wiki.getBackLinks', 199 'this:listBackLinks', 200 array('struct','string'), 201 'Returns the pages that link to this page.' 202 ); 203 $this->addCallback( 204 'wiki.getPageInfo', 205 'this:pageInfo', 206 array('struct','string'), 207 'Returns a struct with infos about the page.' 208 ); 209 $this->addCallback( 210 'wiki.getPageInfoVersion', 211 'this:pageInfo', 212 array('struct','string','int'), 213 'Returns a struct with infos about the page.' 214 ); 215 $this->addCallback( 216 'wiki.getPageVersions', 217 'this:pageVersions', 218 array('struct','string','int'), 219 'Returns the available revisions of the page.' 220 ); 221 $this->addCallback( 222 'wiki.putPage', 223 'this:putPage', 224 array('int', 'string', 'string', 'struct'), 225 'Saves a wiki page.' 226 ); 227 $this->addCallback( 228 'wiki.listLinks', 229 'this:listLinks', 230 array('struct','string'), 231 'Lists all links contained in a wiki page.' 232 ); 233 $this->addCallback( 234 'wiki.getRecentChanges', 235 'this:getRecentChanges', 236 array('struct','int'), 237 'Returns a struct about all recent changes since given timestamp.' 238 ); 239 $this->addCallback( 240 'wiki.getRecentMediaChanges', 241 'this:getRecentMediaChanges', 242 array('struct','int'), 243 'Returns a struct about all recent media changes since given timestamp.' 244 ); 245 $this->addCallback( 246 'wiki.aclCheck', 247 'this:aclCheck', 248 array('int', 'string'), 249 'Returns the permissions of a given wiki page.' 250 ); 251 $this->addCallback( 252 'wiki.putAttachment', 253 'this:putAttachment', 254 array('struct', 'string', 'base64', 'struct'), 255 'Upload a file to the wiki.' 256 ); 257 $this->addCallback( 258 'wiki.deleteAttachment', 259 'this:deleteAttachment', 260 array('int', 'string'), 261 'Delete a file from the wiki.' 262 ); 263 $this->addCallback( 264 'wiki.getAttachment', 265 'this:getAttachment', 266 array('base64', 'string'), 267 'Download a file from the wiki.' 268 ); 269 $this->addCallback( 270 'wiki.getAttachmentInfo', 271 'this:getAttachmentInfo', 272 array('struct', 'string'), 273 'Returns a struct with infos about the attachment.' 274 ); 275 276 /** 277 * Trigger XMLRPC_CALLBACK_REGISTER, action plugins can use this event 278 * to extend the XMLRPC interface and register their own callbacks. 279 * 280 * Event data: 281 * The XMLRPC server object: 282 * 283 * $event->data->addCallback() - register a callback, the second 284 * paramter has to be of the form "plugin:<pluginname>:<plugin 285 * method>" 286 * 287 * $event->data->callbacks - an array which holds all awaylable 288 * callbacks 289 */ 290 trigger_event('XMLRPC_CALLBACK_REGISTER', $this); 291 292 $this->serve(); 293 } 294 295 /** 296 * Return a raw wiki page 297 */ 298 function rawPage($id,$rev=''){ 299 $id = cleanID($id); 300 if(auth_quickaclcheck($id) < AUTH_READ){ 301 return new IXR_Error(1, 'You are not allowed to read this page'); 302 } 303 $text = rawWiki($id,$rev); 304 if(!$text) { 305 return pageTemplate($id); 306 } else { 307 return $text; 308 } 309 } 310 311 /** 312 * Return a media file encoded in base64 313 * 314 * @author Gina Haeussge <osd@foosel.net> 315 */ 316 function getAttachment($id){ 317 $id = cleanID($id); 318 if (auth_quickaclcheck(getNS($id).':*') < AUTH_READ) 319 return new IXR_Error(1, 'You are not allowed to read this file'); 320 321 $file = mediaFN($id); 322 if (!@ file_exists($file)) 323 return new IXR_Error(1, 'The requested file does not exist'); 324 325 $data = io_readFile($file, false); 326 $base64 = base64_encode($data); 327 return $base64; 328 } 329 330 /** 331 * Return info about a media file 332 * 333 * @author Gina Haeussge <osd@foosel.net> 334 */ 335 function getAttachmentInfo($id){ 336 $id = cleanID($id); 337 $info = array( 338 'lastModified' => 0, 339 'size' => 0, 340 ); 341 342 $file = mediaFN($id); 343 if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){ 344 $info['lastModified'] = new IXR_Date(filemtime($file)); 345 $info['size'] = filesize($file); 346 } 347 348 return $info; 349 } 350 351 /** 352 * Return a wiki page rendered to html 353 */ 354 function htmlPage($id,$rev=''){ 355 $id = cleanID($id); 356 if(auth_quickaclcheck($id) < AUTH_READ){ 357 return new IXR_Error(1, 'You are not allowed to read this page'); 358 } 359 return p_wiki_xhtml($id,$rev,false); 360 } 361 362 /** 363 * List all pages - we use the indexer list here 364 */ 365 function listPages(){ 366 $list = array(); 367 $pages = array_filter(array_filter(idx_getIndex('page', ''), 368 'isVisiblePage'), 369 'page_exists'); 370 371 foreach(array_keys($pages) as $idx) { 372 $perm = auth_quickaclcheck($pages[$idx]); 373 if($perm < AUTH_READ) { 374 continue; 375 } 376 $page = array(); 377 $page['id'] = trim($pages[$idx]); 378 $page['perms'] = $perm; 379 $page['size'] = @filesize(wikiFN($pages[$idx])); 380 $page['lastModified'] = new IXR_Date(@filemtime(wikiFN($pages[$idx]))); 381 $list[] = $page; 382 } 383 384 return $list; 385 } 386 387 /** 388 * List all pages in the given namespace (and below) 389 */ 390 function readNamespace($ns,$opts){ 391 global $conf; 392 393 if(!is_array($opts)) $opts=array(); 394 395 $ns = cleanID($ns); 396 $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 397 $data = array(); 398 $opts['skipacl'] = 0; // no ACL skipping for XMLRPC 399 search($data, $conf['datadir'], 'search_allpages', $opts, $dir); 400 return $data; 401 } 402 403 /** 404 * List all pages in the given namespace (and below) 405 */ 406 function search($query){ 407 require_once(DOKU_INC.'inc/fulltext.php'); 408 409 $regex = ''; 410 $data = ft_pageSearch($query,$regex); 411 $pages = array(); 412 413 // prepare additional data 414 $idx = 0; 415 foreach($data as $id => $score){ 416 $file = wikiFN($id); 417 418 if($idx < FT_SNIPPET_NUMBER){ 419 $snippet = ft_snippet($id,$regex); 420 $idx++; 421 }else{ 422 $snippet = ''; 423 } 424 425 $pages[] = array( 426 'id' => $id, 427 'score' => $score, 428 'rev' => filemtime($file), 429 'mtime' => filemtime($file), 430 'size' => filesize($file), 431 'snippet' => $snippet, 432 ); 433 } 434 return $pages; 435 } 436 437 /** 438 * Returns the wiki title. 439 */ 440 function getTitle(){ 441 global $conf; 442 return $conf['title']; 443 } 444 445 /** 446 * List all media files. 447 * 448 * Available options are 'recursive' for also including the subnamespaces 449 * in the listing, and 'pattern' for filtering the returned files against 450 * a regular expression matching their name. 451 * 452 * @author Gina Haeussge <osd@foosel.net> 453 */ 454 function listAttachments($ns, $options = array()) { 455 global $conf; 456 global $lang; 457 458 $ns = cleanID($ns); 459 460 if (!is_array($options)) $options = array(); 461 $options['skipacl'] = 0; // no ACL skipping for XMLRPC 462 463 464 if(auth_quickaclcheck($ns.':*') >= AUTH_READ) { 465 $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 466 467 $data = array(); 468 search($data, $conf['mediadir'], 'search_media', $options, $dir); 469 $len = count($data); 470 if(!$len) return array(); 471 472 for($i=0; $i<$len; $i++) { 473 unset($data[$i]['meta']); 474 $data[$i]['lastModified'] = new IXR_Date($data[$i]['mtime']); 475 } 476 return $data; 477 } else { 478 return new IXR_Error(1, 'You are not allowed to list media files.'); 479 } 480 } 481 482 /** 483 * Return a list of backlinks 484 */ 485 function listBackLinks($id){ 486 return ft_backlinks(cleanID($id)); 487 } 488 489 /** 490 * Return some basic data about a page 491 */ 492 function pageInfo($id,$rev=''){ 493 $id = cleanID($id); 494 if(auth_quickaclcheck($id) < AUTH_READ){ 495 return new IXR_Error(1, 'You are not allowed to read this page'); 496 } 497 $file = wikiFN($id,$rev); 498 $time = @filemtime($file); 499 if(!$time){ 500 return new IXR_Error(10, 'The requested page does not exist'); 501 } 502 503 $info = getRevisionInfo($id, $time, 1024); 504 505 $data = array( 506 'name' => $id, 507 'lastModified' => new IXR_Date($time), 508 'author' => (($info['user']) ? $info['user'] : $info['ip']), 509 'version' => $time 510 ); 511 512 return ($data); 513 } 514 515 /** 516 * Save a wiki page 517 * 518 * @author Michael Klier <chi@chimeric.de> 519 */ 520 function putPage($id, $text, $params) { 521 global $TEXT; 522 global $lang; 523 global $conf; 524 525 $id = cleanID($id); 526 $TEXT = cleanText($text); 527 $sum = $params['sum']; 528 $minor = $params['minor']; 529 530 if(empty($id)) 531 return new IXR_Error(1, 'Empty page ID'); 532 533 if(!page_exists($id) && trim($TEXT) == '' ) { 534 return new IXR_ERROR(1, 'Refusing to write an empty new wiki page'); 535 } 536 537 if(auth_quickaclcheck($id) < AUTH_EDIT) 538 return new IXR_Error(1, 'You are not allowed to edit this page'); 539 540 // Check, if page is locked 541 if(checklock($id)) 542 return new IXR_Error(1, 'The page is currently locked'); 543 544 // SPAM check 545 if(checkwordblock()) 546 return new IXR_Error(1, 'Positive wordblock check'); 547 548 // autoset summary on new pages 549 if(!page_exists($id) && empty($sum)) { 550 $sum = $lang['created']; 551 } 552 553 // autoset summary on deleted pages 554 if(page_exists($id) && empty($TEXT) && empty($sum)) { 555 $sum = $lang['deleted']; 556 } 557 558 lock($id); 559 560 saveWikiText($id,$TEXT,$sum,$minor); 561 562 unlock($id); 563 564 // run the indexer if page wasn't indexed yet 565 if(!@file_exists(metaFN($id, '.indexed'))) { 566 // try to aquire a lock 567 $lock = $conf['lockdir'].'/_indexer.lock'; 568 while(!@mkdir($lock,$conf['dmode'])){ 569 usleep(50); 570 if(time()-@filemtime($lock) > 60*5){ 571 // looks like a stale lock - remove it 572 @rmdir($lock); 573 }else{ 574 return false; 575 } 576 } 577 if($conf['dperm']) chmod($lock, $conf['dperm']); 578 579 // do the work 580 idx_addPage($id); 581 582 // we're finished - save and free lock 583 io_saveFile(metaFN($id,'.indexed'),INDEXER_VERSION); 584 @rmdir($lock); 585 } 586 587 return 0; 588 } 589 590 /** 591 * Appends text to a wiki page. 592 */ 593 function appendPage($id, $text, $params) { 594 $currentpage = $this->rawPage($id); 595 if (!is_string($currentpage)) { 596 return $currentpage; 597 } 598 return $this->putPage($id, $currentpage.$text, $params); 599 } 600 601 /** 602 * Uploads a file to the wiki. 603 * 604 * Michael Klier <chi@chimeric.de> 605 */ 606 function putAttachment($id, $file, $params) { 607 $id = cleanID($id); 608 $auth = auth_quickaclcheck(getNS($id).':*'); 609 610 if(!isset($id)) { 611 return new IXR_ERROR(1, 'Filename not given.'); 612 } 613 614 global $conf; 615 616 $ftmp = $conf['tmpdir'] . '/' . md5($id.clientIP()); 617 618 // save temporary file 619 @unlink($ftmp); 620 $buff = base64_decode($file); 621 io_saveFile($ftmp, $buff); 622 623 $res = media_save(array('name' => $ftmp), $id, $params['ow'], $auth, 'rename'); 624 if (is_array($res)) { 625 return new IXR_ERROR(-$res[1], $res[0]); 626 } else { 627 return $res; 628 } 629 } 630 631 /** 632 * Deletes a file from the wiki. 633 * 634 * @author Gina Haeussge <osd@foosel.net> 635 */ 636 function deleteAttachment($id){ 637 $id = cleanID($id); 638 $auth = auth_quickaclcheck(getNS($id).':*'); 639 $res = media_delete($id, $auth); 640 if ($res & DOKU_MEDIA_DELETED) { 641 return 0; 642 } elseif ($res & DOKU_MEDIA_NOT_AUTH) { 643 return new IXR_ERROR(1, "You don't have permissions to delete files."); 644 } elseif ($res & DOKU_MEDIA_INUSE) { 645 return new IXR_ERROR(1, 'File is still referenced'); 646 } else { 647 return new IXR_ERROR(1, 'Could not delete file'); 648 } 649 } 650 651 /** 652 * Returns the permissions of a given wiki page 653 */ 654 function aclCheck($id) { 655 $id = cleanID($id); 656 return auth_quickaclcheck($id); 657 } 658 659 /** 660 * Lists all links contained in a wiki page 661 * 662 * @author Michael Klier <chi@chimeric.de> 663 */ 664 function listLinks($id) { 665 $id = cleanID($id); 666 if(auth_quickaclcheck($id) < AUTH_READ){ 667 return new IXR_Error(1, 'You are not allowed to read this page'); 668 } 669 $links = array(); 670 671 // resolve page instructions 672 $ins = p_cached_instructions(wikiFN($id)); 673 674 // instantiate new Renderer - needed for interwiki links 675 include(DOKU_INC.'inc/parser/xhtml.php'); 676 $Renderer = new Doku_Renderer_xhtml(); 677 $Renderer->interwiki = getInterwiki(); 678 679 // parse parse instructions 680 foreach($ins as $in) { 681 $link = array(); 682 switch($in[0]) { 683 case 'internallink': 684 $link['type'] = 'local'; 685 $link['page'] = $in[1][0]; 686 $link['href'] = wl($in[1][0]); 687 array_push($links,$link); 688 break; 689 case 'externallink': 690 $link['type'] = 'extern'; 691 $link['page'] = $in[1][0]; 692 $link['href'] = $in[1][0]; 693 array_push($links,$link); 694 break; 695 case 'interwikilink': 696 $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]); 697 $link['type'] = 'extern'; 698 $link['page'] = $url; 699 $link['href'] = $url; 700 array_push($links,$link); 701 break; 702 } 703 } 704 705 return ($links); 706 } 707 708 /** 709 * Returns a list of recent changes since give timestamp 710 * 711 * @author Michael Hamann <michael@content-space.de> 712 * @author Michael Klier <chi@chimeric.de> 713 */ 714 function getRecentChanges($timestamp) { 715 if(strlen($timestamp) != 10) 716 return new IXR_Error(20, 'The provided value is not a valid timestamp'); 717 718 $recents = getRecentsSince($timestamp); 719 720 $changes = array(); 721 722 foreach ($recents as $recent) { 723 $change = array(); 724 $change['name'] = $recent['id']; 725 $change['lastModified'] = new IXR_Date($recent['date']); 726 $change['author'] = $recent['user']; 727 $change['version'] = $recent['date']; 728 $change['perms'] = $recent['perms']; 729 $change['size'] = @filesize(wikiFN($recent['id'])); 730 array_push($changes, $change); 731 } 732 733 if (!empty($changes)) { 734 return $changes; 735 } else { 736 // in case we still have nothing at this point 737 return new IXR_Error(30, 'There are no changes in the specified timeframe'); 738 } 739 } 740 741 /** 742 * Returns a list of recent media changes since give timestamp 743 * 744 * @author Michael Hamann <michael@content-space.de> 745 * @author Michael Klier <chi@chimeric.de> 746 */ 747 function getRecentMediaChanges($timestamp) { 748 if(strlen($timestamp) != 10) 749 return new IXR_Error(20, 'The provided value is not a valid timestamp'); 750 751 $recents = getRecentsSince($timestamp, null, '', RECENTS_MEDIA_CHANGES); 752 753 $changes = array(); 754 755 foreach ($recents as $recent) { 756 $change = array(); 757 $change['name'] = $recent['id']; 758 $change['lastModified'] = new IXR_Date($recent['date']); 759 $change['author'] = $recent['user']; 760 $change['version'] = $recent['date']; 761 $change['perms'] = $recent['perms']; 762 $change['size'] = @filesize(mediaFN($recent['id'])); 763 array_push($changes, $change); 764 } 765 766 if (!empty($changes)) { 767 return $changes; 768 } else { 769 // in case we still have nothing at this point 770 return new IXR_Error(30, 'There are no changes in the specified timeframe'); 771 } 772 } 773 774 /** 775 * Returns a list of available revisions of a given wiki page 776 * 777 * @author Michael Klier <chi@chimeric.de> 778 */ 779 function pageVersions($id, $first) { 780 $id = cleanID($id); 781 if(auth_quickaclcheck($id) < AUTH_READ){ 782 return new IXR_Error(1, 'You are not allowed to read this page'); 783 } 784 global $conf; 785 786 $versions = array(); 787 788 if(empty($id)) 789 return new IXR_Error(1, 'Empty page ID'); 790 791 $revisions = getRevisions($id, $first, $conf['recent']+1); 792 793 if(count($revisions)==0 && $first!=0) { 794 $first=0; 795 $revisions = getRevisions($id, $first, $conf['recent']+1); 796 } 797 798 if(count($revisions)>0 && $first==0) { 799 array_unshift($revisions, ''); // include current revision 800 array_pop($revisions); // remove extra log entry 801 } 802 803 $hasNext = false; 804 if(count($revisions)>$conf['recent']) { 805 $hasNext = true; 806 array_pop($revisions); // remove extra log entry 807 } 808 809 if(!empty($revisions)) { 810 foreach($revisions as $rev) { 811 $file = wikiFN($id,$rev); 812 $time = @filemtime($file); 813 // we check if the page actually exists, if this is not the 814 // case this can lead to less pages being returned than 815 // specified via $conf['recent'] 816 if($time){ 817 $info = getRevisionInfo($id, $time, 1024); 818 if(!empty($info)) { 819 $data['user'] = $info['user']; 820 $data['ip'] = $info['ip']; 821 $data['type'] = $info['type']; 822 $data['sum'] = $info['sum']; 823 $data['modified'] = new IXR_Date($info['date']); 824 $data['version'] = $info['date']; 825 array_push($versions, $data); 826 } 827 } 828 } 829 return $versions; 830 } else { 831 return array(); 832 } 833 } 834 835 /** 836 * The version of Wiki RPC API supported 837 */ 838 function wiki_RPCVersion(){ 839 return 2; 840 } 841 842 843 /** 844 * Locks or unlocks a given batch of pages 845 * 846 * Give an associative array with two keys: lock and unlock. Both should contain a 847 * list of pages to lock or unlock 848 * 849 * Returns an associative array with the keys locked, lockfail, unlocked and 850 * unlockfail, each containing lists of pages. 851 */ 852 function setLocks($set){ 853 $locked = array(); 854 $lockfail = array(); 855 $unlocked = array(); 856 $unlockfail = array(); 857 858 foreach((array) $set['lock'] as $id){ 859 $id = cleanID($id); 860 if(auth_quickaclcheck($id) < AUTH_EDIT || checklock($id)){ 861 $lockfail[] = $id; 862 }else{ 863 lock($id); 864 $locked[] = $id; 865 } 866 } 867 868 foreach((array) $set['unlock'] as $id){ 869 $id = cleanID($id); 870 if(auth_quickaclcheck($id) < AUTH_EDIT || !unlock($id)){ 871 $unlockfail[] = $id; 872 }else{ 873 $unlocked[] = $id; 874 } 875 } 876 877 return array( 878 'locked' => $locked, 879 'lockfail' => $lockfail, 880 'unlocked' => $unlocked, 881 'unlockfail' => $unlockfail, 882 ); 883 } 884 885 function getAPIVersion(){ 886 return DOKU_XMLRPC_API_VERSION; 887 } 888 889 function login($user,$pass){ 890 global $conf; 891 global $auth; 892 if(!$conf['useacl']) return 0; 893 if(!$auth) return 0; 894 if($auth->canDo('external')){ 895 return $auth->trustExternal($user,$pass,false); 896 }else{ 897 return auth_login($user,$pass,false,true); 898 } 899 } 900 901 902} 903 904$server = new dokuwiki_xmlrpc_server(); 905 906// vim:ts=4:sw=4:et: 907