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