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