xref: /dokuwiki/lib/exe/xmlrpc.php (revision b760af946cf29d1bee05a5cb33cfc6e357df441f)
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 */
10ba9418bcSHakan Sandelldefine('DOKU_XMLRPC_API_VERSION',5);
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
33992ded5aSAndreas Gohr        if(trim($conf['xmlrpcuser']) == '') return true; //no restrictions
343ee5b583SAndreas Gohr
35992ded5aSAndreas Gohr        return auth_isMember($conf['xmlrpcuser'],$_SERVER['REMOTE_USER'],(array) $USERINFO['grps']);
363ee5b583SAndreas Gohr    }
373ee5b583SAndreas Gohr
383ee5b583SAndreas Gohr    /**
393ee5b583SAndreas Gohr     * Adds a callback, extends parent method
403ee5b583SAndreas Gohr     *
413ee5b583SAndreas Gohr     * add another parameter to define if anonymous access to
423ee5b583SAndreas Gohr     * this method should be granted.
433ee5b583SAndreas Gohr     */
443ee5b583SAndreas Gohr    function addCallback($method, $callback, $args, $help, $public=false){
453ee5b583SAndreas Gohr        if($public) $this->public_methods[] = $method;
463ee5b583SAndreas Gohr        return parent::addCallback($method, $callback, $args, $help);
473ee5b583SAndreas Gohr    }
483ee5b583SAndreas Gohr
493ee5b583SAndreas Gohr    /**
503ee5b583SAndreas Gohr     * Execute a call, extends parent method
513ee5b583SAndreas Gohr     *
523ee5b583SAndreas Gohr     * Checks for authentication first
533ee5b583SAndreas Gohr     */
543ee5b583SAndreas Gohr    function call($methodname, $args){
553ee5b583SAndreas Gohr        if(!in_array($methodname,$this->public_methods) && !$this->checkAuth()){
56*b760af94SMichael Hamann            header('HTTP/1.1 401 Unauthorized');
573ee5b583SAndreas Gohr            return new IXR_Error(-32603, 'server error. not authorized to call method "'.$methodname.'".');
583ee5b583SAndreas Gohr        }
593ee5b583SAndreas Gohr        return parent::call($methodname, $args);
603ee5b583SAndreas Gohr    }
61797c0d11SAndreas Gohr
62797c0d11SAndreas Gohr    /**
63797c0d11SAndreas Gohr     * Constructor. Register methods and run Server
64797c0d11SAndreas Gohr     */
65797c0d11SAndreas Gohr    function dokuwiki_xmlrpc_server(){
66797c0d11SAndreas Gohr        $this->IXR_IntrospectionServer();
67797c0d11SAndreas Gohr
68797c0d11SAndreas Gohr        /* DokuWiki's own methods */
69797c0d11SAndreas Gohr        $this->addCallback(
70445e8084SAndreas Gohr            'dokuwiki.getXMLRPCAPIVersion',
71445e8084SAndreas Gohr            'this:getAPIVersion',
72445e8084SAndreas Gohr            array('integer'),
733ee5b583SAndreas Gohr            'Returns the XMLRPC API version.',
743ee5b583SAndreas Gohr            true
75445e8084SAndreas Gohr        );
76445e8084SAndreas Gohr
77445e8084SAndreas Gohr        $this->addCallback(
78797c0d11SAndreas Gohr            'dokuwiki.getVersion',
79797c0d11SAndreas Gohr            'getVersion',
80797c0d11SAndreas Gohr            array('string'),
813ee5b583SAndreas Gohr            'Returns the running DokuWiki version.',
823ee5b583SAndreas Gohr            true
83797c0d11SAndreas Gohr        );
84797c0d11SAndreas Gohr
851b11c097SAndreas Gohr        $this->addCallback(
86445e8084SAndreas Gohr            'dokuwiki.login',
87445e8084SAndreas Gohr            'this:login',
88445e8084SAndreas Gohr            array('integer','string','string'),
893ee5b583SAndreas Gohr            'Tries to login with the given credentials and sets auth cookies.',
903ee5b583SAndreas Gohr            true
91445e8084SAndreas Gohr        );
92445e8084SAndreas Gohr
93445e8084SAndreas Gohr        $this->addCallback(
941b11c097SAndreas Gohr            'dokuwiki.getPagelist',
951b11c097SAndreas Gohr            'this:readNamespace',
961b11c097SAndreas Gohr            array('struct','string','struct'),
971b11c097SAndreas Gohr            'List all pages within the given namespace.'
981b11c097SAndreas Gohr        );
991b11c097SAndreas Gohr
1001b11c097SAndreas Gohr        $this->addCallback(
101f71f4f53SAndreas Gohr            'dokuwiki.search',
102f71f4f53SAndreas Gohr            'this:search',
103f71f4f53SAndreas Gohr            array('struct','string'),
104f71f4f53SAndreas Gohr            'Perform a fulltext search and return a list of matching pages'
105f71f4f53SAndreas Gohr        );
106f71f4f53SAndreas Gohr
107f71f4f53SAndreas Gohr        $this->addCallback(
1081b11c097SAndreas Gohr            'dokuwiki.getTime',
1091b11c097SAndreas Gohr            'time',
1101b11c097SAndreas Gohr            array('int'),
1111b11c097SAndreas Gohr            'Return the current time at the wiki server.'
1121b11c097SAndreas Gohr        );
1131b11c097SAndreas Gohr
11428ec3c76SAndreas Gohr        $this->addCallback(
11528ec3c76SAndreas Gohr            'dokuwiki.setLocks',
11628ec3c76SAndreas Gohr            'this:setLocks',
11728ec3c76SAndreas Gohr            array('struct','struct'),
11828ec3c76SAndreas Gohr            'Lock or unlock pages.'
11928ec3c76SAndreas Gohr        );
12028ec3c76SAndreas Gohr
121e6f4c9d4SGeorges-Etienne Legendre
122e6f4c9d4SGeorges-Etienne Legendre        $this->addCallback(
123e6f4c9d4SGeorges-Etienne Legendre            'dokuwiki.getTitle',
124e6f4c9d4SGeorges-Etienne Legendre            'this:getTitle',
125e6f4c9d4SGeorges-Etienne Legendre            array('string'),
126e6f4c9d4SGeorges-Etienne Legendre            'Returns the wiki title.',
127e6f4c9d4SGeorges-Etienne Legendre            true
128e6f4c9d4SGeorges-Etienne Legendre        );
129e6f4c9d4SGeorges-Etienne Legendre
130ba9418bcSHakan Sandell        $this->addCallback(
131ba9418bcSHakan Sandell            'dokuwiki.appendPage',
132ba9418bcSHakan Sandell            'this:appendPage',
133ba9418bcSHakan Sandell            array('int', 'string', 'string', 'struct'),
134ba9418bcSHakan Sandell            'Append text to a wiki page.'
135ba9418bcSHakan Sandell        );
136ba9418bcSHakan Sandell
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=''){
283eff795acSMichael Hamann        $id = cleanID($id);
284797c0d11SAndreas Gohr        if(auth_quickaclcheck($id) < AUTH_READ){
285797c0d11SAndreas Gohr            return new IXR_Error(1, 'You are not allowed to read this page');
286797c0d11SAndreas Gohr        }
2872c176304SMichael Klier        $text = rawWiki($id,$rev);
2882c176304SMichael Klier        if(!$text) {
289fe17917eSAdrian Lang            return pageTemplate($id);
2902c176304SMichael Klier        } else {
2912c176304SMichael Klier            return $text;
2922c176304SMichael Klier        }
293797c0d11SAndreas Gohr    }
294797c0d11SAndreas Gohr
295797c0d11SAndreas Gohr    /**
296cfef3001SGina Haeussge     * Return a media file encoded in base64
297c63d1645SGina Haeussge     *
298c63d1645SGina Haeussge     * @author Gina Haeussge <osd@foosel.net>
299cfef3001SGina Haeussge     */
300cfef3001SGina Haeussge    function getAttachment($id){
301c63d1645SGina Haeussge        $id = cleanID($id);
302cfef3001SGina Haeussge        if (auth_quickaclcheck(getNS($id).':*') < AUTH_READ)
303cfef3001SGina Haeussge            return new IXR_Error(1, 'You are not allowed to read this file');
304cfef3001SGina Haeussge
305cfef3001SGina Haeussge        $file = mediaFN($id);
306cfef3001SGina Haeussge        if (!@ file_exists($file))
307cfef3001SGina Haeussge            return new IXR_Error(1, 'The requested file does not exist');
308cfef3001SGina Haeussge
309cfef3001SGina Haeussge        $data = io_readFile($file, false);
310cfef3001SGina Haeussge        $base64 = base64_encode($data);
311cfef3001SGina Haeussge        return $base64;
312cfef3001SGina Haeussge    }
313cfef3001SGina Haeussge
314cfef3001SGina Haeussge    /**
3155672e868SGina Haeussge     * Return info about a media file
3165672e868SGina Haeussge     *
3175672e868SGina Haeussge     * @author Gina Haeussge <osd@foosel.net>
3185672e868SGina Haeussge     */
3195672e868SGina Haeussge    function getAttachmentInfo($id){
3205672e868SGina Haeussge        $id = cleanID($id);
3215672e868SGina Haeussge        $info = array(
3225672e868SGina Haeussge            'lastModified' => 0,
3235672e868SGina Haeussge            'size' => 0,
3245672e868SGina Haeussge        );
3255672e868SGina Haeussge
3265672e868SGina Haeussge        $file = mediaFN($id);
3275672e868SGina Haeussge        if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){
3285672e868SGina Haeussge            $info['lastModified'] = new IXR_Date(filemtime($file));
3295672e868SGina Haeussge            $info['size'] = filesize($file);
3305672e868SGina Haeussge        }
3315672e868SGina Haeussge
3325672e868SGina Haeussge        return $info;
3335672e868SGina Haeussge    }
3345672e868SGina Haeussge
3355672e868SGina Haeussge    /**
336797c0d11SAndreas Gohr     * Return a wiki page rendered to html
337797c0d11SAndreas Gohr     */
338797c0d11SAndreas Gohr    function htmlPage($id,$rev=''){
339eff795acSMichael Hamann        $id = cleanID($id);
340797c0d11SAndreas Gohr        if(auth_quickaclcheck($id) < AUTH_READ){
341797c0d11SAndreas Gohr            return new IXR_Error(1, 'You are not allowed to read this page');
342797c0d11SAndreas Gohr        }
343797c0d11SAndreas Gohr        return p_wiki_xhtml($id,$rev,false);
344797c0d11SAndreas Gohr    }
345797c0d11SAndreas Gohr
346797c0d11SAndreas Gohr    /**
347797c0d11SAndreas Gohr     * List all pages - we use the indexer list here
348797c0d11SAndreas Gohr     */
349797c0d11SAndreas Gohr    function listPages(){
350dfd13e55SMichael Klier        $list  = array();
3519b41be24STom N Harris        $pages = idx_get_indexer()->getPages();
3529b41be24STom N Harris        $pages = array_filter(array_filter($pages,'isVisiblePage'),'page_exists');
353dfd13e55SMichael Klier
354dfd13e55SMichael Klier        foreach(array_keys($pages) as $idx) {
355dfd13e55SMichael Klier            $perm = auth_quickaclcheck($pages[$idx]);
356a0070b52SAdrian Lang            if($perm < AUTH_READ) {
357a0070b52SAdrian Lang                continue;
358a0070b52SAdrian Lang            }
359dfd13e55SMichael Klier            $page = array();
360dfd13e55SMichael Klier            $page['id'] = trim($pages[$idx]);
361dfd13e55SMichael Klier            $page['perms'] = $perm;
362dfd13e55SMichael Klier            $page['size'] = @filesize(wikiFN($pages[$idx]));
363e070c6f3SGina Haeussge            $page['lastModified'] = new IXR_Date(@filemtime(wikiFN($pages[$idx])));
364dfd13e55SMichael Klier            $list[] = $page;
365dfd13e55SMichael Klier        }
366dfd13e55SMichael Klier
367dfd13e55SMichael Klier        return $list;
368797c0d11SAndreas Gohr    }
369797c0d11SAndreas Gohr
370797c0d11SAndreas Gohr    /**
3711b11c097SAndreas Gohr     * List all pages in the given namespace (and below)
3721b11c097SAndreas Gohr     */
3731b11c097SAndreas Gohr    function readNamespace($ns,$opts){
3741b11c097SAndreas Gohr        global $conf;
3751b11c097SAndreas Gohr
3761b11c097SAndreas Gohr        if(!is_array($opts)) $opts=array();
3771b11c097SAndreas Gohr
3781b11c097SAndreas Gohr        $ns = cleanID($ns);
3791b11c097SAndreas Gohr        $dir = utf8_encodeFN(str_replace(':', '/', $ns));
3801b11c097SAndreas Gohr        $data = array();
3816fc3aa1aSAndreas Gohr        $opts['skipacl'] = 0; // no ACL skipping for XMLRPC
3821b11c097SAndreas Gohr        search($data, $conf['datadir'], 'search_allpages', $opts, $dir);
3831b11c097SAndreas Gohr        return $data;
3841b11c097SAndreas Gohr    }
3851b11c097SAndreas Gohr
3861b11c097SAndreas Gohr    /**
387f71f4f53SAndreas Gohr     * List all pages in the given namespace (and below)
388f71f4f53SAndreas Gohr     */
389f71f4f53SAndreas Gohr    function search($query){
390f71f4f53SAndreas Gohr        require_once(DOKU_INC.'inc/fulltext.php');
391f71f4f53SAndreas Gohr
392f71f4f53SAndreas Gohr        $regex = '';
393f71f4f53SAndreas Gohr        $data  = ft_pageSearch($query,$regex);
394f71f4f53SAndreas Gohr        $pages = array();
395f71f4f53SAndreas Gohr
396f71f4f53SAndreas Gohr        // prepare additional data
397f71f4f53SAndreas Gohr        $idx = 0;
398f71f4f53SAndreas Gohr        foreach($data as $id => $score){
399f71f4f53SAndreas Gohr            $file = wikiFN($id);
400f71f4f53SAndreas Gohr
401f71f4f53SAndreas Gohr            if($idx < FT_SNIPPET_NUMBER){
402f71f4f53SAndreas Gohr                $snippet = ft_snippet($id,$regex);
403f71f4f53SAndreas Gohr                $idx++;
404f71f4f53SAndreas Gohr            }else{
405f71f4f53SAndreas Gohr                $snippet = '';
406f71f4f53SAndreas Gohr            }
407f71f4f53SAndreas Gohr
408f71f4f53SAndreas Gohr            $pages[] = array(
409f71f4f53SAndreas Gohr                'id'      => $id,
410f71f4f53SAndreas Gohr                'score'   => $score,
411f71f4f53SAndreas Gohr                'rev'     => filemtime($file),
412f71f4f53SAndreas Gohr                'mtime'   => filemtime($file),
413f71f4f53SAndreas Gohr                'size'    => filesize($file),
414f71f4f53SAndreas Gohr                'snippet' => $snippet,
415f71f4f53SAndreas Gohr            );
416f71f4f53SAndreas Gohr        }
417ac1ffddeSGeorges-Etienne Legendre        return $pages;
418f71f4f53SAndreas Gohr    }
419f71f4f53SAndreas Gohr
420e6f4c9d4SGeorges-Etienne Legendre    /**
421e6f4c9d4SGeorges-Etienne Legendre     * Returns the wiki title.
422e6f4c9d4SGeorges-Etienne Legendre     */
423e6f4c9d4SGeorges-Etienne Legendre    function getTitle(){
424e6f4c9d4SGeorges-Etienne Legendre        global $conf;
425e6f4c9d4SGeorges-Etienne Legendre        return $conf['title'];
426e6f4c9d4SGeorges-Etienne Legendre    }
427f71f4f53SAndreas Gohr
428f71f4f53SAndreas Gohr    /**
42926bec61eSMichael Klier     * List all media files.
4303275953aSGina Haeussge     *
4313275953aSGina Haeussge     * Available options are 'recursive' for also including the subnamespaces
4323275953aSGina Haeussge     * in the listing, and 'pattern' for filtering the returned files against
4333275953aSGina Haeussge     * a regular expression matching their name.
4343275953aSGina Haeussge     *
4353275953aSGina Haeussge     * @author Gina Haeussge <osd@foosel.net>
43626bec61eSMichael Klier     */
4373275953aSGina Haeussge    function listAttachments($ns, $options = array()) {
43826bec61eSMichael Klier        global $conf;
43926bec61eSMichael Klier        global $lang;
44026bec61eSMichael Klier
44126bec61eSMichael Klier        $ns = cleanID($ns);
44226bec61eSMichael Klier
4436fc3aa1aSAndreas Gohr        if (!is_array($options)) $options = array();
4446fc3aa1aSAndreas Gohr        $options['skipacl'] = 0; // no ACL skipping for XMLRPC
4453275953aSGina Haeussge
4463275953aSGina Haeussge
44726bec61eSMichael Klier        if(auth_quickaclcheck($ns.':*') >= AUTH_READ) {
44826bec61eSMichael Klier            $dir = utf8_encodeFN(str_replace(':', '/', $ns));
44926bec61eSMichael Klier
45026bec61eSMichael Klier            $data = array();
451224122cfSAndreas Gohr            search($data, $conf['mediadir'], 'search_media', $options, $dir);
452224122cfSAndreas Gohr            $len = count($data);
453224122cfSAndreas Gohr            if(!$len) return array();
45426bec61eSMichael Klier
455224122cfSAndreas Gohr            for($i=0; $i<$len; $i++) {
456224122cfSAndreas Gohr                unset($data[$i]['meta']);
457224122cfSAndreas Gohr                $data[$i]['lastModified'] = new IXR_Date($data[$i]['mtime']);
45826bec61eSMichael Klier            }
459224122cfSAndreas Gohr            return $data;
46026bec61eSMichael Klier        } else {
46126bec61eSMichael Klier            return new IXR_Error(1, 'You are not allowed to list media files.');
46226bec61eSMichael Klier        }
46326bec61eSMichael Klier    }
46426bec61eSMichael Klier
46526bec61eSMichael Klier    /**
466797c0d11SAndreas Gohr     * Return a list of backlinks
467797c0d11SAndreas Gohr     */
468beccd742SMichael Klier    function listBackLinks($id){
46986228f10SDominik Eckelmann        return ft_backlinks(cleanID($id));
470797c0d11SAndreas Gohr    }
471797c0d11SAndreas Gohr
472797c0d11SAndreas Gohr    /**
47363dd0d58SMichael Klier     * Return some basic data about a page
474797c0d11SAndreas Gohr     */
475797c0d11SAndreas Gohr    function pageInfo($id,$rev=''){
476eff795acSMichael Hamann        $id = cleanID($id);
477797c0d11SAndreas Gohr        if(auth_quickaclcheck($id) < AUTH_READ){
478797c0d11SAndreas Gohr            return new IXR_Error(1, 'You are not allowed to read this page');
479797c0d11SAndreas Gohr        }
480797c0d11SAndreas Gohr        $file = wikiFN($id,$rev);
481797c0d11SAndreas Gohr        $time = @filemtime($file);
482797c0d11SAndreas Gohr        if(!$time){
483797c0d11SAndreas Gohr            return new IXR_Error(10, 'The requested page does not exist');
484797c0d11SAndreas Gohr        }
485797c0d11SAndreas Gohr
486797c0d11SAndreas Gohr        $info = getRevisionInfo($id, $time, 1024);
487797c0d11SAndreas Gohr
488797c0d11SAndreas Gohr        $data = array(
489797c0d11SAndreas Gohr            'name'         => $id,
490797c0d11SAndreas Gohr            'lastModified' => new IXR_Date($time),
491797c0d11SAndreas Gohr            'author'       => (($info['user']) ? $info['user'] : $info['ip']),
492797c0d11SAndreas Gohr            'version'      => $time
493797c0d11SAndreas Gohr        );
49463dd0d58SMichael Klier
49563dd0d58SMichael Klier        return ($data);
496797c0d11SAndreas Gohr    }
497797c0d11SAndreas Gohr
498797c0d11SAndreas Gohr    /**
4993a1dad2dSDennis Ploeger     * Save a wiki page
500222572bfSMichael Klier     *
501222572bfSMichael Klier     * @author Michael Klier <chi@chimeric.de>
5023a1dad2dSDennis Ploeger     */
503222572bfSMichael Klier    function putPage($id, $text, $params) {
5043a1dad2dSDennis Ploeger        global $TEXT;
505a6a229ceSMichael Klier        global $lang;
506593bf8f6SMichael Klier        global $conf;
5073a1dad2dSDennis Ploeger
508222572bfSMichael Klier        $id    = cleanID($id);
50956523eecSAndreas Gohr        $TEXT  = cleanText($text);
510222572bfSMichael Klier        $sum   = $params['sum'];
511222572bfSMichael Klier        $minor = $params['minor'];
512222572bfSMichael Klier
513222572bfSMichael Klier        if(empty($id))
514fdd2e9d6SMichael Klier            return new IXR_Error(1, 'Empty page ID');
515222572bfSMichael Klier
51656523eecSAndreas Gohr        if(!page_exists($id) && trim($TEXT) == '' ) {
51751597811SMichael Klier            return new IXR_ERROR(1, 'Refusing to write an empty new wiki page');
51851597811SMichael Klier        }
51951597811SMichael Klier
520055b0144SChris Smith        if(auth_quickaclcheck($id) < AUTH_EDIT)
521222572bfSMichael Klier            return new IXR_Error(1, 'You are not allowed to edit this page');
5223a1dad2dSDennis Ploeger
5233a1dad2dSDennis Ploeger        // Check, if page is locked
524222572bfSMichael Klier        if(checklock($id))
525222572bfSMichael Klier            return new IXR_Error(1, 'The page is currently locked');
526222572bfSMichael Klier
527a6a229ceSMichael Klier        // SPAM check
5283a1dad2dSDennis Ploeger        if(checkwordblock())
529222572bfSMichael Klier            return new IXR_Error(1, 'Positive wordblock check');
5303a1dad2dSDennis Ploeger
531a6a229ceSMichael Klier        // autoset summary on new pages
532a6a229ceSMichael Klier        if(!page_exists($id) && empty($sum)) {
533a6a229ceSMichael Klier            $sum = $lang['created'];
534a6a229ceSMichael Klier        }
535a6a229ceSMichael Klier
536a6a229ceSMichael Klier        // autoset summary on deleted pages
537a6a229ceSMichael Klier        if(page_exists($id) && empty($TEXT) && empty($sum)) {
538a6a229ceSMichael Klier            $sum = $lang['deleted'];
539a6a229ceSMichael Klier        }
540a6a229ceSMichael Klier
541222572bfSMichael Klier        lock($id);
5423a1dad2dSDennis Ploeger
543222572bfSMichael Klier        saveWikiText($id,$TEXT,$sum,$minor);
5443a1dad2dSDennis Ploeger
545222572bfSMichael Klier        unlock($id);
5463a1dad2dSDennis Ploeger
547593bf8f6SMichael Klier        // run the indexer if page wasn't indexed yet
548593bf8f6SMichael Klier        idx_addPage($id);
549593bf8f6SMichael Klier
5503a1dad2dSDennis Ploeger        return 0;
551beccd742SMichael Klier    }
5523a1dad2dSDennis Ploeger
553beccd742SMichael Klier    /**
554ba9418bcSHakan Sandell     * Appends text to a wiki page.
555ba9418bcSHakan Sandell     */
556ba9418bcSHakan Sandell    function appendPage($id, $text, $params) {
557ba9418bcSHakan Sandell        $currentpage = $this->rawPage($id);
558ba9418bcSHakan Sandell        if (!is_string($currentpage)) {
559ba9418bcSHakan Sandell            return $currentpage;
560ba9418bcSHakan Sandell        }
561ba9418bcSHakan Sandell        return $this->putPage($id, $currentpage.$text, $params);
562ba9418bcSHakan Sandell    }
563ba9418bcSHakan Sandell
564ba9418bcSHakan Sandell    /**
5652aca132fSMichael Klier     * Uploads a file to the wiki.
5662aca132fSMichael Klier     *
5672aca132fSMichael Klier     * Michael Klier <chi@chimeric.de>
5682aca132fSMichael Klier     */
569f01ff8c1SGina Haeussge    function putAttachment($id, $file, $params) {
570eff795acSMichael Hamann        $id = cleanID($id);
571f01ff8c1SGina Haeussge        $auth = auth_quickaclcheck(getNS($id).':*');
572ffb291f2SAdrian Lang
573f01ff8c1SGina Haeussge        if(!isset($id)) {
5742aca132fSMichael Klier            return new IXR_ERROR(1, 'Filename not given.');
5752aca132fSMichael Klier        }
5762aca132fSMichael Klier
577ffb291f2SAdrian Lang        global $conf;
578ffb291f2SAdrian Lang
579c77fa67bSMichael Hamann        $ftmp = $conf['tmpdir'] . '/' . md5($id.clientIP());
5802aca132fSMichael Klier
5812aca132fSMichael Klier        // save temporary file
5822aca132fSMichael Klier        @unlink($ftmp);
5832aca132fSMichael Klier        $buff = base64_decode($file);
5842aca132fSMichael Klier        io_saveFile($ftmp, $buff);
5852aca132fSMichael Klier
586ffb291f2SAdrian Lang        $res = media_save(array('name' => $ftmp), $id, $params['ow'], $auth, 'rename');
587ffb291f2SAdrian Lang        if (is_array($res)) {
588ffb291f2SAdrian Lang            return new IXR_ERROR(-$res[1], $res[0]);
5892aca132fSMichael Klier        } else {
590ffb291f2SAdrian Lang            return $res;
5912aca132fSMichael Klier        }
5922aca132fSMichael Klier    }
5932aca132fSMichael Klier
5942aca132fSMichael Klier    /**
595f01ff8c1SGina Haeussge     * Deletes a file from the wiki.
596f01ff8c1SGina Haeussge     *
597f01ff8c1SGina Haeussge     * @author Gina Haeussge <osd@foosel.net>
598f01ff8c1SGina Haeussge     */
599f01ff8c1SGina Haeussge    function deleteAttachment($id){
600eff795acSMichael Hamann        $id = cleanID($id);
601f01ff8c1SGina Haeussge        $auth = auth_quickaclcheck(getNS($id).':*');
60287229c84SAdrian Lang        $res = media_delete($id, $auth);
60387229c84SAdrian Lang        if ($res & DOKU_MEDIA_DELETED) {
604f01ff8c1SGina Haeussge            return 0;
60587229c84SAdrian Lang        } elseif ($res & DOKU_MEDIA_NOT_AUTH) {
60687229c84SAdrian Lang            return new IXR_ERROR(1, "You don't have permissions to delete files.");
60787229c84SAdrian Lang        } elseif ($res & DOKU_MEDIA_INUSE) {
608f01ff8c1SGina Haeussge            return new IXR_ERROR(1, 'File is still referenced');
60999c8d7f2Smichael        } else {
61087229c84SAdrian Lang            return new IXR_ERROR(1, 'Could not delete file');
6112aca132fSMichael Klier        }
6122aca132fSMichael Klier    }
6132aca132fSMichael Klier
6142aca132fSMichael Klier    /**
615e62b9ea5SMichael Klier    * Returns the permissions of a given wiki page
616e62b9ea5SMichael Klier    */
617e62b9ea5SMichael Klier    function aclCheck($id) {
618eff795acSMichael Hamann        $id = cleanID($id);
619e62b9ea5SMichael Klier        return auth_quickaclcheck($id);
620e62b9ea5SMichael Klier    }
621e62b9ea5SMichael Klier
622e62b9ea5SMichael Klier    /**
623beccd742SMichael Klier     * Lists all links contained in a wiki page
62463dd0d58SMichael Klier     *
62563dd0d58SMichael Klier     * @author Michael Klier <chi@chimeric.de>
626beccd742SMichael Klier     */
627beccd742SMichael Klier    function listLinks($id) {
628eff795acSMichael Hamann        $id = cleanID($id);
629beccd742SMichael Klier        if(auth_quickaclcheck($id) < AUTH_READ){
630beccd742SMichael Klier            return new IXR_Error(1, 'You are not allowed to read this page');
631beccd742SMichael Klier        }
632beccd742SMichael Klier        $links = array();
633beccd742SMichael Klier
634beccd742SMichael Klier        // resolve page instructions
635eff795acSMichael Hamann        $ins   = p_cached_instructions(wikiFN($id));
636beccd742SMichael Klier
637beccd742SMichael Klier        // instantiate new Renderer - needed for interwiki links
638beccd742SMichael Klier        include(DOKU_INC.'inc/parser/xhtml.php');
639beccd742SMichael Klier        $Renderer = new Doku_Renderer_xhtml();
640beccd742SMichael Klier        $Renderer->interwiki = getInterwiki();
641beccd742SMichael Klier
642beccd742SMichael Klier        // parse parse instructions
643beccd742SMichael Klier        foreach($ins as $in) {
644beccd742SMichael Klier            $link = array();
645beccd742SMichael Klier            switch($in[0]) {
646beccd742SMichael Klier                case 'internallink':
647beccd742SMichael Klier                    $link['type'] = 'local';
648beccd742SMichael Klier                    $link['page'] = $in[1][0];
649beccd742SMichael Klier                    $link['href'] = wl($in[1][0]);
650beccd742SMichael Klier                    array_push($links,$link);
651beccd742SMichael Klier                    break;
652beccd742SMichael Klier                case 'externallink':
653beccd742SMichael Klier                    $link['type'] = 'extern';
654beccd742SMichael Klier                    $link['page'] = $in[1][0];
655beccd742SMichael Klier                    $link['href'] = $in[1][0];
656beccd742SMichael Klier                    array_push($links,$link);
657beccd742SMichael Klier                    break;
658beccd742SMichael Klier                case 'interwikilink':
659beccd742SMichael Klier                    $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]);
660beccd742SMichael Klier                    $link['type'] = 'extern';
661beccd742SMichael Klier                    $link['page'] = $url;
662beccd742SMichael Klier                    $link['href'] = $url;
663beccd742SMichael Klier                    array_push($links,$link);
664beccd742SMichael Klier                    break;
665beccd742SMichael Klier            }
666beccd742SMichael Klier        }
667beccd742SMichael Klier
66863dd0d58SMichael Klier        return ($links);
66963dd0d58SMichael Klier    }
67063dd0d58SMichael Klier
67163dd0d58SMichael Klier    /**
67263dd0d58SMichael Klier     * Returns a list of recent changes since give timestamp
67363dd0d58SMichael Klier     *
67499c8d7f2Smichael     * @author Michael Hamann <michael@content-space.de>
67563dd0d58SMichael Klier     * @author Michael Klier <chi@chimeric.de>
67663dd0d58SMichael Klier     */
67763dd0d58SMichael Klier    function getRecentChanges($timestamp) {
67863dd0d58SMichael Klier        if(strlen($timestamp) != 10)
67963dd0d58SMichael Klier            return new IXR_Error(20, 'The provided value is not a valid timestamp');
68063dd0d58SMichael Klier
68199c8d7f2Smichael        $recents = getRecentsSince($timestamp);
68263dd0d58SMichael Klier
68399c8d7f2Smichael        $changes = array();
68463dd0d58SMichael Klier
68599c8d7f2Smichael        foreach ($recents as $recent) {
68699c8d7f2Smichael            $change = array();
68799c8d7f2Smichael            $change['name']         = $recent['id'];
68899c8d7f2Smichael            $change['lastModified'] = new IXR_Date($recent['date']);
68999c8d7f2Smichael            $change['author']       = $recent['user'];
69099c8d7f2Smichael            $change['version']      = $recent['date'];
69199c8d7f2Smichael            $change['perms']        = $recent['perms'];
69299c8d7f2Smichael            $change['size']         = @filesize(wikiFN($recent['id']));
69363dd0d58SMichael Klier            array_push($changes, $change);
69499c8d7f2Smichael        }
69599c8d7f2Smichael
69699c8d7f2Smichael        if (!empty($changes)) {
69799c8d7f2Smichael            return $changes;
69863dd0d58SMichael Klier        } else {
69963dd0d58SMichael Klier            // in case we still have nothing at this point
70063dd0d58SMichael Klier            return new IXR_Error(30, 'There are no changes in the specified timeframe');
7013a1dad2dSDennis Ploeger        }
70299c8d7f2Smichael    }
70399c8d7f2Smichael
70499c8d7f2Smichael    /**
70599c8d7f2Smichael     * Returns a list of recent media changes since give timestamp
70699c8d7f2Smichael     *
70799c8d7f2Smichael     * @author Michael Hamann <michael@content-space.de>
70899c8d7f2Smichael     * @author Michael Klier <chi@chimeric.de>
70999c8d7f2Smichael     */
71099c8d7f2Smichael    function getRecentMediaChanges($timestamp) {
71199c8d7f2Smichael        if(strlen($timestamp) != 10)
71299c8d7f2Smichael            return new IXR_Error(20, 'The provided value is not a valid timestamp');
71399c8d7f2Smichael
71499c8d7f2Smichael        $recents = getRecentsSince($timestamp, null, '', RECENTS_MEDIA_CHANGES);
71599c8d7f2Smichael
71699c8d7f2Smichael        $changes = array();
71799c8d7f2Smichael
71899c8d7f2Smichael        foreach ($recents as $recent) {
71999c8d7f2Smichael            $change = array();
72099c8d7f2Smichael            $change['name']         = $recent['id'];
72199c8d7f2Smichael            $change['lastModified'] = new IXR_Date($recent['date']);
72299c8d7f2Smichael            $change['author']       = $recent['user'];
72399c8d7f2Smichael            $change['version']      = $recent['date'];
72499c8d7f2Smichael            $change['perms']        = $recent['perms'];
725a4da2756Smichael            $change['size']         = @filesize(mediaFN($recent['id']));
72699c8d7f2Smichael            array_push($changes, $change);
72799c8d7f2Smichael        }
72899c8d7f2Smichael
72999c8d7f2Smichael        if (!empty($changes)) {
73099c8d7f2Smichael            return $changes;
73199c8d7f2Smichael        } else {
73299c8d7f2Smichael            // in case we still have nothing at this point
73399c8d7f2Smichael            return new IXR_Error(30, 'There are no changes in the specified timeframe');
73499c8d7f2Smichael        }
73599c8d7f2Smichael    }
7363a1dad2dSDennis Ploeger
7373a1dad2dSDennis Ploeger    /**
73873056168SMichael Klier     * Returns a list of available revisions of a given wiki page
73973056168SMichael Klier     *
74073056168SMichael Klier     * @author Michael Klier <chi@chimeric.de>
74173056168SMichael Klier     */
74273056168SMichael Klier    function pageVersions($id, $first) {
743eff795acSMichael Hamann        $id = cleanID($id);
744eff795acSMichael Hamann        if(auth_quickaclcheck($id) < AUTH_READ){
745eff795acSMichael Hamann            return new IXR_Error(1, 'You are not allowed to read this page');
746eff795acSMichael Hamann        }
74773056168SMichael Klier        global $conf;
74873056168SMichael Klier
74973056168SMichael Klier        $versions = array();
75073056168SMichael Klier
75173056168SMichael Klier        if(empty($id))
75273056168SMichael Klier            return new IXR_Error(1, 'Empty page ID');
75373056168SMichael Klier
75473056168SMichael Klier        $revisions = getRevisions($id, $first, $conf['recent']+1);
75573056168SMichael Klier
75673056168SMichael Klier        if(count($revisions)==0 && $first!=0) {
75773056168SMichael Klier            $first=0;
75873056168SMichael Klier            $revisions = getRevisions($id, $first, $conf['recent']+1);
75973056168SMichael Klier        }
76073056168SMichael Klier
76145c63471SMichael Klier        if(count($revisions)>0 && $first==0) {
76245c63471SMichael Klier            array_unshift($revisions, '');  // include current revision
76345c63471SMichael Klier            array_pop($revisions);          // remove extra log entry
76445c63471SMichael Klier        }
76545c63471SMichael Klier
76673056168SMichael Klier        $hasNext = false;
76773056168SMichael Klier        if(count($revisions)>$conf['recent']) {
76873056168SMichael Klier            $hasNext = true;
76973056168SMichael Klier            array_pop($revisions); // remove extra log entry
77073056168SMichael Klier        }
77173056168SMichael Klier
77273056168SMichael Klier        if(!empty($revisions)) {
77373056168SMichael Klier            foreach($revisions as $rev) {
77473056168SMichael Klier                $file = wikiFN($id,$rev);
77573056168SMichael Klier                $time = @filemtime($file);
77645c63471SMichael Klier                // we check if the page actually exists, if this is not the
77745c63471SMichael Klier                // case this can lead to less pages being returned than
77845c63471SMichael Klier                // specified via $conf['recent']
77973056168SMichael Klier                if($time){
78073056168SMichael Klier                    $info = getRevisionInfo($id, $time, 1024);
78173056168SMichael Klier                    if(!empty($info)) {
78273056168SMichael Klier                        $data['user'] = $info['user'];
78373056168SMichael Klier                        $data['ip']   = $info['ip'];
78473056168SMichael Klier                        $data['type'] = $info['type'];
78573056168SMichael Klier                        $data['sum']  = $info['sum'];
78673056168SMichael Klier                        $data['modified'] = new IXR_Date($info['date']);
78773056168SMichael Klier                        $data['version'] = $info['date'];
78873056168SMichael Klier                        array_push($versions, $data);
78973056168SMichael Klier                    }
79073056168SMichael Klier                }
79173056168SMichael Klier            }
79273056168SMichael Klier            return $versions;
79373056168SMichael Klier        } else {
79473056168SMichael Klier            return array();
79573056168SMichael Klier        }
79673056168SMichael Klier    }
79773056168SMichael Klier
79873056168SMichael Klier    /**
799797c0d11SAndreas Gohr     * The version of Wiki RPC API supported
800797c0d11SAndreas Gohr     */
801797c0d11SAndreas Gohr    function wiki_RPCVersion(){
802797c0d11SAndreas Gohr        return 2;
803797c0d11SAndreas Gohr    }
8041b11c097SAndreas Gohr
80528ec3c76SAndreas Gohr
80628ec3c76SAndreas Gohr    /**
80728ec3c76SAndreas Gohr     * Locks or unlocks a given batch of pages
80828ec3c76SAndreas Gohr     *
80928ec3c76SAndreas Gohr     * Give an associative array with two keys: lock and unlock. Both should contain a
81028ec3c76SAndreas Gohr     * list of pages to lock or unlock
81128ec3c76SAndreas Gohr     *
81228ec3c76SAndreas Gohr     * Returns an associative array with the keys locked, lockfail, unlocked and
81328ec3c76SAndreas Gohr     * unlockfail, each containing lists of pages.
81428ec3c76SAndreas Gohr     */
81528ec3c76SAndreas Gohr    function setLocks($set){
81628ec3c76SAndreas Gohr        $locked     = array();
81728ec3c76SAndreas Gohr        $lockfail   = array();
81828ec3c76SAndreas Gohr        $unlocked   = array();
81928ec3c76SAndreas Gohr        $unlockfail = array();
82028ec3c76SAndreas Gohr
82128ec3c76SAndreas Gohr        foreach((array) $set['lock'] as $id){
822eff795acSMichael Hamann            $id = cleanID($id);
823eff795acSMichael Hamann            if(auth_quickaclcheck($id) < AUTH_EDIT || checklock($id)){
82428ec3c76SAndreas Gohr                $lockfail[] = $id;
82528ec3c76SAndreas Gohr            }else{
82628ec3c76SAndreas Gohr                lock($id);
82728ec3c76SAndreas Gohr                $locked[] = $id;
82828ec3c76SAndreas Gohr            }
82928ec3c76SAndreas Gohr        }
83028ec3c76SAndreas Gohr
83128ec3c76SAndreas Gohr        foreach((array) $set['unlock'] as $id){
832eff795acSMichael Hamann            $id = cleanID($id);
833eff795acSMichael Hamann            if(auth_quickaclcheck($id) < AUTH_EDIT || !unlock($id)){
83428ec3c76SAndreas Gohr                $unlockfail[] = $id;
835eff795acSMichael Hamann            }else{
836eff795acSMichael Hamann                $unlocked[] = $id;
83728ec3c76SAndreas Gohr            }
83828ec3c76SAndreas Gohr        }
83928ec3c76SAndreas Gohr
84028ec3c76SAndreas Gohr        return array(
84128ec3c76SAndreas Gohr            'locked'     => $locked,
84228ec3c76SAndreas Gohr            'lockfail'   => $lockfail,
84328ec3c76SAndreas Gohr            'unlocked'   => $unlocked,
84428ec3c76SAndreas Gohr            'unlockfail' => $unlockfail,
84528ec3c76SAndreas Gohr        );
84628ec3c76SAndreas Gohr    }
84728ec3c76SAndreas Gohr
848445e8084SAndreas Gohr    function getAPIVersion(){
849445e8084SAndreas Gohr        return DOKU_XMLRPC_API_VERSION;
850445e8084SAndreas Gohr    }
851445e8084SAndreas Gohr
852445e8084SAndreas Gohr    function login($user,$pass){
853445e8084SAndreas Gohr        global $conf;
854445e8084SAndreas Gohr        global $auth;
855445e8084SAndreas Gohr        if(!$conf['useacl']) return 0;
856445e8084SAndreas Gohr        if(!$auth) return 0;
857445e8084SAndreas Gohr        if($auth->canDo('external')){
858445e8084SAndreas Gohr            return $auth->trustExternal($user,$pass,false);
859445e8084SAndreas Gohr        }else{
860445e8084SAndreas Gohr            return auth_login($user,$pass,false,true);
861445e8084SAndreas Gohr        }
862445e8084SAndreas Gohr    }
8633ee5b583SAndreas Gohr
8643ee5b583SAndreas Gohr
865797c0d11SAndreas Gohr}
866797c0d11SAndreas Gohr
867797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server();
868797c0d11SAndreas Gohr
869e3776c06SMichael Hamann// vim:ts=4:sw=4:et:
870