1*797c0d11SAndreas Gohr<?php 2*797c0d11SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 3*797c0d11SAndreas Gohr 4*797c0d11SAndreas Gohr// fix when '<?xml' isn't on the very first line 5*797c0d11SAndreas Gohrif(isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); 6*797c0d11SAndreas Gohr 7*797c0d11SAndreas Gohr 8*797c0d11SAndreas Gohr//EXPERIMENTAL CODE 9*797c0d11SAndreas Gohrdie('remove me to get it work'); 10*797c0d11SAndreas Gohr 11*797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php'); 12*797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/common.php'); 13*797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/auth.php'); 14*797c0d11SAndreas Gohrsession_write_close(); //close session 15*797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/IXR_Library.php'); 16*797c0d11SAndreas Gohr 17*797c0d11SAndreas Gohr 18*797c0d11SAndreas Gohr 19*797c0d11SAndreas Gohr/** 20*797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available 21*797c0d11SAndreas Gohr * XMLRPC functions. 22*797c0d11SAndreas Gohr */ 23*797c0d11SAndreas Gohrclass dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { 24*797c0d11SAndreas Gohr var $methods = array(); 25*797c0d11SAndreas Gohr 26*797c0d11SAndreas Gohr /** 27*797c0d11SAndreas Gohr * Constructor. Register methods and run Server 28*797c0d11SAndreas Gohr */ 29*797c0d11SAndreas Gohr function dokuwiki_xmlrpc_server(){ 30*797c0d11SAndreas Gohr $this->IXR_IntrospectionServer(); 31*797c0d11SAndreas Gohr 32*797c0d11SAndreas Gohr /* DokuWiki's own methods */ 33*797c0d11SAndreas Gohr $this->addCallback( 34*797c0d11SAndreas Gohr 'dokuwiki.getVersion', 35*797c0d11SAndreas Gohr 'getVersion', 36*797c0d11SAndreas Gohr array('string'), 37*797c0d11SAndreas Gohr 'Returns the running DokuWiki version' 38*797c0d11SAndreas Gohr ); 39*797c0d11SAndreas Gohr 40*797c0d11SAndreas Gohr /* Wiki API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 */ 41*797c0d11SAndreas Gohr $this->addCallback( 42*797c0d11SAndreas Gohr 'wiki.getRPCVersionSupported', 43*797c0d11SAndreas Gohr 'this:wiki_RPCVersion', 44*797c0d11SAndreas Gohr array('int'), 45*797c0d11SAndreas Gohr 'Returns 2 with the supported RPC API version' 46*797c0d11SAndreas Gohr ); 47*797c0d11SAndreas Gohr $this->addCallback( 48*797c0d11SAndreas Gohr 'wiki.getPage', 49*797c0d11SAndreas Gohr 'this:rawPage', 50*797c0d11SAndreas Gohr array('string','string'), 51*797c0d11SAndreas Gohr 'Get the raw Wiki text of page, latest version.' 52*797c0d11SAndreas Gohr ); 53*797c0d11SAndreas Gohr $this->addCallback( 54*797c0d11SAndreas Gohr 'wiki.getPageVersion', 55*797c0d11SAndreas Gohr 'this:rawPage', 56*797c0d11SAndreas Gohr array('string','string','int'), 57*797c0d11SAndreas Gohr 'Get the raw Wiki text of page.' 58*797c0d11SAndreas Gohr ); 59*797c0d11SAndreas Gohr $this->addCallback( 60*797c0d11SAndreas Gohr 'wiki.getPageHTML', 61*797c0d11SAndreas Gohr 'this:htmlPage', 62*797c0d11SAndreas Gohr array('string','string'), 63*797c0d11SAndreas Gohr 'Return page in rendered HTML, latest version.' 64*797c0d11SAndreas Gohr ); 65*797c0d11SAndreas Gohr $this->addCallback( 66*797c0d11SAndreas Gohr 'wiki.getPageHTMLVersion', 67*797c0d11SAndreas Gohr 'this:htmlPage', 68*797c0d11SAndreas Gohr array('string','string','int'), 69*797c0d11SAndreas Gohr 'Return page in rendered HTML.' 70*797c0d11SAndreas Gohr ); 71*797c0d11SAndreas Gohr $this->addCallback( 72*797c0d11SAndreas Gohr 'wiki.getAllPages', 73*797c0d11SAndreas Gohr 'this:listPages', 74*797c0d11SAndreas Gohr array('struct'), 75*797c0d11SAndreas Gohr 'Returns a list of all pages. The result is an array of utf8 pagenames.' 76*797c0d11SAndreas Gohr ); 77*797c0d11SAndreas Gohr $this->addCallback( 78*797c0d11SAndreas Gohr 'wiki.getBackLinks', 79*797c0d11SAndreas Gohr 'this:listBackLinks', 80*797c0d11SAndreas Gohr array('struct','string'), 81*797c0d11SAndreas Gohr 'Returns the pages that link to this page.' 82*797c0d11SAndreas Gohr ); 83*797c0d11SAndreas Gohr $this->addCallback( 84*797c0d11SAndreas Gohr 'wiki.getPageInfo', 85*797c0d11SAndreas Gohr 'this:pageInfo', 86*797c0d11SAndreas Gohr array('struct','string'), 87*797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 88*797c0d11SAndreas Gohr ); 89*797c0d11SAndreas Gohr $this->addCallback( 90*797c0d11SAndreas Gohr 'wiki.getPageInfoVersion', 91*797c0d11SAndreas Gohr 'this:pageInfo', 92*797c0d11SAndreas Gohr array('struct','string','int'), 93*797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 94*797c0d11SAndreas Gohr ); 95*797c0d11SAndreas Gohr/* 96*797c0d11SAndreas Gohr FIXME: missing, yet 97*797c0d11SAndreas Gohr 'wiki.getRecentChanges' 98*797c0d11SAndreas Gohr 'wiki.listLinks' 99*797c0d11SAndreas Gohr 'wiki.putPage' 100*797c0d11SAndreas Gohr*/ 101*797c0d11SAndreas Gohr 102*797c0d11SAndreas Gohr $this->serve(); 103*797c0d11SAndreas Gohr } 104*797c0d11SAndreas Gohr 105*797c0d11SAndreas Gohr /** 106*797c0d11SAndreas Gohr * Return a raw wiki page 107*797c0d11SAndreas Gohr */ 108*797c0d11SAndreas Gohr function rawPage($id,$rev=''){ 109*797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 110*797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 111*797c0d11SAndreas Gohr } 112*797c0d11SAndreas Gohr return rawWiki($id,$rev); 113*797c0d11SAndreas Gohr } 114*797c0d11SAndreas Gohr 115*797c0d11SAndreas Gohr /** 116*797c0d11SAndreas Gohr * Return a wiki page rendered to html 117*797c0d11SAndreas Gohr */ 118*797c0d11SAndreas Gohr function htmlPage($id,$rev=''){ 119*797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 120*797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 121*797c0d11SAndreas Gohr } 122*797c0d11SAndreas Gohr return p_wiki_xhtml($id,$rev,false); 123*797c0d11SAndreas Gohr } 124*797c0d11SAndreas Gohr 125*797c0d11SAndreas Gohr /** 126*797c0d11SAndreas Gohr * List all pages - we use the indexer list here 127*797c0d11SAndreas Gohr */ 128*797c0d11SAndreas Gohr function listPages(){ 129*797c0d11SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 130*797c0d11SAndreas Gohr return ft_pageLookup(''); 131*797c0d11SAndreas Gohr } 132*797c0d11SAndreas Gohr 133*797c0d11SAndreas Gohr 134*797c0d11SAndreas Gohr /** 135*797c0d11SAndreas Gohr * Return a list of backlinks 136*797c0d11SAndreas Gohr */ 137*797c0d11SAndreas Gohr function listBacklinks($id){ 138*797c0d11SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 139*797c0d11SAndreas Gohr return ft_backlinks($id); 140*797c0d11SAndreas Gohr } 141*797c0d11SAndreas Gohr 142*797c0d11SAndreas Gohr /** 143*797c0d11SAndreas Gohr * return some basic data about a page 144*797c0d11SAndreas Gohr */ 145*797c0d11SAndreas Gohr function pageInfo($id,$rev=''){ 146*797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 147*797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 148*797c0d11SAndreas Gohr } 149*797c0d11SAndreas Gohr $file = wikiFN($id,$rev); 150*797c0d11SAndreas Gohr $time = @filemtime($file); 151*797c0d11SAndreas Gohr if(!$time){ 152*797c0d11SAndreas Gohr return new IXR_Error(10, 'The requested page does not exist'); 153*797c0d11SAndreas Gohr } 154*797c0d11SAndreas Gohr 155*797c0d11SAndreas Gohr $info = getRevisionInfo($id, $time, 1024); 156*797c0d11SAndreas Gohr 157*797c0d11SAndreas Gohr $data = array( 158*797c0d11SAndreas Gohr 'name' => $id, 159*797c0d11SAndreas Gohr 'lastModified' => new IXR_Date($time), 160*797c0d11SAndreas Gohr 'author' => (($info['user']) ? $info['user'] : $info['ip']), 161*797c0d11SAndreas Gohr 'version' => $time 162*797c0d11SAndreas Gohr ); 163*797c0d11SAndreas Gohr return $data; 164*797c0d11SAndreas Gohr } 165*797c0d11SAndreas Gohr 166*797c0d11SAndreas Gohr /** 167*797c0d11SAndreas Gohr * The version of Wiki RPC API supported 168*797c0d11SAndreas Gohr */ 169*797c0d11SAndreas Gohr function wiki_RPCVersion(){ 170*797c0d11SAndreas Gohr return 2; 171*797c0d11SAndreas Gohr } 172*797c0d11SAndreas Gohr 173*797c0d11SAndreas Gohr} 174*797c0d11SAndreas Gohr 175*797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server(); 176*797c0d11SAndreas Gohr 177