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