xref: /dokuwiki/lib/exe/xmlrpc.php (revision 7aec69d1682617fca206712f1dfcd25f6531157a)
1797c0d11SAndreas Gohr<?php
2*7aec69d1SGuy 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
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        );
953a1dad2dSDennis Ploeger
963a1dad2dSDennis Ploeger        $this->addCallback(
973a1dad2dSDennis Ploeger            'wiki.putPage',
983a1dad2dSDennis Ploeger            'this:putPage',
993a1dad2dSDennis Ploeger            array('int', 'string', 'string'),
1003a1dad2dSDennis Ploeger            'Saves a wiki page'
1013a1dad2dSDennis 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    /**
1733a1dad2dSDennis Ploeger     * Save a wiki page
1743a1dad2dSDennis Ploeger     */
1753a1dad2dSDennis Ploeger
1763a1dad2dSDennis Ploeger    function putPage($put_id, $put_text, $put_summary='', $put_minor=0, $put_rev = '', $put_pre = '', $put_suf = '') {
1773a1dad2dSDennis Ploeger
1783a1dad2dSDennis Ploeger        global $TEXT;
1793a1dad2dSDennis Ploeger
1803a1dad2dSDennis Ploeger        $TEXT = $put_text;
1813a1dad2dSDennis Ploeger
1823a1dad2dSDennis Ploeger        // Check, if page is locked
1833a1dad2dSDennis Ploeger
1843a1dad2dSDennis Ploeger        if (checklock($put_id) !== false) {
1853a1dad2dSDennis Ploeger
1863a1dad2dSDennis Ploeger            return 1;
1873a1dad2dSDennis Ploeger
1883a1dad2dSDennis Ploeger        }
1893a1dad2dSDennis Ploeger
1903a1dad2dSDennis Ploeger        //spam check
1913a1dad2dSDennis Ploeger        if(checkwordblock())
1923a1dad2dSDennis Ploeger            return 2;
1933a1dad2dSDennis Ploeger
1943a1dad2dSDennis Ploeger        // lock the page
1953a1dad2dSDennis Ploeger
1963a1dad2dSDennis Ploeger        lock($put_id);
1973a1dad2dSDennis Ploeger
1983a1dad2dSDennis Ploeger        // save it
1993a1dad2dSDennis Ploeger
2003a1dad2dSDennis Ploeger        saveWikiText($put_id,con($put_pre,$put_text,$put_suf,1),$put_summary,$put_minor); //use pretty mode for con
2013a1dad2dSDennis Ploeger
2023a1dad2dSDennis Ploeger        // unlock it
2033a1dad2dSDennis Ploeger
2043a1dad2dSDennis Ploeger        unlock($put_id);
2053a1dad2dSDennis Ploeger
2063a1dad2dSDennis Ploeger        return 0;
2073a1dad2dSDennis Ploeger
2083a1dad2dSDennis Ploeger    }
2093a1dad2dSDennis Ploeger
2103a1dad2dSDennis 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