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