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