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