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 global $conf; 358 359 $list = array(); 360 $pages = file($conf['indexdir'] . '/page.idx'); 361 $pages = array_filter($pages, 'isVisiblePage'); 362 363 foreach(array_keys($pages) as $idx) { 364 if(page_exists($pages[$idx])) { 365 $perm = auth_quickaclcheck($pages[$idx]); 366 if($perm >= AUTH_READ) { 367 $page = array(); 368 $page['id'] = trim($pages[$idx]); 369 $page['perms'] = $perm; 370 $page['size'] = @filesize(wikiFN($pages[$idx])); 371 $page['lastModified'] = new IXR_Date(@filemtime(wikiFN($pages[$idx]))); 372 $list[] = $page; 373 } 374 } 375 } 376 377 return $list; 378 } 379 380 /** 381 * List all pages in the given namespace (and below) 382 */ 383 function readNamespace($ns,$opts){ 384 global $conf; 385 386 if(!is_array($opts)) $opts=array(); 387 388 $ns = cleanID($ns); 389 $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 390 $data = array(); 391 $opts['skipacl'] = 0; // no ACL skipping for XMLRPC 392 search($data, $conf['datadir'], 'search_allpages', $opts, $dir); 393 return $data; 394 } 395 396 /** 397 * List all pages in the given namespace (and below) 398 */ 399 function search($query){ 400 require_once(DOKU_INC.'inc/fulltext.php'); 401 402 $regex = ''; 403 $data = ft_pageSearch($query,$regex); 404 $pages = array(); 405 406 // prepare additional data 407 $idx = 0; 408 foreach($data as $id => $score){ 409 $file = wikiFN($id); 410 411 if($idx < FT_SNIPPET_NUMBER){ 412 $snippet = ft_snippet($id,$regex); 413 $idx++; 414 }else{ 415 $snippet = ''; 416 } 417 418 $pages[] = array( 419 'id' => $id, 420 'score' => $score, 421 'rev' => filemtime($file), 422 'mtime' => filemtime($file), 423 'size' => filesize($file), 424 'snippet' => $snippet, 425 ); 426 } 427 return $pages; 428 } 429 430 /** 431 * Returns the wiki title. 432 */ 433 function getTitle(){ 434 global $conf; 435 return $conf['title']; 436 } 437 438 /** 439 * List all media files. 440 * 441 * Available options are 'recursive' for also including the subnamespaces 442 * in the listing, and 'pattern' for filtering the returned files against 443 * a regular expression matching their name. 444 * 445 * @author Gina Haeussge <osd@foosel.net> 446 */ 447 function listAttachments($ns, $options = array()) { 448 global $conf; 449 global $lang; 450 451 $ns = cleanID($ns); 452 453 if (!is_array($options)) $options = array(); 454 $options['skipacl'] = 0; // no ACL skipping for XMLRPC 455 456 457 if(auth_quickaclcheck($ns.':*') >= AUTH_READ) { 458 $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 459 460 $data = array(); 461 search($data, $conf['mediadir'], 'search_media', $options, $dir); 462 $len = count($data); 463 if(!$len) return array(); 464 465 for($i=0; $i<$len; $i++) { 466 unset($data[$i]['meta']); 467 $data[$i]['lastModified'] = new IXR_Date($data[$i]['mtime']); 468 } 469 return $data; 470 } else { 471 return new IXR_Error(1, 'You are not allowed to list media files.'); 472 } 473 } 474 475 /** 476 * Return a list of backlinks 477 */ 478 function listBackLinks($id){ 479 return ft_backlinks($id); 480 } 481 482 /** 483 * Return some basic data about a page 484 */ 485 function pageInfo($id,$rev=''){ 486 if(auth_quickaclcheck($id) < AUTH_READ){ 487 return new IXR_Error(1, 'You are not allowed to read this page'); 488 } 489 $file = wikiFN($id,$rev); 490 $time = @filemtime($file); 491 if(!$time){ 492 return new IXR_Error(10, 'The requested page does not exist'); 493 } 494 495 $info = getRevisionInfo($id, $time, 1024); 496 497 $data = array( 498 'name' => $id, 499 'lastModified' => new IXR_Date($time), 500 'author' => (($info['user']) ? $info['user'] : $info['ip']), 501 'version' => $time 502 ); 503 504 return ($data); 505 } 506 507 /** 508 * Save a wiki page 509 * 510 * @author Michael Klier <chi@chimeric.de> 511 */ 512 function putPage($id, $text, $params) { 513 global $TEXT; 514 global $lang; 515 global $conf; 516 517 $id = cleanID($id); 518 $TEXT = cleanText($text); 519 $sum = $params['sum']; 520 $minor = $params['minor']; 521 522 if(empty($id)) 523 return new IXR_Error(1, 'Empty page ID'); 524 525 if(!page_exists($id) && trim($TEXT) == '' ) { 526 return new IXR_ERROR(1, 'Refusing to write an empty new wiki page'); 527 } 528 529 if(auth_quickaclcheck($id) < AUTH_EDIT) 530 return new IXR_Error(1, 'You are not allowed to edit this page'); 531 532 // Check, if page is locked 533 if(checklock($id)) 534 return new IXR_Error(1, 'The page is currently locked'); 535 536 // SPAM check 537 if(checkwordblock()) 538 return new IXR_Error(1, 'Positive wordblock check'); 539 540 // autoset summary on new pages 541 if(!page_exists($id) && empty($sum)) { 542 $sum = $lang['created']; 543 } 544 545 // autoset summary on deleted pages 546 if(page_exists($id) && empty($TEXT) && empty($sum)) { 547 $sum = $lang['deleted']; 548 } 549 550 lock($id); 551 552 saveWikiText($id,$TEXT,$sum,$minor); 553 554 unlock($id); 555 556 // run the indexer if page wasn't indexed yet 557 if(!@file_exists(metaFN($id, '.indexed'))) { 558 // try to aquire a lock 559 $lock = $conf['lockdir'].'/_indexer.lock'; 560 while(!@mkdir($lock,$conf['dmode'])){ 561 usleep(50); 562 if(time()-@filemtime($lock) > 60*5){ 563 // looks like a stale lock - remove it 564 @rmdir($lock); 565 }else{ 566 return false; 567 } 568 } 569 if($conf['dperm']) chmod($lock, $conf['dperm']); 570 571 // do the work 572 idx_addPage($id); 573 574 // we're finished - save and free lock 575 io_saveFile(metaFN($id,'.indexed'),INDEXER_VERSION); 576 @rmdir($lock); 577 } 578 579 return 0; 580 } 581 582 /** 583 * Uploads a file to the wiki. 584 * 585 * Michael Klier <chi@chimeric.de> 586 */ 587 function putAttachment($id, $file, $params) { 588 global $conf; 589 global $lang; 590 591 $auth = auth_quickaclcheck(getNS($id).':*'); 592 if($auth >= AUTH_UPLOAD) { 593 if(!isset($id)) { 594 return new IXR_ERROR(1, 'Filename not given.'); 595 } 596 597 $ftmp = $conf['tmpdir'] . '/' . md5($id.clientIP()); 598 599 // save temporary file 600 @unlink($ftmp); 601 $buff = base64_decode($file); 602 io_saveFile($ftmp, $buff); 603 604 // get filename 605 list($iext, $imime,$dl) = mimetype($id); 606 $id = cleanID($id); 607 $fn = mediaFN($id); 608 609 // get filetype regexp 610 $types = array_keys(getMimeTypes()); 611 $types = array_map(create_function('$q','return preg_quote($q,"/");'),$types); 612 $regex = join('|',$types); 613 614 // because a temp file was created already 615 if(preg_match('/\.('.$regex.')$/i',$fn)) { 616 //check for overwrite 617 $overwrite = @file_exists($fn); 618 if($overwrite && (!$params['ow'] || $auth < AUTH_DELETE)) { 619 return new IXR_ERROR(1, $lang['uploadexist'].'1'); 620 } 621 // check for valid content 622 $ok = media_contentcheck($ftmp, $imime); 623 if($ok == -1) { 624 return new IXR_ERROR(1, sprintf($lang['uploadexist'].'2', ".$iext")); 625 } elseif($ok == -2) { 626 return new IXR_ERROR(1, $lang['uploadspam']); 627 } elseif($ok == -3) { 628 return new IXR_ERROR(1, $lang['uploadxss']); 629 } 630 631 // prepare event data 632 $data[0] = $ftmp; 633 $data[1] = $fn; 634 $data[2] = $id; 635 $data[3] = $imime; 636 $data[4] = $overwrite; 637 638 // trigger event 639 return trigger_event('MEDIA_UPLOAD_FINISH', $data, array($this, '_media_upload_action'), true); 640 641 } else { 642 return new IXR_ERROR(1, $lang['uploadwrong']); 643 } 644 } else { 645 return new IXR_ERROR(1, "You don't have permissions to upload files."); 646 } 647 } 648 649 /** 650 * Deletes a file from the wiki. 651 * 652 * @author Gina Haeussge <osd@foosel.net> 653 */ 654 function deleteAttachment($id){ 655 $auth = auth_quickaclcheck(getNS($id).':*'); 656 if($auth < AUTH_DELETE) return new IXR_ERROR(1, "You don't have permissions to delete files."); 657 global $conf; 658 global $lang; 659 660 // check for references if needed 661 $mediareferences = array(); 662 if($conf['refcheck']){ 663 $mediareferences = ft_mediause($id,$conf['refshow']); 664 } 665 666 if(!count($mediareferences)){ 667 $file = mediaFN($id); 668 if(@unlink($file)){ 669 addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_DELETE); 670 io_sweepNS($id,'mediadir'); 671 return 0; 672 } 673 //something went wrong 674 return new IXR_ERROR(1, 'Could not delete file'); 675 } else { 676 return new IXR_ERROR(1, 'File is still referenced'); 677 } 678 } 679 680 /** 681 * Moves the temporary file to its final destination. 682 * 683 * Michael Klier <chi@chimeric.de> 684 */ 685 function _media_upload_action($data) { 686 global $conf; 687 688 if(is_array($data) && count($data)===5) { 689 io_createNamespace($data[2], 'media'); 690 if(rename($data[0], $data[1])) { 691 chmod($data[1], $conf['fmode']); 692 media_notify($data[2], $data[1], $data[3]); 693 // add a log entry to the media changelog 694 if ($data[4]) { 695 addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_EDIT); 696 } else { 697 addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_CREATE); 698 } 699 return $data[2]; 700 } else { 701 return new IXR_ERROR(1, 'Upload failed.'); 702 } 703 } else { 704 return new IXR_ERROR(1, 'Upload failed.'); 705 } 706 } 707 708 /** 709 * Returns the permissions of a given wiki page 710 */ 711 function aclCheck($id) { 712 return auth_quickaclcheck($id); 713 } 714 715 /** 716 * Lists all links contained in a wiki page 717 * 718 * @author Michael Klier <chi@chimeric.de> 719 */ 720 function listLinks($id) { 721 if(auth_quickaclcheck($id) < AUTH_READ){ 722 return new IXR_Error(1, 'You are not allowed to read this page'); 723 } 724 $links = array(); 725 726 // resolve page instructions 727 $ins = p_cached_instructions(wikiFN(cleanID($id))); 728 729 // instantiate new Renderer - needed for interwiki links 730 include(DOKU_INC.'inc/parser/xhtml.php'); 731 $Renderer = new Doku_Renderer_xhtml(); 732 $Renderer->interwiki = getInterwiki(); 733 734 // parse parse instructions 735 foreach($ins as $in) { 736 $link = array(); 737 switch($in[0]) { 738 case 'internallink': 739 $link['type'] = 'local'; 740 $link['page'] = $in[1][0]; 741 $link['href'] = wl($in[1][0]); 742 array_push($links,$link); 743 break; 744 case 'externallink': 745 $link['type'] = 'extern'; 746 $link['page'] = $in[1][0]; 747 $link['href'] = $in[1][0]; 748 array_push($links,$link); 749 break; 750 case 'interwikilink': 751 $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]); 752 $link['type'] = 'extern'; 753 $link['page'] = $url; 754 $link['href'] = $url; 755 array_push($links,$link); 756 break; 757 } 758 } 759 760 return ($links); 761 } 762 763 /** 764 * Returns a list of recent changes since give timestamp 765 * 766 * @author Michael Hamann <michael@content-space.de> 767 * @author Michael Klier <chi@chimeric.de> 768 */ 769 function getRecentChanges($timestamp) { 770 if(strlen($timestamp) != 10) 771 return new IXR_Error(20, 'The provided value is not a valid timestamp'); 772 773 $recents = getRecentsSince($timestamp); 774 775 $changes = array(); 776 777 foreach ($recents as $recent) { 778 $change = array(); 779 $change['name'] = $recent['id']; 780 $change['lastModified'] = new IXR_Date($recent['date']); 781 $change['author'] = $recent['user']; 782 $change['version'] = $recent['date']; 783 $change['perms'] = $recent['perms']; 784 $change['size'] = @filesize(wikiFN($recent['id'])); 785 array_push($changes, $change); 786 } 787 788 if (!empty($changes)) { 789 return $changes; 790 } else { 791 // in case we still have nothing at this point 792 return new IXR_Error(30, 'There are no changes in the specified timeframe'); 793 } 794 } 795 796 /** 797 * Returns a list of recent media changes since give timestamp 798 * 799 * @author Michael Hamann <michael@content-space.de> 800 * @author Michael Klier <chi@chimeric.de> 801 */ 802 function getRecentMediaChanges($timestamp) { 803 if(strlen($timestamp) != 10) 804 return new IXR_Error(20, 'The provided value is not a valid timestamp'); 805 806 $recents = getRecentsSince($timestamp, null, '', RECENTS_MEDIA_CHANGES); 807 808 $changes = array(); 809 810 foreach ($recents as $recent) { 811 $change = array(); 812 $change['name'] = $recent['id']; 813 $change['lastModified'] = new IXR_Date($recent['date']); 814 $change['author'] = $recent['user']; 815 $change['version'] = $recent['date']; 816 $change['perms'] = $recent['perms']; 817 $change['size'] = @filesize(mediaFN($recent['id'])); 818 array_push($changes, $change); 819 } 820 821 if (!empty($changes)) { 822 return $changes; 823 } else { 824 // in case we still have nothing at this point 825 return new IXR_Error(30, 'There are no changes in the specified timeframe'); 826 } 827 } 828 829 /** 830 * Returns a list of available revisions of a given wiki page 831 * 832 * @author Michael Klier <chi@chimeric.de> 833 */ 834 function pageVersions($id, $first) { 835 global $conf; 836 837 $versions = array(); 838 839 if(empty($id)) 840 return new IXR_Error(1, 'Empty page ID'); 841 842 $revisions = getRevisions($id, $first, $conf['recent']+1); 843 844 if(count($revisions)==0 && $first!=0) { 845 $first=0; 846 $revisions = getRevisions($id, $first, $conf['recent']+1); 847 } 848 849 if(count($revisions)>0 && $first==0) { 850 array_unshift($revisions, ''); // include current revision 851 array_pop($revisions); // remove extra log entry 852 } 853 854 $hasNext = false; 855 if(count($revisions)>$conf['recent']) { 856 $hasNext = true; 857 array_pop($revisions); // remove extra log entry 858 } 859 860 if(!empty($revisions)) { 861 foreach($revisions as $rev) { 862 $file = wikiFN($id,$rev); 863 $time = @filemtime($file); 864 // we check if the page actually exists, if this is not the 865 // case this can lead to less pages being returned than 866 // specified via $conf['recent'] 867 if($time){ 868 $info = getRevisionInfo($id, $time, 1024); 869 if(!empty($info)) { 870 $data['user'] = $info['user']; 871 $data['ip'] = $info['ip']; 872 $data['type'] = $info['type']; 873 $data['sum'] = $info['sum']; 874 $data['modified'] = new IXR_Date($info['date']); 875 $data['version'] = $info['date']; 876 array_push($versions, $data); 877 } 878 } 879 } 880 return $versions; 881 } else { 882 return array(); 883 } 884 } 885 886 /** 887 * The version of Wiki RPC API supported 888 */ 889 function wiki_RPCVersion(){ 890 return 2; 891 } 892 893 894 /** 895 * Locks or unlocks a given batch of pages 896 * 897 * Give an associative array with two keys: lock and unlock. Both should contain a 898 * list of pages to lock or unlock 899 * 900 * Returns an associative array with the keys locked, lockfail, unlocked and 901 * unlockfail, each containing lists of pages. 902 */ 903 function setLocks($set){ 904 $locked = array(); 905 $lockfail = array(); 906 $unlocked = array(); 907 $unlockfail = array(); 908 909 foreach((array) $set['lock'] as $id){ 910 if(checklock($id)){ 911 $lockfail[] = $id; 912 }else{ 913 lock($id); 914 $locked[] = $id; 915 } 916 } 917 918 foreach((array) $set['unlock'] as $id){ 919 if(unlock($id)){ 920 $unlocked[] = $id; 921 }else{ 922 $unlockfail[] = $id; 923 } 924 } 925 926 return array( 927 'locked' => $locked, 928 'lockfail' => $lockfail, 929 'unlocked' => $unlocked, 930 'unlockfail' => $unlockfail, 931 ); 932 } 933 934 function getAPIVersion(){ 935 return DOKU_XMLRPC_API_VERSION; 936 } 937 938 function login($user,$pass){ 939 global $conf; 940 global $auth; 941 if(!$conf['useacl']) return 0; 942 if(!$auth) return 0; 943 if($auth->canDo('external')){ 944 return $auth->trustExternal($user,$pass,false); 945 }else{ 946 return auth_login($user,$pass,false,true); 947 } 948 } 949 950 951} 952 953$server = new dokuwiki_xmlrpc_server(); 954 955// vim:ts=4:sw=4:et:enc=utf-8: 956