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 96 $this->addCallback( 97 'wiki.putPage', 98 'this:putPage', 99 array('int', 'string', 'string'), 100 'Saves a wiki page' 101 ); 102/* 103 FIXME: missing, yet 104 'wiki.getRecentChanges' 105 'wiki.listLinks' 106*/ 107 108 $this->serve(); 109 } 110 111 /** 112 * Return a raw wiki page 113 */ 114 function rawPage($id,$rev=''){ 115 if(auth_quickaclcheck($id) < AUTH_READ){ 116 return new IXR_Error(1, 'You are not allowed to read this page'); 117 } 118 return rawWiki($id,$rev); 119 } 120 121 /** 122 * Return a wiki page rendered to html 123 */ 124 function htmlPage($id,$rev=''){ 125 if(auth_quickaclcheck($id) < AUTH_READ){ 126 return new IXR_Error(1, 'You are not allowed to read this page'); 127 } 128 return p_wiki_xhtml($id,$rev,false); 129 } 130 131 /** 132 * List all pages - we use the indexer list here 133 */ 134 function listPages(){ 135 require_once(DOKU_INC.'inc/fulltext.php'); 136 return ft_pageLookup(''); 137 } 138 139 140 /** 141 * Return a list of backlinks 142 */ 143 function listBacklinks($id){ 144 require_once(DOKU_INC.'inc/fulltext.php'); 145 return ft_backlinks($id); 146 } 147 148 /** 149 * return some basic data about a page 150 */ 151 function pageInfo($id,$rev=''){ 152 if(auth_quickaclcheck($id) < AUTH_READ){ 153 return new IXR_Error(1, 'You are not allowed to read this page'); 154 } 155 $file = wikiFN($id,$rev); 156 $time = @filemtime($file); 157 if(!$time){ 158 return new IXR_Error(10, 'The requested page does not exist'); 159 } 160 161 $info = getRevisionInfo($id, $time, 1024); 162 163 $data = array( 164 'name' => $id, 165 'lastModified' => new IXR_Date($time), 166 'author' => (($info['user']) ? $info['user'] : $info['ip']), 167 'version' => $time 168 ); 169 return $data; 170 } 171 172 /** 173 * Save a wiki page 174 */ 175 176 function putPage($put_id, $put_text, $put_summary='', $put_minor=0, $put_rev = '', $put_pre = '', $put_suf = '') { 177 178 global $TEXT; 179 180 $TEXT = $put_text; 181 182 // Check, if page is locked 183 184 if (checklock($put_id) !== false) { 185 186 return 1; 187 188 } 189 190 //spam check 191 if(checkwordblock()) 192 return 2; 193 194 // lock the page 195 196 lock($put_id); 197 198 // save it 199 200 saveWikiText($put_id,con($put_pre,$put_text,$put_suf,1),$put_summary,$put_minor); //use pretty mode for con 201 202 // unlock it 203 204 unlock($put_id); 205 206 return 0; 207 208 } 209 210 /** 211 * The version of Wiki RPC API supported 212 */ 213 function wiki_RPCVersion(){ 214 return 2; 215 } 216 217} 218 219$server = new dokuwiki_xmlrpc_server(); 220 221