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 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 $this->addCallback( 963a1dad2dSDennis Ploeger 'wiki.putPage', 973a1dad2dSDennis Ploeger 'this:putPage', 983a1dad2dSDennis Ploeger array('int', 'string', 'string'), 993a1dad2dSDennis Ploeger 'Saves a wiki page' 1003a1dad2dSDennis Ploeger ); 101*beccd742SMichael Klier $this->addCallback( 102*beccd742SMichael Klier 'wiki.listLinks', 103*beccd742SMichael Klier 'this:listLinks', 104*beccd742SMichael Klier array('struct','string'), 105*beccd742SMichael Klier 'Lists all links contained in a wiki page' 106*beccd742SMichael Klier ); 107797c0d11SAndreas Gohr/* 108797c0d11SAndreas Gohr FIXME: missing, yet 109797c0d11SAndreas Gohr 'wiki.getRecentChanges' 110797c0d11SAndreas Gohr*/ 111797c0d11SAndreas Gohr 112797c0d11SAndreas Gohr $this->serve(); 113797c0d11SAndreas Gohr } 114797c0d11SAndreas Gohr 115797c0d11SAndreas Gohr /** 116797c0d11SAndreas Gohr * Return a raw wiki page 117797c0d11SAndreas Gohr */ 118797c0d11SAndreas Gohr function rawPage($id,$rev=''){ 119797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 120797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 121797c0d11SAndreas Gohr } 122797c0d11SAndreas Gohr return rawWiki($id,$rev); 123797c0d11SAndreas Gohr } 124797c0d11SAndreas Gohr 125797c0d11SAndreas Gohr /** 126797c0d11SAndreas Gohr * Return a wiki page rendered to html 127797c0d11SAndreas Gohr */ 128797c0d11SAndreas Gohr function htmlPage($id,$rev=''){ 129797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 130797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 131797c0d11SAndreas Gohr } 132797c0d11SAndreas Gohr return p_wiki_xhtml($id,$rev,false); 133797c0d11SAndreas Gohr } 134797c0d11SAndreas Gohr 135797c0d11SAndreas Gohr /** 136797c0d11SAndreas Gohr * List all pages - we use the indexer list here 137797c0d11SAndreas Gohr */ 138797c0d11SAndreas Gohr function listPages(){ 139797c0d11SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 140797c0d11SAndreas Gohr return ft_pageLookup(''); 141797c0d11SAndreas Gohr } 142797c0d11SAndreas Gohr 143797c0d11SAndreas Gohr 144797c0d11SAndreas Gohr /** 145797c0d11SAndreas Gohr * Return a list of backlinks 146797c0d11SAndreas Gohr */ 147*beccd742SMichael Klier function listBackLinks($id){ 148797c0d11SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 149797c0d11SAndreas Gohr return ft_backlinks($id); 150797c0d11SAndreas Gohr } 151797c0d11SAndreas Gohr 152797c0d11SAndreas Gohr /** 153797c0d11SAndreas Gohr * return some basic data about a page 154797c0d11SAndreas Gohr */ 155797c0d11SAndreas Gohr function pageInfo($id,$rev=''){ 156797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 157797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 158797c0d11SAndreas Gohr } 159797c0d11SAndreas Gohr $file = wikiFN($id,$rev); 160797c0d11SAndreas Gohr $time = @filemtime($file); 161797c0d11SAndreas Gohr if(!$time){ 162797c0d11SAndreas Gohr return new IXR_Error(10, 'The requested page does not exist'); 163797c0d11SAndreas Gohr } 164797c0d11SAndreas Gohr 165797c0d11SAndreas Gohr $info = getRevisionInfo($id, $time, 1024); 166797c0d11SAndreas Gohr 167797c0d11SAndreas Gohr $data = array( 168797c0d11SAndreas Gohr 'name' => $id, 169797c0d11SAndreas Gohr 'lastModified' => new IXR_Date($time), 170797c0d11SAndreas Gohr 'author' => (($info['user']) ? $info['user'] : $info['ip']), 171797c0d11SAndreas Gohr 'version' => $time 172797c0d11SAndreas Gohr ); 173797c0d11SAndreas Gohr return $data; 174797c0d11SAndreas Gohr } 175797c0d11SAndreas Gohr 176797c0d11SAndreas Gohr /** 1773a1dad2dSDennis Ploeger * Save a wiki page 1783a1dad2dSDennis Ploeger */ 1793a1dad2dSDennis Ploeger function putPage($put_id, $put_text, $put_summary='', $put_minor=0, $put_rev='', $put_pre='', $put_suf='') { 1803a1dad2dSDennis Ploeger global $TEXT; 1813a1dad2dSDennis Ploeger 1823a1dad2dSDennis Ploeger $TEXT = $put_text; 1833a1dad2dSDennis Ploeger 1843a1dad2dSDennis Ploeger // Check, if page is locked 185*beccd742SMichael Klier if (checklock($put_id) !== false) 1863a1dad2dSDennis Ploeger return 1; 1873a1dad2dSDennis Ploeger 1883a1dad2dSDennis Ploeger //spam check 1893a1dad2dSDennis Ploeger if(checkwordblock()) 1903a1dad2dSDennis Ploeger return 2; 1913a1dad2dSDennis Ploeger 1923a1dad2dSDennis Ploeger lock($put_id); 1933a1dad2dSDennis Ploeger 194*beccd742SMichael Klier saveWikiText($put_id,con($put_pre,$put_text,$put_suf,1),$put_summary,$put_minor); 1953a1dad2dSDennis Ploeger 1963a1dad2dSDennis Ploeger unlock($put_id); 1973a1dad2dSDennis Ploeger 1983a1dad2dSDennis Ploeger return 0; 199*beccd742SMichael Klier } 2003a1dad2dSDennis Ploeger 201*beccd742SMichael Klier /** 202*beccd742SMichael Klier * Lists all links contained in a wiki page 203*beccd742SMichael Klier */ 204*beccd742SMichael Klier function listLinks($id) { 205*beccd742SMichael Klier if(auth_quickaclcheck($id) < AUTH_READ){ 206*beccd742SMichael Klier return new IXR_Error(1, 'You are not allowed to read this page'); 207*beccd742SMichael Klier } 208*beccd742SMichael Klier $links = array(); 209*beccd742SMichael Klier 210*beccd742SMichael Klier // resolve page instructions 211*beccd742SMichael Klier $ins = p_cached_instructions(wikiFN(cleanID($id))); 212*beccd742SMichael Klier 213*beccd742SMichael Klier // instantiate new Renderer - needed for interwiki links 214*beccd742SMichael Klier include(DOKU_INC.'inc/parser/xhtml.php'); 215*beccd742SMichael Klier $Renderer = new Doku_Renderer_xhtml(); 216*beccd742SMichael Klier $Renderer->interwiki = getInterwiki(); 217*beccd742SMichael Klier 218*beccd742SMichael Klier // parse parse instructions 219*beccd742SMichael Klier foreach($ins as $in) { 220*beccd742SMichael Klier $link = array(); 221*beccd742SMichael Klier switch($in[0]) { 222*beccd742SMichael Klier case 'internallink': 223*beccd742SMichael Klier $link['type'] = 'local'; 224*beccd742SMichael Klier $link['page'] = $in[1][0]; 225*beccd742SMichael Klier $link['href'] = wl($in[1][0]); 226*beccd742SMichael Klier array_push($links,$link); 227*beccd742SMichael Klier break; 228*beccd742SMichael Klier case 'externallink': 229*beccd742SMichael Klier $link['type'] = 'extern'; 230*beccd742SMichael Klier $link['page'] = $in[1][0]; 231*beccd742SMichael Klier $link['href'] = $in[1][0]; 232*beccd742SMichael Klier array_push($links,$link); 233*beccd742SMichael Klier break; 234*beccd742SMichael Klier case 'interwikilink': 235*beccd742SMichael Klier $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]); 236*beccd742SMichael Klier $link['type'] = 'extern'; 237*beccd742SMichael Klier $link['page'] = $url; 238*beccd742SMichael Klier $link['href'] = $url; 239*beccd742SMichael Klier array_push($links,$link); 240*beccd742SMichael Klier break; 241*beccd742SMichael Klier } 242*beccd742SMichael Klier } 243*beccd742SMichael Klier 244*beccd742SMichael Klier return $links; 2453a1dad2dSDennis Ploeger } 2463a1dad2dSDennis Ploeger 2473a1dad2dSDennis Ploeger /** 248797c0d11SAndreas Gohr * The version of Wiki RPC API supported 249797c0d11SAndreas Gohr */ 250797c0d11SAndreas Gohr function wiki_RPCVersion(){ 251797c0d11SAndreas Gohr return 2; 252797c0d11SAndreas Gohr } 253797c0d11SAndreas Gohr 254797c0d11SAndreas Gohr} 255797c0d11SAndreas Gohr 256797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server(); 257797c0d11SAndreas Gohr 258