1797c0d11SAndreas Gohr<?php 27aec69d1SGuy Brandif(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); 3797c0d11SAndreas Gohr 4797c0d11SAndreas Gohr// fix when '<?xml' isn't on the very first line 5797c0d11SAndreas Gohrif(isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); 6797c0d11SAndreas Gohr 7445e8084SAndreas Gohr/** 8445e8084SAndreas Gohr * Increased whenever the API is changed 9445e8084SAndreas Gohr */ 10f71f4f53SAndreas Gohrdefine('DOKU_XMLRPC_API_VERSION',3); 11797c0d11SAndreas Gohr 12797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php'); 13797c0d11SAndreas Gohrsession_write_close(); //close session 14593bf8f6SMichael Klier 153ee5b583SAndreas Gohrif(!$conf['xmlrpc']) die('XML-RPC server not enabled.'); 16593bf8f6SMichael Klier 17797c0d11SAndreas Gohr/** 18797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available 19797c0d11SAndreas Gohr * XMLRPC functions. 20797c0d11SAndreas Gohr */ 21797c0d11SAndreas Gohrclass dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { 22797c0d11SAndreas Gohr var $methods = array(); 233ee5b583SAndreas Gohr var $public_methods = array(); 243ee5b583SAndreas Gohr 253ee5b583SAndreas Gohr /** 263ee5b583SAndreas Gohr * Checks if the current user is allowed to execute non anonymous methods 273ee5b583SAndreas Gohr */ 283ee5b583SAndreas Gohr function checkAuth(){ 293ee5b583SAndreas Gohr global $conf; 303ee5b583SAndreas Gohr global $USERINFO; 313ee5b583SAndreas Gohr 323ee5b583SAndreas Gohr if(!$conf['useacl']) return true; //no ACL - then no checks 333ee5b583SAndreas Gohr 343ee5b583SAndreas Gohr $allowed = explode(',',$conf['xmlrpcuser']); 353ee5b583SAndreas Gohr $allowed = array_map('trim', $allowed); 363ee5b583SAndreas Gohr $allowed = array_unique($allowed); 373ee5b583SAndreas Gohr $allowed = array_filter($allowed); 383ee5b583SAndreas Gohr 393ee5b583SAndreas Gohr if(!count($allowed)) return true; //no restrictions 403ee5b583SAndreas Gohr 413ee5b583SAndreas Gohr $user = $_SERVER['REMOTE_USER']; 423ee5b583SAndreas Gohr $groups = (array) $USERINFO['grps']; 433ee5b583SAndreas Gohr 443ee5b583SAndreas Gohr if(in_array($user,$allowed)) return true; //user explicitly mentioned 453ee5b583SAndreas Gohr 463ee5b583SAndreas Gohr //check group memberships 473ee5b583SAndreas Gohr foreach($groups as $group){ 483ee5b583SAndreas Gohr if(in_array('@'.$group,$allowed)) return true; 493ee5b583SAndreas Gohr } 503ee5b583SAndreas Gohr 513ee5b583SAndreas Gohr //still here? no access! 523ee5b583SAndreas Gohr return false; 533ee5b583SAndreas Gohr } 543ee5b583SAndreas Gohr 553ee5b583SAndreas Gohr /** 563ee5b583SAndreas Gohr * Adds a callback, extends parent method 573ee5b583SAndreas Gohr * 583ee5b583SAndreas Gohr * add another parameter to define if anonymous access to 593ee5b583SAndreas Gohr * this method should be granted. 603ee5b583SAndreas Gohr */ 613ee5b583SAndreas Gohr function addCallback($method, $callback, $args, $help, $public=false){ 623ee5b583SAndreas Gohr if($public) $this->public_methods[] = $method; 633ee5b583SAndreas Gohr return parent::addCallback($method, $callback, $args, $help); 643ee5b583SAndreas Gohr } 653ee5b583SAndreas Gohr 663ee5b583SAndreas Gohr /** 673ee5b583SAndreas Gohr * Execute a call, extends parent method 683ee5b583SAndreas Gohr * 693ee5b583SAndreas Gohr * Checks for authentication first 703ee5b583SAndreas Gohr */ 713ee5b583SAndreas Gohr function call($methodname, $args){ 723ee5b583SAndreas Gohr if(!in_array($methodname,$this->public_methods) && !$this->checkAuth()){ 733ee5b583SAndreas Gohr return new IXR_Error(-32603, 'server error. not authorized to call method "'.$methodname.'".'); 743ee5b583SAndreas Gohr } 753ee5b583SAndreas Gohr return parent::call($methodname, $args); 763ee5b583SAndreas Gohr } 77797c0d11SAndreas Gohr 78797c0d11SAndreas Gohr /** 79797c0d11SAndreas Gohr * Constructor. Register methods and run Server 80797c0d11SAndreas Gohr */ 81797c0d11SAndreas Gohr function dokuwiki_xmlrpc_server(){ 82797c0d11SAndreas Gohr $this->IXR_IntrospectionServer(); 83797c0d11SAndreas Gohr 84797c0d11SAndreas Gohr /* DokuWiki's own methods */ 85797c0d11SAndreas Gohr $this->addCallback( 86445e8084SAndreas Gohr 'dokuwiki.getXMLRPCAPIVersion', 87445e8084SAndreas Gohr 'this:getAPIVersion', 88445e8084SAndreas Gohr array('integer'), 893ee5b583SAndreas Gohr 'Returns the XMLRPC API version.', 903ee5b583SAndreas Gohr true 91445e8084SAndreas Gohr ); 92445e8084SAndreas Gohr 93445e8084SAndreas Gohr $this->addCallback( 94797c0d11SAndreas Gohr 'dokuwiki.getVersion', 95797c0d11SAndreas Gohr 'getVersion', 96797c0d11SAndreas Gohr array('string'), 973ee5b583SAndreas Gohr 'Returns the running DokuWiki version.', 983ee5b583SAndreas Gohr true 99797c0d11SAndreas Gohr ); 100797c0d11SAndreas Gohr 1011b11c097SAndreas Gohr $this->addCallback( 102445e8084SAndreas Gohr 'dokuwiki.login', 103445e8084SAndreas Gohr 'this:login', 104445e8084SAndreas Gohr array('integer','string','string'), 1053ee5b583SAndreas Gohr 'Tries to login with the given credentials and sets auth cookies.', 1063ee5b583SAndreas Gohr true 107445e8084SAndreas Gohr ); 108445e8084SAndreas Gohr 109445e8084SAndreas Gohr $this->addCallback( 1101b11c097SAndreas Gohr 'dokuwiki.getPagelist', 1111b11c097SAndreas Gohr 'this:readNamespace', 1121b11c097SAndreas Gohr array('struct','string','struct'), 1131b11c097SAndreas Gohr 'List all pages within the given namespace.' 1141b11c097SAndreas Gohr ); 1151b11c097SAndreas Gohr 1161b11c097SAndreas Gohr $this->addCallback( 117f71f4f53SAndreas Gohr 'dokuwiki.search', 118f71f4f53SAndreas Gohr 'this:search', 119f71f4f53SAndreas Gohr array('struct','string'), 120f71f4f53SAndreas Gohr 'Perform a fulltext search and return a list of matching pages' 121f71f4f53SAndreas Gohr ); 122f71f4f53SAndreas Gohr 123f71f4f53SAndreas Gohr $this->addCallback( 1241b11c097SAndreas Gohr 'dokuwiki.getTime', 1251b11c097SAndreas Gohr 'time', 1261b11c097SAndreas Gohr array('int'), 1271b11c097SAndreas Gohr 'Return the current time at the wiki server.' 1281b11c097SAndreas Gohr ); 1291b11c097SAndreas Gohr 13028ec3c76SAndreas Gohr $this->addCallback( 13128ec3c76SAndreas Gohr 'dokuwiki.setLocks', 13228ec3c76SAndreas Gohr 'this:setLocks', 13328ec3c76SAndreas Gohr array('struct','struct'), 13428ec3c76SAndreas Gohr 'Lock or unlock pages.' 13528ec3c76SAndreas Gohr ); 13628ec3c76SAndreas Gohr 137797c0d11SAndreas Gohr /* Wiki API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 */ 138797c0d11SAndreas Gohr $this->addCallback( 139797c0d11SAndreas Gohr 'wiki.getRPCVersionSupported', 140797c0d11SAndreas Gohr 'this:wiki_RPCVersion', 141797c0d11SAndreas Gohr array('int'), 1423ee5b583SAndreas Gohr 'Returns 2 with the supported RPC API version.', 1433ee5b583SAndreas Gohr true 144797c0d11SAndreas Gohr ); 145797c0d11SAndreas Gohr $this->addCallback( 146797c0d11SAndreas Gohr 'wiki.getPage', 147797c0d11SAndreas Gohr 'this:rawPage', 148797c0d11SAndreas Gohr array('string','string'), 149797c0d11SAndreas Gohr 'Get the raw Wiki text of page, latest version.' 150797c0d11SAndreas Gohr ); 151797c0d11SAndreas Gohr $this->addCallback( 152797c0d11SAndreas Gohr 'wiki.getPageVersion', 153797c0d11SAndreas Gohr 'this:rawPage', 154797c0d11SAndreas Gohr array('string','string','int'), 155797c0d11SAndreas Gohr 'Get the raw Wiki text of page.' 156797c0d11SAndreas Gohr ); 157797c0d11SAndreas Gohr $this->addCallback( 158797c0d11SAndreas Gohr 'wiki.getPageHTML', 159797c0d11SAndreas Gohr 'this:htmlPage', 160797c0d11SAndreas Gohr array('string','string'), 161797c0d11SAndreas Gohr 'Return page in rendered HTML, latest version.' 162797c0d11SAndreas Gohr ); 163797c0d11SAndreas Gohr $this->addCallback( 164797c0d11SAndreas Gohr 'wiki.getPageHTMLVersion', 165797c0d11SAndreas Gohr 'this:htmlPage', 166797c0d11SAndreas Gohr array('string','string','int'), 167797c0d11SAndreas Gohr 'Return page in rendered HTML.' 168797c0d11SAndreas Gohr ); 169797c0d11SAndreas Gohr $this->addCallback( 170797c0d11SAndreas Gohr 'wiki.getAllPages', 171797c0d11SAndreas Gohr 'this:listPages', 172797c0d11SAndreas Gohr array('struct'), 173797c0d11SAndreas Gohr 'Returns a list of all pages. The result is an array of utf8 pagenames.' 174797c0d11SAndreas Gohr ); 175797c0d11SAndreas Gohr $this->addCallback( 17626bec61eSMichael Klier 'wiki.getAttachments', 17726bec61eSMichael Klier 'this:listAttachments', 178c63d1645SGina Haeussge array('struct', 'string', 'struct'), 17926bec61eSMichael Klier 'Returns a list of all media files.' 18026bec61eSMichael Klier ); 18126bec61eSMichael Klier $this->addCallback( 182797c0d11SAndreas Gohr 'wiki.getBackLinks', 183797c0d11SAndreas Gohr 'this:listBackLinks', 184797c0d11SAndreas Gohr array('struct','string'), 185797c0d11SAndreas Gohr 'Returns the pages that link to this page.' 186797c0d11SAndreas Gohr ); 187797c0d11SAndreas Gohr $this->addCallback( 188797c0d11SAndreas Gohr 'wiki.getPageInfo', 189797c0d11SAndreas Gohr 'this:pageInfo', 190797c0d11SAndreas Gohr array('struct','string'), 191797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 192797c0d11SAndreas Gohr ); 193797c0d11SAndreas Gohr $this->addCallback( 194797c0d11SAndreas Gohr 'wiki.getPageInfoVersion', 195797c0d11SAndreas Gohr 'this:pageInfo', 196797c0d11SAndreas Gohr array('struct','string','int'), 197797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 198797c0d11SAndreas Gohr ); 1993a1dad2dSDennis Ploeger $this->addCallback( 20073056168SMichael Klier 'wiki.getPageVersions', 20173056168SMichael Klier 'this:pageVersions', 20273056168SMichael Klier array('struct','string','int'), 20373056168SMichael Klier 'Returns the available revisions of the page.' 20473056168SMichael Klier ); 20573056168SMichael Klier $this->addCallback( 2063a1dad2dSDennis Ploeger 'wiki.putPage', 2073a1dad2dSDennis Ploeger 'this:putPage', 208222572bfSMichael Klier array('int', 'string', 'string', 'struct'), 209fdd2e9d6SMichael Klier 'Saves a wiki page.' 2103a1dad2dSDennis Ploeger ); 211beccd742SMichael Klier $this->addCallback( 212beccd742SMichael Klier 'wiki.listLinks', 213beccd742SMichael Klier 'this:listLinks', 214beccd742SMichael Klier array('struct','string'), 215fdd2e9d6SMichael Klier 'Lists all links contained in a wiki page.' 216beccd742SMichael Klier ); 21763dd0d58SMichael Klier $this->addCallback( 21863dd0d58SMichael Klier 'wiki.getRecentChanges', 21963dd0d58SMichael Klier 'this:getRecentChanges', 22063dd0d58SMichael Klier array('struct','int'), 22199c8d7f2Smichael 'Returns a struct about all recent changes since given timestamp.' 22299c8d7f2Smichael ); 22399c8d7f2Smichael $this->addCallback( 22499c8d7f2Smichael 'wiki.getRecentMediaChanges', 22599c8d7f2Smichael 'this:getRecentMediaChanges', 22699c8d7f2Smichael array('struct','int'), 22799c8d7f2Smichael 'Returns a struct about all recent media changes since given timestamp.' 22863dd0d58SMichael Klier ); 229e62b9ea5SMichael Klier $this->addCallback( 230e62b9ea5SMichael Klier 'wiki.aclCheck', 231e62b9ea5SMichael Klier 'this:aclCheck', 232c63d1645SGina Haeussge array('int', 'string'), 233e62b9ea5SMichael Klier 'Returns the permissions of a given wiki page.' 234e62b9ea5SMichael Klier ); 2352aca132fSMichael Klier $this->addCallback( 2362aca132fSMichael Klier 'wiki.putAttachment', 2372aca132fSMichael Klier 'this:putAttachment', 2382aca132fSMichael Klier array('struct', 'string', 'base64', 'struct'), 2392aca132fSMichael Klier 'Upload a file to the wiki.' 2402aca132fSMichael Klier ); 241cfef3001SGina Haeussge $this->addCallback( 242f01ff8c1SGina Haeussge 'wiki.deleteAttachment', 243f01ff8c1SGina Haeussge 'this:deleteAttachment', 244f01ff8c1SGina Haeussge array('int', 'string'), 245f01ff8c1SGina Haeussge 'Delete a file from the wiki.' 246f01ff8c1SGina Haeussge ); 247f01ff8c1SGina Haeussge $this->addCallback( 248cfef3001SGina Haeussge 'wiki.getAttachment', 249cfef3001SGina Haeussge 'this:getAttachment', 250c63d1645SGina Haeussge array('base64', 'string'), 251cfef3001SGina Haeussge 'Download a file from the wiki.' 252cfef3001SGina Haeussge ); 2535672e868SGina Haeussge $this->addCallback( 2545672e868SGina Haeussge 'wiki.getAttachmentInfo', 2555672e868SGina Haeussge 'this:getAttachmentInfo', 256c63d1645SGina Haeussge array('struct', 'string'), 2575672e868SGina Haeussge 'Returns a struct with infos about the attachment.' 2585672e868SGina Haeussge ); 259797c0d11SAndreas Gohr 260bb32615dSMichael Klier /** 261bb32615dSMichael Klier * Trigger XMLRPC_CALLBACK_REGISTER, action plugins can use this event 262bb32615dSMichael Klier * to extend the XMLRPC interface and register their own callbacks. 263bb32615dSMichael Klier * 264bb32615dSMichael Klier * Event data: 265bb32615dSMichael Klier * The XMLRPC server object: 266bb32615dSMichael Klier * 267bb32615dSMichael Klier * $event->data->addCallback() - register a callback, the second 268bb32615dSMichael Klier * paramter has to be of the form "plugin:<pluginname>:<plugin 269bb32615dSMichael Klier * method>" 270bb32615dSMichael Klier * 271bb32615dSMichael Klier * $event->data->callbacks - an array which holds all awaylable 272bb32615dSMichael Klier * callbacks 273bb32615dSMichael Klier */ 274bb32615dSMichael Klier trigger_event('XMLRPC_CALLBACK_REGISTER', $this); 275bb32615dSMichael Klier 276797c0d11SAndreas Gohr $this->serve(); 277797c0d11SAndreas Gohr } 278797c0d11SAndreas Gohr 279797c0d11SAndreas Gohr /** 280797c0d11SAndreas Gohr * Return a raw wiki page 281797c0d11SAndreas Gohr */ 282797c0d11SAndreas Gohr function rawPage($id,$rev=''){ 283797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 284797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 285797c0d11SAndreas Gohr } 2862c176304SMichael Klier $text = rawWiki($id,$rev); 2872c176304SMichael Klier if(!$text) { 288fe17917eSAdrian Lang return pageTemplate($id); 2892c176304SMichael Klier } else { 2902c176304SMichael Klier return $text; 2912c176304SMichael Klier } 292797c0d11SAndreas Gohr } 293797c0d11SAndreas Gohr 294797c0d11SAndreas Gohr /** 295cfef3001SGina Haeussge * Return a media file encoded in base64 296c63d1645SGina Haeussge * 297c63d1645SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 298cfef3001SGina Haeussge */ 299cfef3001SGina Haeussge function getAttachment($id){ 300c63d1645SGina Haeussge $id = cleanID($id); 301cfef3001SGina Haeussge if (auth_quickaclcheck(getNS($id).':*') < AUTH_READ) 302cfef3001SGina Haeussge return new IXR_Error(1, 'You are not allowed to read this file'); 303cfef3001SGina Haeussge 304cfef3001SGina Haeussge $file = mediaFN($id); 305cfef3001SGina Haeussge if (!@ file_exists($file)) 306cfef3001SGina Haeussge return new IXR_Error(1, 'The requested file does not exist'); 307cfef3001SGina Haeussge 308cfef3001SGina Haeussge $data = io_readFile($file, false); 309cfef3001SGina Haeussge $base64 = base64_encode($data); 310cfef3001SGina Haeussge return $base64; 311cfef3001SGina Haeussge } 312cfef3001SGina Haeussge 313cfef3001SGina Haeussge /** 3145672e868SGina Haeussge * Return info about a media file 3155672e868SGina Haeussge * 3165672e868SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 3175672e868SGina Haeussge */ 3185672e868SGina Haeussge function getAttachmentInfo($id){ 3195672e868SGina Haeussge $id = cleanID($id); 3205672e868SGina Haeussge $info = array( 3215672e868SGina Haeussge 'lastModified' => 0, 3225672e868SGina Haeussge 'size' => 0, 3235672e868SGina Haeussge ); 3245672e868SGina Haeussge 3255672e868SGina Haeussge $file = mediaFN($id); 3265672e868SGina Haeussge if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){ 3275672e868SGina Haeussge $info['lastModified'] = new IXR_Date(filemtime($file)); 3285672e868SGina Haeussge $info['size'] = filesize($file); 3295672e868SGina Haeussge } 3305672e868SGina Haeussge 3315672e868SGina Haeussge return $info; 3325672e868SGina Haeussge } 3335672e868SGina Haeussge 3345672e868SGina Haeussge /** 335797c0d11SAndreas Gohr * Return a wiki page rendered to html 336797c0d11SAndreas Gohr */ 337797c0d11SAndreas Gohr function htmlPage($id,$rev=''){ 338797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 339797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 340797c0d11SAndreas Gohr } 341797c0d11SAndreas Gohr return p_wiki_xhtml($id,$rev,false); 342797c0d11SAndreas Gohr } 343797c0d11SAndreas Gohr 344797c0d11SAndreas Gohr /** 345797c0d11SAndreas Gohr * List all pages - we use the indexer list here 346797c0d11SAndreas Gohr */ 347797c0d11SAndreas Gohr function listPages(){ 348dfd13e55SMichael Klier global $conf; 349dfd13e55SMichael Klier 350dfd13e55SMichael Klier $list = array(); 351dfd13e55SMichael Klier $pages = file($conf['indexdir'] . '/page.idx'); 352dfd13e55SMichael Klier $pages = array_filter($pages, 'isVisiblePage'); 353dfd13e55SMichael Klier 354dfd13e55SMichael Klier foreach(array_keys($pages) as $idx) { 355dfd13e55SMichael Klier if(page_exists($pages[$idx])) { 356dfd13e55SMichael Klier $perm = auth_quickaclcheck($pages[$idx]); 357dfd13e55SMichael Klier if($perm >= AUTH_READ) { 358dfd13e55SMichael Klier $page = array(); 359dfd13e55SMichael Klier $page['id'] = trim($pages[$idx]); 360dfd13e55SMichael Klier $page['perms'] = $perm; 361dfd13e55SMichael Klier $page['size'] = @filesize(wikiFN($pages[$idx])); 362e070c6f3SGina Haeussge $page['lastModified'] = new IXR_Date(@filemtime(wikiFN($pages[$idx]))); 363dfd13e55SMichael Klier $list[] = $page; 364dfd13e55SMichael Klier } 365dfd13e55SMichael Klier } 366dfd13e55SMichael Klier } 367dfd13e55SMichael Klier 368dfd13e55SMichael Klier return $list; 369797c0d11SAndreas Gohr } 370797c0d11SAndreas Gohr 371797c0d11SAndreas Gohr /** 3721b11c097SAndreas Gohr * List all pages in the given namespace (and below) 3731b11c097SAndreas Gohr */ 3741b11c097SAndreas Gohr function readNamespace($ns,$opts){ 3751b11c097SAndreas Gohr global $conf; 3761b11c097SAndreas Gohr 3771b11c097SAndreas Gohr if(!is_array($opts)) $opts=array(); 3781b11c097SAndreas Gohr 3791b11c097SAndreas Gohr $ns = cleanID($ns); 3801b11c097SAndreas Gohr $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 3811b11c097SAndreas Gohr $data = array(); 3826fc3aa1aSAndreas Gohr $opts['skipacl'] = 0; // no ACL skipping for XMLRPC 3831b11c097SAndreas Gohr search($data, $conf['datadir'], 'search_allpages', $opts, $dir); 3841b11c097SAndreas Gohr return $data; 3851b11c097SAndreas Gohr } 3861b11c097SAndreas Gohr 3871b11c097SAndreas Gohr /** 388f71f4f53SAndreas Gohr * List all pages in the given namespace (and below) 389f71f4f53SAndreas Gohr */ 390f71f4f53SAndreas Gohr function search($query){ 391f71f4f53SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 392f71f4f53SAndreas Gohr 393f71f4f53SAndreas Gohr $regex = ''; 394f71f4f53SAndreas Gohr $data = ft_pageSearch($query,$regex); 395f71f4f53SAndreas Gohr $pages = array(); 396f71f4f53SAndreas Gohr 397f71f4f53SAndreas Gohr // prepare additional data 398f71f4f53SAndreas Gohr $idx = 0; 399f71f4f53SAndreas Gohr foreach($data as $id => $score){ 400f71f4f53SAndreas Gohr $file = wikiFN($id); 401f71f4f53SAndreas Gohr 402f71f4f53SAndreas Gohr if($idx < FT_SNIPPET_NUMBER){ 403f71f4f53SAndreas Gohr $snippet = ft_snippet($id,$regex); 404f71f4f53SAndreas Gohr $idx++; 405f71f4f53SAndreas Gohr }else{ 406f71f4f53SAndreas Gohr $snippet = ''; 407f71f4f53SAndreas Gohr } 408f71f4f53SAndreas Gohr 409f71f4f53SAndreas Gohr $pages[] = array( 410f71f4f53SAndreas Gohr 'id' => $id, 411f71f4f53SAndreas Gohr 'score' => $score, 412f71f4f53SAndreas Gohr 'rev' => filemtime($file), 413f71f4f53SAndreas Gohr 'mtime' => filemtime($file), 414f71f4f53SAndreas Gohr 'size' => filesize($file), 415f71f4f53SAndreas Gohr 'snippet' => $snippet, 416f71f4f53SAndreas Gohr ); 417f71f4f53SAndreas Gohr } 418f71f4f53SAndreas Gohr return $data; 419f71f4f53SAndreas Gohr } 420f71f4f53SAndreas Gohr 421f71f4f53SAndreas Gohr 422f71f4f53SAndreas Gohr /** 42326bec61eSMichael Klier * List all media files. 4243275953aSGina Haeussge * 4253275953aSGina Haeussge * Available options are 'recursive' for also including the subnamespaces 4263275953aSGina Haeussge * in the listing, and 'pattern' for filtering the returned files against 4273275953aSGina Haeussge * a regular expression matching their name. 4283275953aSGina Haeussge * 4293275953aSGina Haeussge * @author Gina Haeussge <osd@foosel.net> 43026bec61eSMichael Klier */ 4313275953aSGina Haeussge function listAttachments($ns, $options = array()) { 43226bec61eSMichael Klier global $conf; 43326bec61eSMichael Klier global $lang; 43426bec61eSMichael Klier 43526bec61eSMichael Klier $ns = cleanID($ns); 43626bec61eSMichael Klier 4376fc3aa1aSAndreas Gohr if (!is_array($options)) $options = array(); 4386fc3aa1aSAndreas Gohr $options['skipacl'] = 0; // no ACL skipping for XMLRPC 4393275953aSGina Haeussge 4403275953aSGina Haeussge 44126bec61eSMichael Klier if(auth_quickaclcheck($ns.':*') >= AUTH_READ) { 44226bec61eSMichael Klier $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 44326bec61eSMichael Klier 44426bec61eSMichael Klier $data = array(); 445224122cfSAndreas Gohr search($data, $conf['mediadir'], 'search_media', $options, $dir); 446224122cfSAndreas Gohr $len = count($data); 447224122cfSAndreas Gohr if(!$len) return array(); 44826bec61eSMichael Klier 449224122cfSAndreas Gohr for($i=0; $i<$len; $i++) { 450224122cfSAndreas Gohr unset($data[$i]['meta']); 451224122cfSAndreas Gohr $data[$i]['lastModified'] = new IXR_Date($data[$i]['mtime']); 45226bec61eSMichael Klier } 453224122cfSAndreas Gohr return $data; 45426bec61eSMichael Klier } else { 45526bec61eSMichael Klier return new IXR_Error(1, 'You are not allowed to list media files.'); 45626bec61eSMichael Klier } 45726bec61eSMichael Klier } 45826bec61eSMichael Klier 45926bec61eSMichael Klier /** 460797c0d11SAndreas Gohr * Return a list of backlinks 461797c0d11SAndreas Gohr */ 462beccd742SMichael Klier function listBackLinks($id){ 463797c0d11SAndreas Gohr return ft_backlinks($id); 464797c0d11SAndreas Gohr } 465797c0d11SAndreas Gohr 466797c0d11SAndreas Gohr /** 46763dd0d58SMichael Klier * Return some basic data about a page 468797c0d11SAndreas Gohr */ 469797c0d11SAndreas Gohr function pageInfo($id,$rev=''){ 470797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 471797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 472797c0d11SAndreas Gohr } 473797c0d11SAndreas Gohr $file = wikiFN($id,$rev); 474797c0d11SAndreas Gohr $time = @filemtime($file); 475797c0d11SAndreas Gohr if(!$time){ 476797c0d11SAndreas Gohr return new IXR_Error(10, 'The requested page does not exist'); 477797c0d11SAndreas Gohr } 478797c0d11SAndreas Gohr 479797c0d11SAndreas Gohr $info = getRevisionInfo($id, $time, 1024); 480797c0d11SAndreas Gohr 481797c0d11SAndreas Gohr $data = array( 482797c0d11SAndreas Gohr 'name' => $id, 483797c0d11SAndreas Gohr 'lastModified' => new IXR_Date($time), 484797c0d11SAndreas Gohr 'author' => (($info['user']) ? $info['user'] : $info['ip']), 485797c0d11SAndreas Gohr 'version' => $time 486797c0d11SAndreas Gohr ); 48763dd0d58SMichael Klier 48863dd0d58SMichael Klier return ($data); 489797c0d11SAndreas Gohr } 490797c0d11SAndreas Gohr 491797c0d11SAndreas Gohr /** 4923a1dad2dSDennis Ploeger * Save a wiki page 493222572bfSMichael Klier * 494222572bfSMichael Klier * @author Michael Klier <chi@chimeric.de> 4953a1dad2dSDennis Ploeger */ 496222572bfSMichael Klier function putPage($id, $text, $params) { 4973a1dad2dSDennis Ploeger global $TEXT; 498a6a229ceSMichael Klier global $lang; 499593bf8f6SMichael Klier global $conf; 5003a1dad2dSDennis Ploeger 501222572bfSMichael Klier $id = cleanID($id); 50256523eecSAndreas Gohr $TEXT = cleanText($text); 503222572bfSMichael Klier $sum = $params['sum']; 504222572bfSMichael Klier $minor = $params['minor']; 505222572bfSMichael Klier 506222572bfSMichael Klier if(empty($id)) 507fdd2e9d6SMichael Klier return new IXR_Error(1, 'Empty page ID'); 508222572bfSMichael Klier 50956523eecSAndreas Gohr if(!page_exists($id) && trim($TEXT) == '' ) { 51051597811SMichael Klier return new IXR_ERROR(1, 'Refusing to write an empty new wiki page'); 51151597811SMichael Klier } 51251597811SMichael Klier 513055b0144SChris Smith if(auth_quickaclcheck($id) < AUTH_EDIT) 514222572bfSMichael Klier return new IXR_Error(1, 'You are not allowed to edit this page'); 5153a1dad2dSDennis Ploeger 5163a1dad2dSDennis Ploeger // Check, if page is locked 517222572bfSMichael Klier if(checklock($id)) 518222572bfSMichael Klier return new IXR_Error(1, 'The page is currently locked'); 519222572bfSMichael Klier 520a6a229ceSMichael Klier // SPAM check 5213a1dad2dSDennis Ploeger if(checkwordblock()) 522222572bfSMichael Klier return new IXR_Error(1, 'Positive wordblock check'); 5233a1dad2dSDennis Ploeger 524a6a229ceSMichael Klier // autoset summary on new pages 525a6a229ceSMichael Klier if(!page_exists($id) && empty($sum)) { 526a6a229ceSMichael Klier $sum = $lang['created']; 527a6a229ceSMichael Klier } 528a6a229ceSMichael Klier 529a6a229ceSMichael Klier // autoset summary on deleted pages 530a6a229ceSMichael Klier if(page_exists($id) && empty($TEXT) && empty($sum)) { 531a6a229ceSMichael Klier $sum = $lang['deleted']; 532a6a229ceSMichael Klier } 533a6a229ceSMichael Klier 534222572bfSMichael Klier lock($id); 5353a1dad2dSDennis Ploeger 536222572bfSMichael Klier saveWikiText($id,$TEXT,$sum,$minor); 5373a1dad2dSDennis Ploeger 538222572bfSMichael Klier unlock($id); 5393a1dad2dSDennis Ploeger 540593bf8f6SMichael Klier // run the indexer if page wasn't indexed yet 541593bf8f6SMichael Klier if(!@file_exists(metaFN($id, '.indexed'))) { 542593bf8f6SMichael Klier // try to aquire a lock 543593bf8f6SMichael Klier $lock = $conf['lockdir'].'/_indexer.lock'; 544593bf8f6SMichael Klier while(!@mkdir($lock,$conf['dmode'])){ 545593bf8f6SMichael Klier usleep(50); 546593bf8f6SMichael Klier if(time()-@filemtime($lock) > 60*5){ 547593bf8f6SMichael Klier // looks like a stale lock - remove it 548593bf8f6SMichael Klier @rmdir($lock); 549593bf8f6SMichael Klier }else{ 550593bf8f6SMichael Klier return false; 551593bf8f6SMichael Klier } 552593bf8f6SMichael Klier } 553593bf8f6SMichael Klier if($conf['dperm']) chmod($lock, $conf['dperm']); 554593bf8f6SMichael Klier 555593bf8f6SMichael Klier // do the work 556593bf8f6SMichael Klier idx_addPage($id); 557593bf8f6SMichael Klier 558593bf8f6SMichael Klier // we're finished - save and free lock 559593bf8f6SMichael Klier io_saveFile(metaFN($id,'.indexed'),INDEXER_VERSION); 560593bf8f6SMichael Klier @rmdir($lock); 561593bf8f6SMichael Klier } 562593bf8f6SMichael Klier 5633a1dad2dSDennis Ploeger return 0; 564beccd742SMichael Klier } 5653a1dad2dSDennis Ploeger 566beccd742SMichael Klier /** 5672aca132fSMichael Klier * Uploads a file to the wiki. 5682aca132fSMichael Klier * 5692aca132fSMichael Klier * Michael Klier <chi@chimeric.de> 5702aca132fSMichael Klier */ 571f01ff8c1SGina Haeussge function putAttachment($id, $file, $params) { 5722aca132fSMichael Klier global $conf; 5732aca132fSMichael Klier global $lang; 5742aca132fSMichael Klier 575f01ff8c1SGina Haeussge $auth = auth_quickaclcheck(getNS($id).':*'); 5762aca132fSMichael Klier if($auth >= AUTH_UPLOAD) { 577f01ff8c1SGina Haeussge if(!isset($id)) { 5782aca132fSMichael Klier return new IXR_ERROR(1, 'Filename not given.'); 5792aca132fSMichael Klier } 5802aca132fSMichael Klier 581*c77fa67bSMichael Hamann $ftmp = $conf['tmpdir'] . '/' . md5($id.clientIP()); 5822aca132fSMichael Klier 5832aca132fSMichael Klier // save temporary file 5842aca132fSMichael Klier @unlink($ftmp); 5852aca132fSMichael Klier $buff = base64_decode($file); 5862aca132fSMichael Klier io_saveFile($ftmp, $buff); 5872aca132fSMichael Klier 5882aca132fSMichael Klier // get filename 589ecebf3a8SAndreas Gohr list($iext, $imime,$dl) = mimetype($id); 590f01ff8c1SGina Haeussge $id = cleanID($id); 5912aca132fSMichael Klier $fn = mediaFN($id); 5922aca132fSMichael Klier 5932aca132fSMichael Klier // get filetype regexp 5942aca132fSMichael Klier $types = array_keys(getMimeTypes()); 5952aca132fSMichael Klier $types = array_map(create_function('$q','return preg_quote($q,"/");'),$types); 5962aca132fSMichael Klier $regex = join('|',$types); 5972aca132fSMichael Klier 5982aca132fSMichael Klier // because a temp file was created already 5992aca132fSMichael Klier if(preg_match('/\.('.$regex.')$/i',$fn)) { 6002aca132fSMichael Klier //check for overwrite 60199c8d7f2Smichael $overwrite = @file_exists($fn); 60299c8d7f2Smichael if($overwrite && (!$params['ow'] || $auth < AUTH_DELETE)) { 603224122cfSAndreas Gohr return new IXR_ERROR(1, $lang['uploadexist'].'1'); 6042aca132fSMichael Klier } 6052aca132fSMichael Klier // check for valid content 6062aca132fSMichael Klier $ok = media_contentcheck($ftmp, $imime); 6072aca132fSMichael Klier if($ok == -1) { 608224122cfSAndreas Gohr return new IXR_ERROR(1, sprintf($lang['uploadexist'].'2', ".$iext")); 6092aca132fSMichael Klier } elseif($ok == -2) { 6102aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadspam']); 6112aca132fSMichael Klier } elseif($ok == -3) { 6122aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadxss']); 6132aca132fSMichael Klier } 6142aca132fSMichael Klier 6152aca132fSMichael Klier // prepare event data 6162aca132fSMichael Klier $data[0] = $ftmp; 6172aca132fSMichael Klier $data[1] = $fn; 6182aca132fSMichael Klier $data[2] = $id; 6192aca132fSMichael Klier $data[3] = $imime; 62099c8d7f2Smichael $data[4] = $overwrite; 6212aca132fSMichael Klier 6222aca132fSMichael Klier // trigger event 6232aca132fSMichael Klier return trigger_event('MEDIA_UPLOAD_FINISH', $data, array($this, '_media_upload_action'), true); 6242aca132fSMichael Klier 6252aca132fSMichael Klier } else { 6262aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadwrong']); 6272aca132fSMichael Klier } 6282aca132fSMichael Klier } else { 6292aca132fSMichael Klier return new IXR_ERROR(1, "You don't have permissions to upload files."); 6302aca132fSMichael Klier } 6312aca132fSMichael Klier } 6322aca132fSMichael Klier 6332aca132fSMichael Klier /** 634f01ff8c1SGina Haeussge * Deletes a file from the wiki. 635f01ff8c1SGina Haeussge * 636f01ff8c1SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 637f01ff8c1SGina Haeussge */ 638f01ff8c1SGina Haeussge function deleteAttachment($id){ 639f01ff8c1SGina Haeussge $auth = auth_quickaclcheck(getNS($id).':*'); 640f01ff8c1SGina Haeussge if($auth < AUTH_DELETE) return new IXR_ERROR(1, "You don't have permissions to delete files."); 641f01ff8c1SGina Haeussge global $conf; 642f01ff8c1SGina Haeussge global $lang; 643f01ff8c1SGina Haeussge 644f01ff8c1SGina Haeussge // check for references if needed 645f01ff8c1SGina Haeussge $mediareferences = array(); 646f01ff8c1SGina Haeussge if($conf['refcheck']){ 647f01ff8c1SGina Haeussge $mediareferences = ft_mediause($id,$conf['refshow']); 648f01ff8c1SGina Haeussge } 649f01ff8c1SGina Haeussge 650f01ff8c1SGina Haeussge if(!count($mediareferences)){ 651f01ff8c1SGina Haeussge $file = mediaFN($id); 652f01ff8c1SGina Haeussge if(@unlink($file)){ 65399c8d7f2Smichael addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_DELETE); 654f01ff8c1SGina Haeussge io_sweepNS($id,'mediadir'); 655f01ff8c1SGina Haeussge return 0; 656f01ff8c1SGina Haeussge } 657f01ff8c1SGina Haeussge //something went wrong 658f01ff8c1SGina Haeussge return new IXR_ERROR(1, 'Could not delete file'); 659f01ff8c1SGina Haeussge } else { 660f01ff8c1SGina Haeussge return new IXR_ERROR(1, 'File is still referenced'); 661f01ff8c1SGina Haeussge } 662f01ff8c1SGina Haeussge } 663f01ff8c1SGina Haeussge 664f01ff8c1SGina Haeussge /** 6652aca132fSMichael Klier * Moves the temporary file to its final destination. 6662aca132fSMichael Klier * 6672aca132fSMichael Klier * Michael Klier <chi@chimeric.de> 6682aca132fSMichael Klier */ 6692aca132fSMichael Klier function _media_upload_action($data) { 6702aca132fSMichael Klier global $conf; 6712aca132fSMichael Klier 67299c8d7f2Smichael if(is_array($data) && count($data)===5) { 6732aca132fSMichael Klier io_createNamespace($data[2], 'media'); 6742aca132fSMichael Klier if(rename($data[0], $data[1])) { 6752aca132fSMichael Klier chmod($data[1], $conf['fmode']); 6762aca132fSMichael Klier media_notify($data[2], $data[1], $data[3]); 67799c8d7f2Smichael // add a log entry to the media changelog 67899c8d7f2Smichael if ($data[4]) { 67999c8d7f2Smichael addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_EDIT); 68099c8d7f2Smichael } else { 68199c8d7f2Smichael addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_CREATE); 68299c8d7f2Smichael } 6832aca132fSMichael Klier return $data[2]; 6842aca132fSMichael Klier } else { 6852aca132fSMichael Klier return new IXR_ERROR(1, 'Upload failed.'); 6862aca132fSMichael Klier } 6872aca132fSMichael Klier } else { 6882aca132fSMichael Klier return new IXR_ERROR(1, 'Upload failed.'); 6892aca132fSMichael Klier } 6902aca132fSMichael Klier } 6912aca132fSMichael Klier 6922aca132fSMichael Klier /** 693e62b9ea5SMichael Klier * Returns the permissions of a given wiki page 694e62b9ea5SMichael Klier */ 695e62b9ea5SMichael Klier function aclCheck($id) { 696e62b9ea5SMichael Klier return auth_quickaclcheck($id); 697e62b9ea5SMichael Klier } 698e62b9ea5SMichael Klier 699e62b9ea5SMichael Klier /** 700beccd742SMichael Klier * Lists all links contained in a wiki page 70163dd0d58SMichael Klier * 70263dd0d58SMichael Klier * @author Michael Klier <chi@chimeric.de> 703beccd742SMichael Klier */ 704beccd742SMichael Klier function listLinks($id) { 705beccd742SMichael Klier if(auth_quickaclcheck($id) < AUTH_READ){ 706beccd742SMichael Klier return new IXR_Error(1, 'You are not allowed to read this page'); 707beccd742SMichael Klier } 708beccd742SMichael Klier $links = array(); 709beccd742SMichael Klier 710beccd742SMichael Klier // resolve page instructions 711beccd742SMichael Klier $ins = p_cached_instructions(wikiFN(cleanID($id))); 712beccd742SMichael Klier 713beccd742SMichael Klier // instantiate new Renderer - needed for interwiki links 714beccd742SMichael Klier include(DOKU_INC.'inc/parser/xhtml.php'); 715beccd742SMichael Klier $Renderer = new Doku_Renderer_xhtml(); 716beccd742SMichael Klier $Renderer->interwiki = getInterwiki(); 717beccd742SMichael Klier 718beccd742SMichael Klier // parse parse instructions 719beccd742SMichael Klier foreach($ins as $in) { 720beccd742SMichael Klier $link = array(); 721beccd742SMichael Klier switch($in[0]) { 722beccd742SMichael Klier case 'internallink': 723beccd742SMichael Klier $link['type'] = 'local'; 724beccd742SMichael Klier $link['page'] = $in[1][0]; 725beccd742SMichael Klier $link['href'] = wl($in[1][0]); 726beccd742SMichael Klier array_push($links,$link); 727beccd742SMichael Klier break; 728beccd742SMichael Klier case 'externallink': 729beccd742SMichael Klier $link['type'] = 'extern'; 730beccd742SMichael Klier $link['page'] = $in[1][0]; 731beccd742SMichael Klier $link['href'] = $in[1][0]; 732beccd742SMichael Klier array_push($links,$link); 733beccd742SMichael Klier break; 734beccd742SMichael Klier case 'interwikilink': 735beccd742SMichael Klier $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]); 736beccd742SMichael Klier $link['type'] = 'extern'; 737beccd742SMichael Klier $link['page'] = $url; 738beccd742SMichael Klier $link['href'] = $url; 739beccd742SMichael Klier array_push($links,$link); 740beccd742SMichael Klier break; 741beccd742SMichael Klier } 742beccd742SMichael Klier } 743beccd742SMichael Klier 74463dd0d58SMichael Klier return ($links); 74563dd0d58SMichael Klier } 74663dd0d58SMichael Klier 74763dd0d58SMichael Klier /** 74863dd0d58SMichael Klier * Returns a list of recent changes since give timestamp 74963dd0d58SMichael Klier * 75099c8d7f2Smichael * @author Michael Hamann <michael@content-space.de> 75163dd0d58SMichael Klier * @author Michael Klier <chi@chimeric.de> 75263dd0d58SMichael Klier */ 75363dd0d58SMichael Klier function getRecentChanges($timestamp) { 75463dd0d58SMichael Klier if(strlen($timestamp) != 10) 75563dd0d58SMichael Klier return new IXR_Error(20, 'The provided value is not a valid timestamp'); 75663dd0d58SMichael Klier 75799c8d7f2Smichael $recents = getRecentsSince($timestamp); 75863dd0d58SMichael Klier 75999c8d7f2Smichael $changes = array(); 76063dd0d58SMichael Klier 76199c8d7f2Smichael foreach ($recents as $recent) { 76299c8d7f2Smichael $change = array(); 76399c8d7f2Smichael $change['name'] = $recent['id']; 76499c8d7f2Smichael $change['lastModified'] = new IXR_Date($recent['date']); 76599c8d7f2Smichael $change['author'] = $recent['user']; 76699c8d7f2Smichael $change['version'] = $recent['date']; 76799c8d7f2Smichael $change['perms'] = $recent['perms']; 76899c8d7f2Smichael $change['size'] = @filesize(wikiFN($recent['id'])); 76963dd0d58SMichael Klier array_push($changes, $change); 77099c8d7f2Smichael } 77199c8d7f2Smichael 77299c8d7f2Smichael if (!empty($changes)) { 77399c8d7f2Smichael return $changes; 77463dd0d58SMichael Klier } else { 77563dd0d58SMichael Klier // in case we still have nothing at this point 77663dd0d58SMichael Klier return new IXR_Error(30, 'There are no changes in the specified timeframe'); 7773a1dad2dSDennis Ploeger } 77899c8d7f2Smichael } 77999c8d7f2Smichael 78099c8d7f2Smichael /** 78199c8d7f2Smichael * Returns a list of recent media changes since give timestamp 78299c8d7f2Smichael * 78399c8d7f2Smichael * @author Michael Hamann <michael@content-space.de> 78499c8d7f2Smichael * @author Michael Klier <chi@chimeric.de> 78599c8d7f2Smichael */ 78699c8d7f2Smichael function getRecentMediaChanges($timestamp) { 78799c8d7f2Smichael if(strlen($timestamp) != 10) 78899c8d7f2Smichael return new IXR_Error(20, 'The provided value is not a valid timestamp'); 78999c8d7f2Smichael 79099c8d7f2Smichael $recents = getRecentsSince($timestamp, null, '', RECENTS_MEDIA_CHANGES); 79199c8d7f2Smichael 79299c8d7f2Smichael $changes = array(); 79399c8d7f2Smichael 79499c8d7f2Smichael foreach ($recents as $recent) { 79599c8d7f2Smichael $change = array(); 79699c8d7f2Smichael $change['name'] = $recent['id']; 79799c8d7f2Smichael $change['lastModified'] = new IXR_Date($recent['date']); 79899c8d7f2Smichael $change['author'] = $recent['user']; 79999c8d7f2Smichael $change['version'] = $recent['date']; 80099c8d7f2Smichael $change['perms'] = $recent['perms']; 801a4da2756Smichael $change['size'] = @filesize(mediaFN($recent['id'])); 80299c8d7f2Smichael array_push($changes, $change); 80399c8d7f2Smichael } 80499c8d7f2Smichael 80599c8d7f2Smichael if (!empty($changes)) { 80699c8d7f2Smichael return $changes; 80799c8d7f2Smichael } else { 80899c8d7f2Smichael // in case we still have nothing at this point 80999c8d7f2Smichael return new IXR_Error(30, 'There are no changes in the specified timeframe'); 81099c8d7f2Smichael } 81199c8d7f2Smichael } 8123a1dad2dSDennis Ploeger 8133a1dad2dSDennis Ploeger /** 81473056168SMichael Klier * Returns a list of available revisions of a given wiki page 81573056168SMichael Klier * 81673056168SMichael Klier * @author Michael Klier <chi@chimeric.de> 81773056168SMichael Klier */ 81873056168SMichael Klier function pageVersions($id, $first) { 81973056168SMichael Klier global $conf; 82073056168SMichael Klier 82173056168SMichael Klier $versions = array(); 82273056168SMichael Klier 82373056168SMichael Klier if(empty($id)) 82473056168SMichael Klier return new IXR_Error(1, 'Empty page ID'); 82573056168SMichael Klier 82673056168SMichael Klier $revisions = getRevisions($id, $first, $conf['recent']+1); 82773056168SMichael Klier 82873056168SMichael Klier if(count($revisions)==0 && $first!=0) { 82973056168SMichael Klier $first=0; 83073056168SMichael Klier $revisions = getRevisions($id, $first, $conf['recent']+1); 83173056168SMichael Klier } 83273056168SMichael Klier 83345c63471SMichael Klier if(count($revisions)>0 && $first==0) { 83445c63471SMichael Klier array_unshift($revisions, ''); // include current revision 83545c63471SMichael Klier array_pop($revisions); // remove extra log entry 83645c63471SMichael Klier } 83745c63471SMichael Klier 83873056168SMichael Klier $hasNext = false; 83973056168SMichael Klier if(count($revisions)>$conf['recent']) { 84073056168SMichael Klier $hasNext = true; 84173056168SMichael Klier array_pop($revisions); // remove extra log entry 84273056168SMichael Klier } 84373056168SMichael Klier 84473056168SMichael Klier if(!empty($revisions)) { 84573056168SMichael Klier foreach($revisions as $rev) { 84673056168SMichael Klier $file = wikiFN($id,$rev); 84773056168SMichael Klier $time = @filemtime($file); 84845c63471SMichael Klier // we check if the page actually exists, if this is not the 84945c63471SMichael Klier // case this can lead to less pages being returned than 85045c63471SMichael Klier // specified via $conf['recent'] 85173056168SMichael Klier if($time){ 85273056168SMichael Klier $info = getRevisionInfo($id, $time, 1024); 85373056168SMichael Klier if(!empty($info)) { 85473056168SMichael Klier $data['user'] = $info['user']; 85573056168SMichael Klier $data['ip'] = $info['ip']; 85673056168SMichael Klier $data['type'] = $info['type']; 85773056168SMichael Klier $data['sum'] = $info['sum']; 85873056168SMichael Klier $data['modified'] = new IXR_Date($info['date']); 85973056168SMichael Klier $data['version'] = $info['date']; 86073056168SMichael Klier array_push($versions, $data); 86173056168SMichael Klier } 86273056168SMichael Klier } 86373056168SMichael Klier } 86473056168SMichael Klier return $versions; 86573056168SMichael Klier } else { 86673056168SMichael Klier return array(); 86773056168SMichael Klier } 86873056168SMichael Klier } 86973056168SMichael Klier 87073056168SMichael Klier /** 871797c0d11SAndreas Gohr * The version of Wiki RPC API supported 872797c0d11SAndreas Gohr */ 873797c0d11SAndreas Gohr function wiki_RPCVersion(){ 874797c0d11SAndreas Gohr return 2; 875797c0d11SAndreas Gohr } 8761b11c097SAndreas Gohr 87728ec3c76SAndreas Gohr 87828ec3c76SAndreas Gohr /** 87928ec3c76SAndreas Gohr * Locks or unlocks a given batch of pages 88028ec3c76SAndreas Gohr * 88128ec3c76SAndreas Gohr * Give an associative array with two keys: lock and unlock. Both should contain a 88228ec3c76SAndreas Gohr * list of pages to lock or unlock 88328ec3c76SAndreas Gohr * 88428ec3c76SAndreas Gohr * Returns an associative array with the keys locked, lockfail, unlocked and 88528ec3c76SAndreas Gohr * unlockfail, each containing lists of pages. 88628ec3c76SAndreas Gohr */ 88728ec3c76SAndreas Gohr function setLocks($set){ 88828ec3c76SAndreas Gohr $locked = array(); 88928ec3c76SAndreas Gohr $lockfail = array(); 89028ec3c76SAndreas Gohr $unlocked = array(); 89128ec3c76SAndreas Gohr $unlockfail = array(); 89228ec3c76SAndreas Gohr 89328ec3c76SAndreas Gohr foreach((array) $set['lock'] as $id){ 89428ec3c76SAndreas Gohr if(checklock($id)){ 89528ec3c76SAndreas Gohr $lockfail[] = $id; 89628ec3c76SAndreas Gohr }else{ 89728ec3c76SAndreas Gohr lock($id); 89828ec3c76SAndreas Gohr $locked[] = $id; 89928ec3c76SAndreas Gohr } 90028ec3c76SAndreas Gohr } 90128ec3c76SAndreas Gohr 90228ec3c76SAndreas Gohr foreach((array) $set['unlock'] as $id){ 90328ec3c76SAndreas Gohr if(unlock($id)){ 90428ec3c76SAndreas Gohr $unlocked[] = $id; 90528ec3c76SAndreas Gohr }else{ 90628ec3c76SAndreas Gohr $unlockfail[] = $id; 90728ec3c76SAndreas Gohr } 90828ec3c76SAndreas Gohr } 90928ec3c76SAndreas Gohr 91028ec3c76SAndreas Gohr return array( 91128ec3c76SAndreas Gohr 'locked' => $locked, 91228ec3c76SAndreas Gohr 'lockfail' => $lockfail, 91328ec3c76SAndreas Gohr 'unlocked' => $unlocked, 91428ec3c76SAndreas Gohr 'unlockfail' => $unlockfail, 91528ec3c76SAndreas Gohr ); 91628ec3c76SAndreas Gohr } 91728ec3c76SAndreas Gohr 918445e8084SAndreas Gohr function getAPIVersion(){ 919445e8084SAndreas Gohr return DOKU_XMLRPC_API_VERSION; 920445e8084SAndreas Gohr } 921445e8084SAndreas Gohr 922445e8084SAndreas Gohr function login($user,$pass){ 923445e8084SAndreas Gohr global $conf; 924445e8084SAndreas Gohr global $auth; 925445e8084SAndreas Gohr if(!$conf['useacl']) return 0; 926445e8084SAndreas Gohr if(!$auth) return 0; 927445e8084SAndreas Gohr if($auth->canDo('external')){ 928445e8084SAndreas Gohr return $auth->trustExternal($user,$pass,false); 929445e8084SAndreas Gohr }else{ 930445e8084SAndreas Gohr return auth_login($user,$pass,false,true); 931445e8084SAndreas Gohr } 932445e8084SAndreas Gohr } 9333ee5b583SAndreas Gohr 9343ee5b583SAndreas Gohr 935797c0d11SAndreas Gohr} 936797c0d11SAndreas Gohr 937797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server(); 938797c0d11SAndreas Gohr 9392aca132fSMichael Klier// vim:ts=4:sw=4:et:enc=utf-8: 940