xref: /dokuwiki/lib/exe/xmlrpc.php (revision 9a3b7d9f166ec2227b91614228c308f50d3e259f)
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//EXPERIMENTAL CODE
9die('remove me to get it work');
10
11require_once(DOKU_INC.'inc/init.php');
12require_once(DOKU_INC.'inc/common.php');
13require_once(DOKU_INC.'inc/auth.php');
14session_write_close();  //close session
15require_once(DOKU_INC.'inc/IXR_Library.php');
16
17
18
19/**
20 * Contains needed wrapper functions and registers all available
21 * XMLRPC functions.
22 */
23class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer {
24    var $methods = array();
25
26    /**
27     * Constructor. Register methods and run Server
28     */
29    function dokuwiki_xmlrpc_server(){
30        $this->IXR_IntrospectionServer();
31
32        /* DokuWiki's own methods */
33        $this->addCallback(
34            'dokuwiki.getVersion',
35            'getVersion',
36            array('string'),
37            'Returns the running DokuWiki version'
38        );
39
40        /* Wiki API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 */
41        $this->addCallback(
42            'wiki.getRPCVersionSupported',
43            'this:wiki_RPCVersion',
44            array('int'),
45            'Returns 2 with the supported RPC API version'
46        );
47        $this->addCallback(
48            'wiki.getPage',
49            'this:rawPage',
50            array('string','string'),
51            'Get the raw Wiki text of page, latest version.'
52        );
53        $this->addCallback(
54            'wiki.getPageVersion',
55            'this:rawPage',
56            array('string','string','int'),
57            'Get the raw Wiki text of page.'
58        );
59        $this->addCallback(
60            'wiki.getPageHTML',
61            'this:htmlPage',
62            array('string','string'),
63            'Return page in rendered HTML, latest version.'
64        );
65        $this->addCallback(
66            'wiki.getPageHTMLVersion',
67            'this:htmlPage',
68            array('string','string','int'),
69            'Return page in rendered HTML.'
70        );
71        $this->addCallback(
72            'wiki.getAllPages',
73            'this:listPages',
74            array('struct'),
75            'Returns a list of all pages. The result is an array of utf8 pagenames.'
76        );
77        $this->addCallback(
78            'wiki.getBackLinks',
79            'this:listBackLinks',
80            array('struct','string'),
81            'Returns the pages that link to this page.'
82        );
83        $this->addCallback(
84            'wiki.getPageInfo',
85            'this:pageInfo',
86            array('struct','string'),
87            'Returns a struct with infos about the page.'
88        );
89        $this->addCallback(
90            'wiki.getPageInfoVersion',
91            'this:pageInfo',
92            array('struct','string','int'),
93            'Returns a struct with infos about the page.'
94        );
95        $this->addCallback(
96            'wiki.putPage',
97            'this:putPage',
98            array('int', 'string', 'string'),
99            'Saves a wiki page'
100        );
101        $this->addCallback(
102            'wiki.listLinks',
103            'this:listLinks',
104            array('struct','string'),
105            'Lists all links contained in a wiki page'
106        );
107/*
108  FIXME: missing, yet
109            'wiki.getRecentChanges'
110*/
111
112        $this->serve();
113    }
114
115    /**
116     * Return a raw wiki page
117     */
118    function rawPage($id,$rev=''){
119        if(auth_quickaclcheck($id) < AUTH_READ){
120            return new IXR_Error(1, 'You are not allowed to read this page');
121        }
122        return rawWiki($id,$rev);
123    }
124
125    /**
126     * Return a wiki page rendered to html
127     */
128    function htmlPage($id,$rev=''){
129        if(auth_quickaclcheck($id) < AUTH_READ){
130            return new IXR_Error(1, 'You are not allowed to read this page');
131        }
132        return p_wiki_xhtml($id,$rev,false);
133    }
134
135    /**
136     * List all pages - we use the indexer list here
137     */
138    function listPages(){
139        require_once(DOKU_INC.'inc/fulltext.php');
140        return ft_pageLookup('');
141    }
142
143
144    /**
145     * Return a list of backlinks
146     */
147    function listBackLinks($id){
148        require_once(DOKU_INC.'inc/fulltext.php');
149        return ft_backlinks($id);
150    }
151
152    /**
153     * return some basic data about a page
154     */
155    function pageInfo($id,$rev=''){
156        if(auth_quickaclcheck($id) < AUTH_READ){
157            return new IXR_Error(1, 'You are not allowed to read this page');
158        }
159        $file = wikiFN($id,$rev);
160        $time = @filemtime($file);
161        if(!$time){
162            return new IXR_Error(10, 'The requested page does not exist');
163        }
164
165        $info = getRevisionInfo($id, $time, 1024);
166
167        $data = array(
168            'name'         => $id,
169            'lastModified' => new IXR_Date($time),
170            'author'       => (($info['user']) ? $info['user'] : $info['ip']),
171            'version'      => $time
172        );
173        return $data;
174    }
175
176    /**
177     * Save a wiki page
178     */
179    function putPage($put_id, $put_text, $put_summary='', $put_minor=0, $put_rev='', $put_pre='', $put_suf='') {
180        global $TEXT;
181
182        $TEXT = $put_text;
183
184        // Check, if page is locked
185        if (checklock($put_id) !== false)
186            return 1;
187
188        //spam check
189        if(checkwordblock())
190            return 2;
191
192        lock($put_id);
193
194        saveWikiText($put_id,con($put_pre,$put_text,$put_suf,1),$put_summary,$put_minor);
195
196        unlock($put_id);
197
198        return 0;
199    }
200
201    /**
202     * Lists all links contained in a wiki page
203     */
204    function listLinks($id) {
205        if(auth_quickaclcheck($id) < AUTH_READ){
206            return new IXR_Error(1, 'You are not allowed to read this page');
207        }
208        $links = array();
209
210        // resolve page instructions
211        $ins   = p_cached_instructions(wikiFN(cleanID($id)));
212
213        // instantiate new Renderer - needed for interwiki links
214        include(DOKU_INC.'inc/parser/xhtml.php');
215        $Renderer = new Doku_Renderer_xhtml();
216        $Renderer->interwiki = getInterwiki();
217
218        // parse parse instructions
219        foreach($ins as $in) {
220            $link = array();
221            switch($in[0]) {
222                case 'internallink':
223                    $link['type'] = 'local';
224                    $link['page'] = $in[1][0];
225                    $link['href'] = wl($in[1][0]);
226                    array_push($links,$link);
227                    break;
228                case 'externallink':
229                    $link['type'] = 'extern';
230                    $link['page'] = $in[1][0];
231                    $link['href'] = $in[1][0];
232                    array_push($links,$link);
233                    break;
234                case 'interwikilink':
235                    $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]);
236                    $link['type'] = 'extern';
237                    $link['page'] = $url;
238                    $link['href'] = $url;
239                    array_push($links,$link);
240                    break;
241            }
242        }
243
244        return $links;
245    }
246
247    /**
248     * The version of Wiki RPC API supported
249     */
250    function wiki_RPCVersion(){
251        return 2;
252    }
253
254}
255
256$server = new dokuwiki_xmlrpc_server();
257
258