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