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 * Contains needed wrapper functions and registers all available 20 * XMLRPC functions. 21 */ 22class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { 23 var $methods = array(); 24 25 /** 26 * Constructor. Register methods and run Server 27 */ 28 function dokuwiki_xmlrpc_server(){ 29 $this->IXR_IntrospectionServer(); 30 31 /* DokuWiki's own methods */ 32 $this->addCallback( 33 'dokuwiki.getVersion', 34 'getVersion', 35 array('string'), 36 'Returns the running DokuWiki version' 37 ); 38 39 /* Wiki API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 */ 40 $this->addCallback( 41 'wiki.getRPCVersionSupported', 42 'this:wiki_RPCVersion', 43 array('int'), 44 'Returns 2 with the supported RPC API version' 45 ); 46 $this->addCallback( 47 'wiki.getPage', 48 'this:rawPage', 49 array('string','string'), 50 'Get the raw Wiki text of page, latest version.' 51 ); 52 $this->addCallback( 53 'wiki.getPageVersion', 54 'this:rawPage', 55 array('string','string','int'), 56 'Get the raw Wiki text of page.' 57 ); 58 $this->addCallback( 59 'wiki.getPageHTML', 60 'this:htmlPage', 61 array('string','string'), 62 'Return page in rendered HTML, latest version.' 63 ); 64 $this->addCallback( 65 'wiki.getPageHTMLVersion', 66 'this:htmlPage', 67 array('string','string','int'), 68 'Return page in rendered HTML.' 69 ); 70 $this->addCallback( 71 'wiki.getAllPages', 72 'this:listPages', 73 array('struct'), 74 'Returns a list of all pages. The result is an array of utf8 pagenames.' 75 ); 76 $this->addCallback( 77 'wiki.getBackLinks', 78 'this:listBackLinks', 79 array('struct','string'), 80 'Returns the pages that link to this page.' 81 ); 82 $this->addCallback( 83 'wiki.getPageInfo', 84 'this:pageInfo', 85 array('struct','string'), 86 'Returns a struct with infos about the page.' 87 ); 88 $this->addCallback( 89 'wiki.getPageInfoVersion', 90 'this:pageInfo', 91 array('struct','string','int'), 92 'Returns a struct with infos about the page.' 93 ); 94 $this->addCallback( 95 'wiki.putPage', 96 'this:putPage', 97 array('int', 'string', 'string', 'struct'), 98 'Saves a wiki page' 99 ); 100 $this->addCallback( 101 'wiki.listLinks', 102 'this:listLinks', 103 array('struct','string'), 104 'Lists all links contained in a wiki page' 105 ); 106 $this->addCallback( 107 'wiki.getRecentChanges', 108 'this:getRecentChanges', 109 array('struct','int'), 110 'Returns a strukt about all recent changes since given timestamp.' 111 ); 112 113 $this->serve(); 114 } 115 116 /** 117 * Return a raw wiki page 118 */ 119 function rawPage($id,$rev=''){ 120 if(auth_quickaclcheck($id) < AUTH_READ){ 121 return new IXR_Error(1, 'You are not allowed to read this page'); 122 } 123 return rawWiki($id,$rev); 124 } 125 126 /** 127 * Return a wiki page rendered to html 128 */ 129 function htmlPage($id,$rev=''){ 130 if(auth_quickaclcheck($id) < AUTH_READ){ 131 return new IXR_Error(1, 'You are not allowed to read this page'); 132 } 133 return p_wiki_xhtml($id,$rev,false); 134 } 135 136 /** 137 * List all pages - we use the indexer list here 138 */ 139 function listPages(){ 140 require_once(DOKU_INC.'inc/fulltext.php'); 141 return ft_pageLookup(''); 142 } 143 144 /** 145 * Return a list of backlinks 146 */ 147 function listBackLinks($id){ 148 require_once(DOKU_INC.'inc/fulltext.php'); 149 return ft_backlinks($id); 150 } 151 152 /** 153 * Return some basic data about a page 154 */ 155 function pageInfo($id,$rev=''){ 156 if(auth_quickaclcheck($id) < AUTH_READ){ 157 return new IXR_Error(1, 'You are not allowed to read this page'); 158 } 159 $file = wikiFN($id,$rev); 160 $time = @filemtime($file); 161 if(!$time){ 162 return new IXR_Error(10, 'The requested page does not exist'); 163 } 164 165 $info = getRevisionInfo($id, $time, 1024); 166 167 $data = array( 168 'name' => $id, 169 'lastModified' => new IXR_Date($time), 170 'author' => (($info['user']) ? $info['user'] : $info['ip']), 171 'version' => $time 172 ); 173 174 return ($data); 175 } 176 177 /** 178 * Save a wiki page 179 * 180 * @author Michael Klier <chi@chimeric.de> 181 */ 182 function putPage($id, $text, $params) { 183 global $TEXT; 184 185 $id = cleanID($id); 186 $TEXT = trim($text); 187 $sum = $params['sum']; 188 $minor = $params['minor']; 189 190 if(empty($id)) 191 return new IXR_Error(1, 'Empty Page ID'); 192 193 if(auth_quickaclcheck($id) < AUTH_WRITE) 194 return new IXR_Error(1, 'You are not allowed to edit this page'); 195 196 // Check, if page is locked 197 if(checklock($id)) 198 return new IXR_Error(1, 'The page is currently locked'); 199 200 if(empty($TEXT)) 201 return new IXR_Error(1, 'No Text supplied'); 202 203 //spam check 204 if(checkwordblock()) 205 return new IXR_Error(1, 'Positive wordblock check'); 206 207 lock($id); 208 209 saveWikiText($id,$TEXT,$sum,$minor); 210 211 unlock($id); 212 213 return 0; 214 } 215 216 /** 217 * Lists all links contained in a wiki page 218 * 219 * @author Michael Klier <chi@chimeric.de> 220 */ 221 function listLinks($id) { 222 if(auth_quickaclcheck($id) < AUTH_READ){ 223 return new IXR_Error(1, 'You are not allowed to read this page'); 224 } 225 $links = array(); 226 227 // resolve page instructions 228 $ins = p_cached_instructions(wikiFN(cleanID($id))); 229 230 // instantiate new Renderer - needed for interwiki links 231 include(DOKU_INC.'inc/parser/xhtml.php'); 232 $Renderer = new Doku_Renderer_xhtml(); 233 $Renderer->interwiki = getInterwiki(); 234 235 // parse parse instructions 236 foreach($ins as $in) { 237 $link = array(); 238 switch($in[0]) { 239 case 'internallink': 240 $link['type'] = 'local'; 241 $link['page'] = $in[1][0]; 242 $link['href'] = wl($in[1][0]); 243 array_push($links,$link); 244 break; 245 case 'externallink': 246 $link['type'] = 'extern'; 247 $link['page'] = $in[1][0]; 248 $link['href'] = $in[1][0]; 249 array_push($links,$link); 250 break; 251 case 'interwikilink': 252 $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]); 253 $link['type'] = 'extern'; 254 $link['page'] = $url; 255 $link['href'] = $url; 256 array_push($links,$link); 257 break; 258 } 259 } 260 261 return ($links); 262 } 263 264 /** 265 * Returns a list of recent changes since give timestamp 266 * 267 * @author Michael Klier <chi@chimeric.de> 268 */ 269 function getRecentChanges($timestamp) { 270 global $conf; 271 272 if(strlen($timestamp) != 10) 273 return new IXR_Error(20, 'The provided value is not a valid timestamp'); 274 275 $changes = array(); 276 277 require_once(DOKU_INC.'inc/changelog.php'); 278 require_once(DOKU_INC.'inc/pageutils.php'); 279 280 // read changes 281 $lines = @file($conf['changelog']); 282 283 if(empty($lines)) 284 return new IXR_Error(10, 'The changelog could not be read'); 285 286 // we start searching at the end of the list 287 $lines = array_reverse($lines); 288 289 // cache seen pages and skip them 290 $seen = array(); 291 292 foreach($lines as $line) { 293 294 if(empty($line)) continue; // skip empty lines 295 296 $logline = parseChangelogLine($line); 297 298 if($logline === false) continue; 299 300 // skip seen ones 301 if(isset($seen[$logline['id']])) continue; 302 303 // skip minors 304 if($logline['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT && ($flags & RECENTS_SKIP_MINORS)) continue; 305 306 // remember in seen to skip additional sights 307 $seen[$logline['id']] = 1; 308 309 // check if it's a hidden page 310 if(isHiddenPage($logline['id'])) continue; 311 312 // check ACL 313 if(auth_quickaclcheck($logline['id']) < AUTH_READ) continue; 314 315 // check existance 316 if((!@file_exists(wikiFN($logline['id']))) && ($flags & RECENTS_SKIP_DELETED)) continue; 317 318 // check if logline is still in the queried time frame 319 if($logline['date'] >= $timestamp) { 320 $change['name'] = $logline['id']; 321 $change['lastModified'] = new IXR_Date($logline['date']); 322 $change['author'] = $logline['user']; 323 $change['version'] = $logline['date']; 324 array_push($changes, $change); 325 } else { 326 $changes = array_reverse($changes); 327 return ($changes); 328 } 329 } 330 // in case we still have nothing at this point 331 return new IXR_Error(30, 'There are no changes in the specified timeframe'); 332 } 333 334 /** 335 * The version of Wiki RPC API supported 336 */ 337 function wiki_RPCVersion(){ 338 return 2; 339 } 340 341} 342 343$server = new dokuwiki_xmlrpc_server(); 344 345// vim:ts=4:sw=4:enc=utf-8: 346