xref: /dokuwiki/lib/exe/xmlrpc.php (revision 3a1dad2d15fb82250c76f4ff1ec789d14d38d4fc)
1797c0d11SAndreas Gohr<?php
2*3a1dad2dSDennis Ploegerif(!defined('DOKU_INC')) define('DOKU_INC',realpath(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
7797c0d11SAndreas Gohr
8797c0d11SAndreas Gohr//EXPERIMENTAL CODE
9797c0d11SAndreas Gohrdie('remove me to get it work');
10797c0d11SAndreas Gohr
11797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php');
12797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/common.php');
13797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/auth.php');
14797c0d11SAndreas Gohrsession_write_close();  //close session
15797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/IXR_Library.php');
16797c0d11SAndreas Gohr
17797c0d11SAndreas Gohr
18797c0d11SAndreas Gohr
19797c0d11SAndreas Gohr/**
20797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available
21797c0d11SAndreas Gohr * XMLRPC functions.
22797c0d11SAndreas Gohr */
23797c0d11SAndreas Gohrclass dokuwiki_xmlrpc_server extends IXR_IntrospectionServer {
24797c0d11SAndreas Gohr    var $methods = array();
25797c0d11SAndreas Gohr
26797c0d11SAndreas Gohr    /**
27797c0d11SAndreas Gohr     * Constructor. Register methods and run Server
28797c0d11SAndreas Gohr     */
29797c0d11SAndreas Gohr    function dokuwiki_xmlrpc_server(){
30797c0d11SAndreas Gohr        $this->IXR_IntrospectionServer();
31797c0d11SAndreas Gohr
32797c0d11SAndreas Gohr        /* DokuWiki's own methods */
33797c0d11SAndreas Gohr        $this->addCallback(
34797c0d11SAndreas Gohr            'dokuwiki.getVersion',
35797c0d11SAndreas Gohr            'getVersion',
36797c0d11SAndreas Gohr            array('string'),
37797c0d11SAndreas Gohr            'Returns the running DokuWiki version'
38797c0d11SAndreas Gohr        );
39797c0d11SAndreas Gohr
40797c0d11SAndreas Gohr        /* Wiki API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 */
41797c0d11SAndreas Gohr        $this->addCallback(
42797c0d11SAndreas Gohr            'wiki.getRPCVersionSupported',
43797c0d11SAndreas Gohr            'this:wiki_RPCVersion',
44797c0d11SAndreas Gohr            array('int'),
45797c0d11SAndreas Gohr            'Returns 2 with the supported RPC API version'
46797c0d11SAndreas Gohr        );
47797c0d11SAndreas Gohr        $this->addCallback(
48797c0d11SAndreas Gohr            'wiki.getPage',
49797c0d11SAndreas Gohr            'this:rawPage',
50797c0d11SAndreas Gohr            array('string','string'),
51797c0d11SAndreas Gohr            'Get the raw Wiki text of page, latest version.'
52797c0d11SAndreas Gohr        );
53797c0d11SAndreas Gohr        $this->addCallback(
54797c0d11SAndreas Gohr            'wiki.getPageVersion',
55797c0d11SAndreas Gohr            'this:rawPage',
56797c0d11SAndreas Gohr            array('string','string','int'),
57797c0d11SAndreas Gohr            'Get the raw Wiki text of page.'
58797c0d11SAndreas Gohr        );
59797c0d11SAndreas Gohr        $this->addCallback(
60797c0d11SAndreas Gohr            'wiki.getPageHTML',
61797c0d11SAndreas Gohr            'this:htmlPage',
62797c0d11SAndreas Gohr            array('string','string'),
63797c0d11SAndreas Gohr            'Return page in rendered HTML, latest version.'
64797c0d11SAndreas Gohr        );
65797c0d11SAndreas Gohr        $this->addCallback(
66797c0d11SAndreas Gohr            'wiki.getPageHTMLVersion',
67797c0d11SAndreas Gohr            'this:htmlPage',
68797c0d11SAndreas Gohr            array('string','string','int'),
69797c0d11SAndreas Gohr            'Return page in rendered HTML.'
70797c0d11SAndreas Gohr        );
71797c0d11SAndreas Gohr        $this->addCallback(
72797c0d11SAndreas Gohr            'wiki.getAllPages',
73797c0d11SAndreas Gohr            'this:listPages',
74797c0d11SAndreas Gohr            array('struct'),
75797c0d11SAndreas Gohr            'Returns a list of all pages. The result is an array of utf8 pagenames.'
76797c0d11SAndreas Gohr        );
77797c0d11SAndreas Gohr        $this->addCallback(
78797c0d11SAndreas Gohr            'wiki.getBackLinks',
79797c0d11SAndreas Gohr            'this:listBackLinks',
80797c0d11SAndreas Gohr            array('struct','string'),
81797c0d11SAndreas Gohr            'Returns the pages that link to this page.'
82797c0d11SAndreas Gohr        );
83797c0d11SAndreas Gohr        $this->addCallback(
84797c0d11SAndreas Gohr            'wiki.getPageInfo',
85797c0d11SAndreas Gohr            'this:pageInfo',
86797c0d11SAndreas Gohr            array('struct','string'),
87797c0d11SAndreas Gohr            'Returns a struct with infos about the page.'
88797c0d11SAndreas Gohr        );
89797c0d11SAndreas Gohr        $this->addCallback(
90797c0d11SAndreas Gohr            'wiki.getPageInfoVersion',
91797c0d11SAndreas Gohr            'this:pageInfo',
92797c0d11SAndreas Gohr            array('struct','string','int'),
93797c0d11SAndreas Gohr            'Returns a struct with infos about the page.'
94797c0d11SAndreas Gohr        );
95*3a1dad2dSDennis Ploeger
96*3a1dad2dSDennis Ploeger        $this->addCallback(
97*3a1dad2dSDennis Ploeger            'wiki.putPage',
98*3a1dad2dSDennis Ploeger            'this:putPage',
99*3a1dad2dSDennis Ploeger            array('int', 'string', 'string'),
100*3a1dad2dSDennis Ploeger            'Saves a wiki page'
101*3a1dad2dSDennis Ploeger        );
102797c0d11SAndreas Gohr/*
103797c0d11SAndreas Gohr  FIXME: missing, yet
104797c0d11SAndreas Gohr            'wiki.getRecentChanges'
105797c0d11SAndreas Gohr            'wiki.listLinks'
106797c0d11SAndreas Gohr*/
107797c0d11SAndreas Gohr
108797c0d11SAndreas Gohr        $this->serve();
109797c0d11SAndreas Gohr    }
110797c0d11SAndreas Gohr
111797c0d11SAndreas Gohr    /**
112797c0d11SAndreas Gohr     * Return a raw wiki page
113797c0d11SAndreas Gohr     */
114797c0d11SAndreas Gohr    function rawPage($id,$rev=''){
115797c0d11SAndreas Gohr        if(auth_quickaclcheck($id) < AUTH_READ){
116797c0d11SAndreas Gohr            return new IXR_Error(1, 'You are not allowed to read this page');
117797c0d11SAndreas Gohr        }
118797c0d11SAndreas Gohr        return rawWiki($id,$rev);
119797c0d11SAndreas Gohr    }
120797c0d11SAndreas Gohr
121797c0d11SAndreas Gohr    /**
122797c0d11SAndreas Gohr     * Return a wiki page rendered to html
123797c0d11SAndreas Gohr     */
124797c0d11SAndreas Gohr    function htmlPage($id,$rev=''){
125797c0d11SAndreas Gohr        if(auth_quickaclcheck($id) < AUTH_READ){
126797c0d11SAndreas Gohr            return new IXR_Error(1, 'You are not allowed to read this page');
127797c0d11SAndreas Gohr        }
128797c0d11SAndreas Gohr        return p_wiki_xhtml($id,$rev,false);
129797c0d11SAndreas Gohr    }
130797c0d11SAndreas Gohr
131797c0d11SAndreas Gohr    /**
132797c0d11SAndreas Gohr     * List all pages - we use the indexer list here
133797c0d11SAndreas Gohr     */
134797c0d11SAndreas Gohr    function listPages(){
135797c0d11SAndreas Gohr        require_once(DOKU_INC.'inc/fulltext.php');
136797c0d11SAndreas Gohr        return ft_pageLookup('');
137797c0d11SAndreas Gohr    }
138797c0d11SAndreas Gohr
139797c0d11SAndreas Gohr
140797c0d11SAndreas Gohr    /**
141797c0d11SAndreas Gohr     * Return a list of backlinks
142797c0d11SAndreas Gohr     */
143797c0d11SAndreas Gohr    function listBacklinks($id){
144797c0d11SAndreas Gohr        require_once(DOKU_INC.'inc/fulltext.php');
145797c0d11SAndreas Gohr        return ft_backlinks($id);
146797c0d11SAndreas Gohr    }
147797c0d11SAndreas Gohr
148797c0d11SAndreas Gohr    /**
149797c0d11SAndreas Gohr     * return some basic data about a page
150797c0d11SAndreas Gohr     */
151797c0d11SAndreas Gohr    function pageInfo($id,$rev=''){
152797c0d11SAndreas Gohr        if(auth_quickaclcheck($id) < AUTH_READ){
153797c0d11SAndreas Gohr            return new IXR_Error(1, 'You are not allowed to read this page');
154797c0d11SAndreas Gohr        }
155797c0d11SAndreas Gohr        $file = wikiFN($id,$rev);
156797c0d11SAndreas Gohr        $time = @filemtime($file);
157797c0d11SAndreas Gohr        if(!$time){
158797c0d11SAndreas Gohr            return new IXR_Error(10, 'The requested page does not exist');
159797c0d11SAndreas Gohr        }
160797c0d11SAndreas Gohr
161797c0d11SAndreas Gohr        $info = getRevisionInfo($id, $time, 1024);
162797c0d11SAndreas Gohr
163797c0d11SAndreas Gohr        $data = array(
164797c0d11SAndreas Gohr            'name'         => $id,
165797c0d11SAndreas Gohr            'lastModified' => new IXR_Date($time),
166797c0d11SAndreas Gohr            'author'       => (($info['user']) ? $info['user'] : $info['ip']),
167797c0d11SAndreas Gohr            'version'      => $time
168797c0d11SAndreas Gohr        );
169797c0d11SAndreas Gohr        return $data;
170797c0d11SAndreas Gohr    }
171797c0d11SAndreas Gohr
172797c0d11SAndreas Gohr    /**
173*3a1dad2dSDennis Ploeger     * Save a wiki page
174*3a1dad2dSDennis Ploeger     */
175*3a1dad2dSDennis Ploeger
176*3a1dad2dSDennis Ploeger    function putPage($put_id, $put_text, $put_summary='', $put_minor=0, $put_rev = '', $put_pre = '', $put_suf = '') {
177*3a1dad2dSDennis Ploeger
178*3a1dad2dSDennis Ploeger        global $TEXT;
179*3a1dad2dSDennis Ploeger
180*3a1dad2dSDennis Ploeger        $TEXT = $put_text;
181*3a1dad2dSDennis Ploeger
182*3a1dad2dSDennis Ploeger        // Check, if page is locked
183*3a1dad2dSDennis Ploeger
184*3a1dad2dSDennis Ploeger        if (checklock($put_id) !== false) {
185*3a1dad2dSDennis Ploeger
186*3a1dad2dSDennis Ploeger            return 1;
187*3a1dad2dSDennis Ploeger
188*3a1dad2dSDennis Ploeger        }
189*3a1dad2dSDennis Ploeger
190*3a1dad2dSDennis Ploeger        //spam check
191*3a1dad2dSDennis Ploeger        if(checkwordblock())
192*3a1dad2dSDennis Ploeger            return 2;
193*3a1dad2dSDennis Ploeger
194*3a1dad2dSDennis Ploeger        // lock the page
195*3a1dad2dSDennis Ploeger
196*3a1dad2dSDennis Ploeger        lock($put_id);
197*3a1dad2dSDennis Ploeger
198*3a1dad2dSDennis Ploeger        // save it
199*3a1dad2dSDennis Ploeger
200*3a1dad2dSDennis Ploeger        saveWikiText($put_id,con($put_pre,$put_text,$put_suf,1),$put_summary,$put_minor); //use pretty mode for con
201*3a1dad2dSDennis Ploeger
202*3a1dad2dSDennis Ploeger        // unlock it
203*3a1dad2dSDennis Ploeger
204*3a1dad2dSDennis Ploeger        unlock($put_id);
205*3a1dad2dSDennis Ploeger
206*3a1dad2dSDennis Ploeger        return 0;
207*3a1dad2dSDennis Ploeger
208*3a1dad2dSDennis Ploeger    }
209*3a1dad2dSDennis Ploeger
210*3a1dad2dSDennis Ploeger    /**
211797c0d11SAndreas Gohr     * The version of Wiki RPC API supported
212797c0d11SAndreas Gohr     */
213797c0d11SAndreas Gohr    function wiki_RPCVersion(){
214797c0d11SAndreas Gohr        return 2;
215797c0d11SAndreas Gohr    }
216797c0d11SAndreas Gohr
217797c0d11SAndreas Gohr}
218797c0d11SAndreas Gohr
219797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server();
220797c0d11SAndreas Gohr
221