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 Gohrrequire_once(DOKU_INC.'inc/init.php'); 9797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/common.php'); 10797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/auth.php'); 11797c0d11SAndreas Gohrsession_write_close(); //close session 12593bf8f6SMichael Klier 13593bf8f6SMichael Klierif(!$conf['xmlrpc']) { 14593bf8f6SMichael Klier die('XML-RPC server not enabled.'); 15593bf8f6SMichael Klier // FIXME check for groups allowed 16593bf8f6SMichael Klier} 17593bf8f6SMichael Klier 18797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/IXR_Library.php'); 19797c0d11SAndreas Gohr 20797c0d11SAndreas Gohr 21797c0d11SAndreas Gohr/** 22797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available 23797c0d11SAndreas Gohr * XMLRPC functions. 24797c0d11SAndreas Gohr */ 25797c0d11SAndreas Gohrclass dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { 26797c0d11SAndreas Gohr var $methods = array(); 27797c0d11SAndreas Gohr 28797c0d11SAndreas Gohr /** 29797c0d11SAndreas Gohr * Constructor. Register methods and run Server 30797c0d11SAndreas Gohr */ 31797c0d11SAndreas Gohr function dokuwiki_xmlrpc_server(){ 32797c0d11SAndreas Gohr $this->IXR_IntrospectionServer(); 33797c0d11SAndreas Gohr 34797c0d11SAndreas Gohr /* DokuWiki's own methods */ 35797c0d11SAndreas Gohr $this->addCallback( 36797c0d11SAndreas Gohr 'dokuwiki.getVersion', 37797c0d11SAndreas Gohr 'getVersion', 38797c0d11SAndreas Gohr array('string'), 39fdd2e9d6SMichael Klier 'Returns the running DokuWiki version.' 40797c0d11SAndreas Gohr ); 41797c0d11SAndreas Gohr 42797c0d11SAndreas Gohr /* Wiki API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 */ 43797c0d11SAndreas Gohr $this->addCallback( 44797c0d11SAndreas Gohr 'wiki.getRPCVersionSupported', 45797c0d11SAndreas Gohr 'this:wiki_RPCVersion', 46797c0d11SAndreas Gohr array('int'), 47fdd2e9d6SMichael Klier 'Returns 2 with the supported RPC API version.' 48797c0d11SAndreas Gohr ); 49797c0d11SAndreas Gohr $this->addCallback( 50797c0d11SAndreas Gohr 'wiki.getPage', 51797c0d11SAndreas Gohr 'this:rawPage', 52797c0d11SAndreas Gohr array('string','string'), 53797c0d11SAndreas Gohr 'Get the raw Wiki text of page, latest version.' 54797c0d11SAndreas Gohr ); 55797c0d11SAndreas Gohr $this->addCallback( 56797c0d11SAndreas Gohr 'wiki.getPageVersion', 57797c0d11SAndreas Gohr 'this:rawPage', 58797c0d11SAndreas Gohr array('string','string','int'), 59797c0d11SAndreas Gohr 'Get the raw Wiki text of page.' 60797c0d11SAndreas Gohr ); 61797c0d11SAndreas Gohr $this->addCallback( 62797c0d11SAndreas Gohr 'wiki.getPageHTML', 63797c0d11SAndreas Gohr 'this:htmlPage', 64797c0d11SAndreas Gohr array('string','string'), 65797c0d11SAndreas Gohr 'Return page in rendered HTML, latest version.' 66797c0d11SAndreas Gohr ); 67797c0d11SAndreas Gohr $this->addCallback( 68797c0d11SAndreas Gohr 'wiki.getPageHTMLVersion', 69797c0d11SAndreas Gohr 'this:htmlPage', 70797c0d11SAndreas Gohr array('string','string','int'), 71797c0d11SAndreas Gohr 'Return page in rendered HTML.' 72797c0d11SAndreas Gohr ); 73797c0d11SAndreas Gohr $this->addCallback( 74797c0d11SAndreas Gohr 'wiki.getAllPages', 75797c0d11SAndreas Gohr 'this:listPages', 76797c0d11SAndreas Gohr array('struct'), 77797c0d11SAndreas Gohr 'Returns a list of all pages. The result is an array of utf8 pagenames.' 78797c0d11SAndreas Gohr ); 79797c0d11SAndreas Gohr $this->addCallback( 8026bec61eSMichael Klier 'wiki.getAttachments', 8126bec61eSMichael Klier 'this:listAttachments', 8226bec61eSMichael Klier array('struct'), 8326bec61eSMichael Klier 'Returns a list of all media files.' 8426bec61eSMichael Klier ); 8526bec61eSMichael Klier $this->addCallback( 86797c0d11SAndreas Gohr 'wiki.getBackLinks', 87797c0d11SAndreas Gohr 'this:listBackLinks', 88797c0d11SAndreas Gohr array('struct','string'), 89797c0d11SAndreas Gohr 'Returns the pages that link to this page.' 90797c0d11SAndreas Gohr ); 91797c0d11SAndreas Gohr $this->addCallback( 92797c0d11SAndreas Gohr 'wiki.getPageInfo', 93797c0d11SAndreas Gohr 'this:pageInfo', 94797c0d11SAndreas Gohr array('struct','string'), 95797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 96797c0d11SAndreas Gohr ); 97797c0d11SAndreas Gohr $this->addCallback( 98797c0d11SAndreas Gohr 'wiki.getPageInfoVersion', 99797c0d11SAndreas Gohr 'this:pageInfo', 100797c0d11SAndreas Gohr array('struct','string','int'), 101797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 102797c0d11SAndreas Gohr ); 1033a1dad2dSDennis Ploeger $this->addCallback( 10473056168SMichael Klier 'wiki.getPageVersions', 10573056168SMichael Klier 'this:pageVersions', 10673056168SMichael Klier array('struct','string','int'), 10773056168SMichael Klier 'Returns the available revisions of the page.' 10873056168SMichael Klier ); 10973056168SMichael Klier $this->addCallback( 1103a1dad2dSDennis Ploeger 'wiki.putPage', 1113a1dad2dSDennis Ploeger 'this:putPage', 112222572bfSMichael Klier array('int', 'string', 'string', 'struct'), 113fdd2e9d6SMichael Klier 'Saves a wiki page.' 1143a1dad2dSDennis Ploeger ); 115beccd742SMichael Klier $this->addCallback( 116beccd742SMichael Klier 'wiki.listLinks', 117beccd742SMichael Klier 'this:listLinks', 118beccd742SMichael Klier array('struct','string'), 119fdd2e9d6SMichael Klier 'Lists all links contained in a wiki page.' 120beccd742SMichael Klier ); 12163dd0d58SMichael Klier $this->addCallback( 12263dd0d58SMichael Klier 'wiki.getRecentChanges', 12363dd0d58SMichael Klier 'this:getRecentChanges', 12463dd0d58SMichael Klier array('struct','int'), 12563dd0d58SMichael Klier 'Returns a strukt about all recent changes since given timestamp.' 12663dd0d58SMichael Klier ); 127e62b9ea5SMichael Klier $this->addCallback( 128e62b9ea5SMichael Klier 'wiki.aclCheck', 129e62b9ea5SMichael Klier 'this:aclCheck', 130e62b9ea5SMichael Klier array('struct', 'string'), 131e62b9ea5SMichael Klier 'Returns the permissions of a given wiki page.' 132e62b9ea5SMichael Klier ); 1332aca132fSMichael Klier $this->addCallback( 1342aca132fSMichael Klier 'wiki.putAttachment', 1352aca132fSMichael Klier 'this:putAttachment', 1362aca132fSMichael Klier array('struct', 'string', 'base64', 'struct'), 1372aca132fSMichael Klier 'Upload a file to the wiki.' 1382aca132fSMichael Klier ); 139797c0d11SAndreas Gohr 140797c0d11SAndreas Gohr $this->serve(); 141797c0d11SAndreas Gohr } 142797c0d11SAndreas Gohr 143797c0d11SAndreas Gohr /** 144797c0d11SAndreas Gohr * Return a raw wiki page 145797c0d11SAndreas Gohr */ 146797c0d11SAndreas Gohr function rawPage($id,$rev=''){ 147797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 148797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 149797c0d11SAndreas Gohr } 1502c176304SMichael Klier $text = rawWiki($id,$rev); 1512c176304SMichael Klier if(!$text) { 1522c176304SMichael Klier $data = array($id); 1532c176304SMichael Klier return trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true); 1542c176304SMichael Klier } else { 1552c176304SMichael Klier return $text; 1562c176304SMichael Klier } 157797c0d11SAndreas Gohr } 158797c0d11SAndreas Gohr 159797c0d11SAndreas Gohr /** 160797c0d11SAndreas Gohr * Return a wiki page rendered to html 161797c0d11SAndreas Gohr */ 162797c0d11SAndreas Gohr function htmlPage($id,$rev=''){ 163797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 164797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 165797c0d11SAndreas Gohr } 166797c0d11SAndreas Gohr return p_wiki_xhtml($id,$rev,false); 167797c0d11SAndreas Gohr } 168797c0d11SAndreas Gohr 169797c0d11SAndreas Gohr /** 170797c0d11SAndreas Gohr * List all pages - we use the indexer list here 171797c0d11SAndreas Gohr */ 172797c0d11SAndreas Gohr function listPages(){ 173797c0d11SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 174797c0d11SAndreas Gohr return ft_pageLookup(''); 175797c0d11SAndreas Gohr } 176797c0d11SAndreas Gohr 177797c0d11SAndreas Gohr /** 17826bec61eSMichael Klier * List all media files. 17926bec61eSMichael Klier */ 18026bec61eSMichael Klier function listAttachments($ns) { 18126bec61eSMichael Klier global $conf; 18226bec61eSMichael Klier global $lang; 18326bec61eSMichael Klier 18426bec61eSMichael Klier $ns = cleanID($ns); 18526bec61eSMichael Klier 18626bec61eSMichael Klier if(auth_quickaclcheck($ns.':*') >= AUTH_READ) { 18726bec61eSMichael Klier $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 18826bec61eSMichael Klier 18926bec61eSMichael Klier $data = array(); 19026bec61eSMichael Klier require_once(DOKU_INC.'inc/search.php'); 191*20683e40SGina Haeussge search($data, $conf['mediadir'], 'search_media', array('recursive' => true), $dir); 19226bec61eSMichael Klier 19326bec61eSMichael Klier if(!count($data)) { 19426bec61eSMichael Klier return array(); 19526bec61eSMichael Klier } 19626bec61eSMichael Klier 19726bec61eSMichael Klier $files = array(); 19826bec61eSMichael Klier foreach($data as $item) { 19926bec61eSMichael Klier $file = array(); 20026bec61eSMichael Klier $file['id'] = $item['id']; 20126bec61eSMichael Klier $file['size'] = $item['size']; 20226bec61eSMichael Klier $file['mtime'] = $item['mtime']; 20326bec61eSMichael Klier $file['isimg'] = $item['isimg']; 20426bec61eSMichael Klier $file['writable'] = $item['writeable']; 20526bec61eSMichael Klier array_push($files, $file); 20626bec61eSMichael Klier } 20726bec61eSMichael Klier 20826bec61eSMichael Klier return $files; 20926bec61eSMichael Klier 21026bec61eSMichael Klier } else { 21126bec61eSMichael Klier return new IXR_Error(1, 'You are not allowed to list media files.'); 21226bec61eSMichael Klier } 21326bec61eSMichael Klier } 21426bec61eSMichael Klier 21526bec61eSMichael Klier /** 216797c0d11SAndreas Gohr * Return a list of backlinks 217797c0d11SAndreas Gohr */ 218beccd742SMichael Klier function listBackLinks($id){ 219797c0d11SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 220797c0d11SAndreas Gohr return ft_backlinks($id); 221797c0d11SAndreas Gohr } 222797c0d11SAndreas Gohr 223797c0d11SAndreas Gohr /** 22463dd0d58SMichael Klier * Return some basic data about a page 225797c0d11SAndreas Gohr */ 226797c0d11SAndreas Gohr function pageInfo($id,$rev=''){ 227797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 228797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 229797c0d11SAndreas Gohr } 230797c0d11SAndreas Gohr $file = wikiFN($id,$rev); 231797c0d11SAndreas Gohr $time = @filemtime($file); 232797c0d11SAndreas Gohr if(!$time){ 233797c0d11SAndreas Gohr return new IXR_Error(10, 'The requested page does not exist'); 234797c0d11SAndreas Gohr } 235797c0d11SAndreas Gohr 236797c0d11SAndreas Gohr $info = getRevisionInfo($id, $time, 1024); 237797c0d11SAndreas Gohr 238797c0d11SAndreas Gohr $data = array( 239797c0d11SAndreas Gohr 'name' => $id, 240797c0d11SAndreas Gohr 'lastModified' => new IXR_Date($time), 241797c0d11SAndreas Gohr 'author' => (($info['user']) ? $info['user'] : $info['ip']), 242797c0d11SAndreas Gohr 'version' => $time 243797c0d11SAndreas Gohr ); 24463dd0d58SMichael Klier 24563dd0d58SMichael Klier return ($data); 246797c0d11SAndreas Gohr } 247797c0d11SAndreas Gohr 248797c0d11SAndreas Gohr /** 2493a1dad2dSDennis Ploeger * Save a wiki page 250222572bfSMichael Klier * 251222572bfSMichael Klier * @author Michael Klier <chi@chimeric.de> 2523a1dad2dSDennis Ploeger */ 253222572bfSMichael Klier function putPage($id, $text, $params) { 2543a1dad2dSDennis Ploeger global $TEXT; 255a6a229ceSMichael Klier global $lang; 256593bf8f6SMichael Klier global $conf; 2573a1dad2dSDennis Ploeger 258222572bfSMichael Klier $id = cleanID($id); 259222572bfSMichael Klier $TEXT = trim($text); 260222572bfSMichael Klier $sum = $params['sum']; 261222572bfSMichael Klier $minor = $params['minor']; 262222572bfSMichael Klier 263222572bfSMichael Klier if(empty($id)) 264fdd2e9d6SMichael Klier return new IXR_Error(1, 'Empty page ID'); 265222572bfSMichael Klier 26651597811SMichael Klier if(!page_exists($id) && empty($TEXT)) { 26751597811SMichael Klier return new IXR_ERROR(1, 'Refusing to write an empty new wiki page'); 26851597811SMichael Klier } 26951597811SMichael Klier 270055b0144SChris Smith if(auth_quickaclcheck($id) < AUTH_EDIT) 271222572bfSMichael Klier return new IXR_Error(1, 'You are not allowed to edit this page'); 2723a1dad2dSDennis Ploeger 2733a1dad2dSDennis Ploeger // Check, if page is locked 274222572bfSMichael Klier if(checklock($id)) 275222572bfSMichael Klier return new IXR_Error(1, 'The page is currently locked'); 276222572bfSMichael Klier 277a6a229ceSMichael Klier // SPAM check 2783a1dad2dSDennis Ploeger if(checkwordblock()) 279222572bfSMichael Klier return new IXR_Error(1, 'Positive wordblock check'); 2803a1dad2dSDennis Ploeger 281a6a229ceSMichael Klier // autoset summary on new pages 282a6a229ceSMichael Klier if(!page_exists($id) && empty($sum)) { 283a6a229ceSMichael Klier $sum = $lang['created']; 284a6a229ceSMichael Klier } 285a6a229ceSMichael Klier 286a6a229ceSMichael Klier // autoset summary on deleted pages 287a6a229ceSMichael Klier if(page_exists($id) && empty($TEXT) && empty($sum)) { 288a6a229ceSMichael Klier $sum = $lang['deleted']; 289a6a229ceSMichael Klier } 290a6a229ceSMichael Klier 291222572bfSMichael Klier lock($id); 2923a1dad2dSDennis Ploeger 293222572bfSMichael Klier saveWikiText($id,$TEXT,$sum,$minor); 2943a1dad2dSDennis Ploeger 295222572bfSMichael Klier unlock($id); 2963a1dad2dSDennis Ploeger 297593bf8f6SMichael Klier // run the indexer if page wasn't indexed yet 298593bf8f6SMichael Klier if(!@file_exists(metaFN($id, '.indexed'))) { 299593bf8f6SMichael Klier // try to aquire a lock 300593bf8f6SMichael Klier $lock = $conf['lockdir'].'/_indexer.lock'; 301593bf8f6SMichael Klier while(!@mkdir($lock,$conf['dmode'])){ 302593bf8f6SMichael Klier usleep(50); 303593bf8f6SMichael Klier if(time()-@filemtime($lock) > 60*5){ 304593bf8f6SMichael Klier // looks like a stale lock - remove it 305593bf8f6SMichael Klier @rmdir($lock); 306593bf8f6SMichael Klier }else{ 307593bf8f6SMichael Klier return false; 308593bf8f6SMichael Klier } 309593bf8f6SMichael Klier } 310593bf8f6SMichael Klier if($conf['dperm']) chmod($lock, $conf['dperm']); 311593bf8f6SMichael Klier 312593bf8f6SMichael Klier require_once(DOKU_INC.'inc/indexer.php'); 313593bf8f6SMichael Klier 314593bf8f6SMichael Klier // do the work 315593bf8f6SMichael Klier idx_addPage($id); 316593bf8f6SMichael Klier 317593bf8f6SMichael Klier // we're finished - save and free lock 318593bf8f6SMichael Klier io_saveFile(metaFN($id,'.indexed'),INDEXER_VERSION); 319593bf8f6SMichael Klier @rmdir($lock); 320593bf8f6SMichael Klier } 321593bf8f6SMichael Klier 3223a1dad2dSDennis Ploeger return 0; 323beccd742SMichael Klier } 3243a1dad2dSDennis Ploeger 325beccd742SMichael Klier /** 3262aca132fSMichael Klier * Uploads a file to the wiki. 3272aca132fSMichael Klier * 3282aca132fSMichael Klier * Michael Klier <chi@chimeric.de> 3292aca132fSMichael Klier */ 3302aca132fSMichael Klier function putAttachment($ns, $file, $params) { 3312aca132fSMichael Klier global $conf; 3322aca132fSMichael Klier global $lang; 3332aca132fSMichael Klier 3342aca132fSMichael Klier $auth = auth_quickaclcheck($ns.':*'); 3352aca132fSMichael Klier if($auth >= AUTH_UPLOAD) { 3362aca132fSMichael Klier if(!isset($params['name'])) { 3372aca132fSMichael Klier return new IXR_ERROR(1, 'Filename not given.'); 3382aca132fSMichael Klier } 3392aca132fSMichael Klier 3402aca132fSMichael Klier $ftmp = $conf['tmpdir'] . '/' . $params['name']; 3412aca132fSMichael Klier $name = $params['name']; 3422aca132fSMichael Klier 3432aca132fSMichael Klier // save temporary file 3442aca132fSMichael Klier @unlink($ftmp); 3452aca132fSMichael Klier $buff = base64_decode($file); 3462aca132fSMichael Klier io_saveFile($ftmp, $buff); 3472aca132fSMichael Klier 3482aca132fSMichael Klier // get filename 3492aca132fSMichael Klier list($iext, $imime) = mimetype($name); 3502aca132fSMichael Klier $id = cleanID($ns.':'.$name); 3512aca132fSMichael Klier $fn = mediaFN($id); 3522aca132fSMichael Klier 3532aca132fSMichael Klier // get filetype regexp 3542aca132fSMichael Klier $types = array_keys(getMimeTypes()); 3552aca132fSMichael Klier $types = array_map(create_function('$q','return preg_quote($q,"/");'),$types); 3562aca132fSMichael Klier $regex = join('|',$types); 3572aca132fSMichael Klier 3582aca132fSMichael Klier // because a temp file was created already 3592aca132fSMichael Klier if(preg_match('/\.('.$regex.')$/i',$fn)) { 3602aca132fSMichael Klier //check for overwrite 3612aca132fSMichael Klier if(@file_exists($fn) && (!$params['ow'] || $auth < AUTH_DELETE)) { 3622aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadexist']); 3632aca132fSMichael Klier } 3642aca132fSMichael Klier // check for valid content 3652aca132fSMichael Klier @require_once(DOKU_INC.'inc/media.php'); 3662aca132fSMichael Klier $ok = media_contentcheck($ftmp, $imime); 3672aca132fSMichael Klier if($ok == -1) { 3682aca132fSMichael Klier return new IXR_ERROR(1, sprintf($lang['uploadexist'], ".$iext")); 3692aca132fSMichael Klier } elseif($ok == -2) { 3702aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadspam']); 3712aca132fSMichael Klier } elseif($ok == -3) { 3722aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadxss']); 3732aca132fSMichael Klier } 3742aca132fSMichael Klier 3752aca132fSMichael Klier // prepare event data 3762aca132fSMichael Klier $data[0] = $ftmp; 3772aca132fSMichael Klier $data[1] = $fn; 3782aca132fSMichael Klier $data[2] = $id; 3792aca132fSMichael Klier $data[3] = $imime; 3802aca132fSMichael Klier 3812aca132fSMichael Klier // trigger event 3822aca132fSMichael Klier require_once(DOKU_INC.'inc/events.php'); 3832aca132fSMichael Klier return trigger_event('MEDIA_UPLOAD_FINISH', $data, array($this, '_media_upload_action'), true); 3842aca132fSMichael Klier 3852aca132fSMichael Klier } else { 3862aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadwrong']); 3872aca132fSMichael Klier } 3882aca132fSMichael Klier } else { 3892aca132fSMichael Klier return new IXR_ERROR(1, "You don't have permissions to upload files."); 3902aca132fSMichael Klier } 3912aca132fSMichael Klier } 3922aca132fSMichael Klier 3932aca132fSMichael Klier /** 3942aca132fSMichael Klier * Moves the temporary file to its final destination. 3952aca132fSMichael Klier * 3962aca132fSMichael Klier * Michael Klier <chi@chimeric.de> 3972aca132fSMichael Klier */ 3982aca132fSMichael Klier function _media_upload_action($data) { 3992aca132fSMichael Klier global $conf; 4002aca132fSMichael Klier 4012aca132fSMichael Klier if(is_array($data) && count($data)===4) { 4022aca132fSMichael Klier io_createNamespace($data[2], 'media'); 4032aca132fSMichael Klier if(rename($data[0], $data[1])) { 4042aca132fSMichael Klier chmod($data[1], $conf['fmode']); 4052aca132fSMichael Klier media_notify($data[2], $data[1], $data[3]); 4062aca132fSMichael Klier return $data[2]; 4072aca132fSMichael Klier } else { 4082aca132fSMichael Klier return new IXR_ERROR(1, 'Upload failed.'); 4092aca132fSMichael Klier } 4102aca132fSMichael Klier } else { 4112aca132fSMichael Klier return new IXR_ERROR(1, 'Upload failed.'); 4122aca132fSMichael Klier } 4132aca132fSMichael Klier } 4142aca132fSMichael Klier 4152aca132fSMichael Klier /** 416e62b9ea5SMichael Klier * Returns the permissions of a given wiki page 417e62b9ea5SMichael Klier */ 418e62b9ea5SMichael Klier function aclCheck($id) { 419e62b9ea5SMichael Klier return auth_quickaclcheck($id); 420e62b9ea5SMichael Klier } 421e62b9ea5SMichael Klier 422e62b9ea5SMichael Klier /** 423beccd742SMichael Klier * Lists all links contained in a wiki page 42463dd0d58SMichael Klier * 42563dd0d58SMichael Klier * @author Michael Klier <chi@chimeric.de> 426beccd742SMichael Klier */ 427beccd742SMichael Klier function listLinks($id) { 428beccd742SMichael Klier if(auth_quickaclcheck($id) < AUTH_READ){ 429beccd742SMichael Klier return new IXR_Error(1, 'You are not allowed to read this page'); 430beccd742SMichael Klier } 431beccd742SMichael Klier $links = array(); 432beccd742SMichael Klier 433beccd742SMichael Klier // resolve page instructions 434beccd742SMichael Klier $ins = p_cached_instructions(wikiFN(cleanID($id))); 435beccd742SMichael Klier 436beccd742SMichael Klier // instantiate new Renderer - needed for interwiki links 437beccd742SMichael Klier include(DOKU_INC.'inc/parser/xhtml.php'); 438beccd742SMichael Klier $Renderer = new Doku_Renderer_xhtml(); 439beccd742SMichael Klier $Renderer->interwiki = getInterwiki(); 440beccd742SMichael Klier 441beccd742SMichael Klier // parse parse instructions 442beccd742SMichael Klier foreach($ins as $in) { 443beccd742SMichael Klier $link = array(); 444beccd742SMichael Klier switch($in[0]) { 445beccd742SMichael Klier case 'internallink': 446beccd742SMichael Klier $link['type'] = 'local'; 447beccd742SMichael Klier $link['page'] = $in[1][0]; 448beccd742SMichael Klier $link['href'] = wl($in[1][0]); 449beccd742SMichael Klier array_push($links,$link); 450beccd742SMichael Klier break; 451beccd742SMichael Klier case 'externallink': 452beccd742SMichael Klier $link['type'] = 'extern'; 453beccd742SMichael Klier $link['page'] = $in[1][0]; 454beccd742SMichael Klier $link['href'] = $in[1][0]; 455beccd742SMichael Klier array_push($links,$link); 456beccd742SMichael Klier break; 457beccd742SMichael Klier case 'interwikilink': 458beccd742SMichael Klier $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]); 459beccd742SMichael Klier $link['type'] = 'extern'; 460beccd742SMichael Klier $link['page'] = $url; 461beccd742SMichael Klier $link['href'] = $url; 462beccd742SMichael Klier array_push($links,$link); 463beccd742SMichael Klier break; 464beccd742SMichael Klier } 465beccd742SMichael Klier } 466beccd742SMichael Klier 46763dd0d58SMichael Klier return ($links); 46863dd0d58SMichael Klier } 46963dd0d58SMichael Klier 47063dd0d58SMichael Klier /** 47163dd0d58SMichael Klier * Returns a list of recent changes since give timestamp 47263dd0d58SMichael Klier * 47363dd0d58SMichael Klier * @author Michael Klier <chi@chimeric.de> 47463dd0d58SMichael Klier */ 47563dd0d58SMichael Klier function getRecentChanges($timestamp) { 47663dd0d58SMichael Klier global $conf; 47763dd0d58SMichael Klier 47863dd0d58SMichael Klier if(strlen($timestamp) != 10) 47963dd0d58SMichael Klier return new IXR_Error(20, 'The provided value is not a valid timestamp'); 48063dd0d58SMichael Klier 48163dd0d58SMichael Klier $changes = array(); 48263dd0d58SMichael Klier 48363dd0d58SMichael Klier require_once(DOKU_INC.'inc/changelog.php'); 48463dd0d58SMichael Klier require_once(DOKU_INC.'inc/pageutils.php'); 48563dd0d58SMichael Klier 48663dd0d58SMichael Klier // read changes 48763dd0d58SMichael Klier $lines = @file($conf['changelog']); 48863dd0d58SMichael Klier 48963dd0d58SMichael Klier if(empty($lines)) 49063dd0d58SMichael Klier return new IXR_Error(10, 'The changelog could not be read'); 49163dd0d58SMichael Klier 49263dd0d58SMichael Klier // we start searching at the end of the list 49363dd0d58SMichael Klier $lines = array_reverse($lines); 49463dd0d58SMichael Klier 49563dd0d58SMichael Klier // cache seen pages and skip them 49663dd0d58SMichael Klier $seen = array(); 49763dd0d58SMichael Klier 49863dd0d58SMichael Klier foreach($lines as $line) { 49963dd0d58SMichael Klier 50063dd0d58SMichael Klier if(empty($line)) continue; // skip empty lines 50163dd0d58SMichael Klier 50263dd0d58SMichael Klier $logline = parseChangelogLine($line); 50363dd0d58SMichael Klier 50463dd0d58SMichael Klier if($logline === false) continue; 50563dd0d58SMichael Klier 50663dd0d58SMichael Klier // skip seen ones 50763dd0d58SMichael Klier if(isset($seen[$logline['id']])) continue; 50863dd0d58SMichael Klier 50963dd0d58SMichael Klier // skip minors 51063dd0d58SMichael Klier if($logline['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT && ($flags & RECENTS_SKIP_MINORS)) continue; 51163dd0d58SMichael Klier 51263dd0d58SMichael Klier // remember in seen to skip additional sights 51363dd0d58SMichael Klier $seen[$logline['id']] = 1; 51463dd0d58SMichael Klier 51563dd0d58SMichael Klier // check if it's a hidden page 51663dd0d58SMichael Klier if(isHiddenPage($logline['id'])) continue; 51763dd0d58SMichael Klier 51863dd0d58SMichael Klier // check ACL 51963dd0d58SMichael Klier if(auth_quickaclcheck($logline['id']) < AUTH_READ) continue; 52063dd0d58SMichael Klier 52163dd0d58SMichael Klier // check existance 52263dd0d58SMichael Klier if((!@file_exists(wikiFN($logline['id']))) && ($flags & RECENTS_SKIP_DELETED)) continue; 52363dd0d58SMichael Klier 52463dd0d58SMichael Klier // check if logline is still in the queried time frame 52563dd0d58SMichael Klier if($logline['date'] >= $timestamp) { 52663dd0d58SMichael Klier $change['name'] = $logline['id']; 527610b2ab1SMichael Klier $change['lastModified'] = new IXR_Date($logline['date']); 52863dd0d58SMichael Klier $change['author'] = $logline['user']; 52963dd0d58SMichael Klier $change['version'] = $logline['date']; 53063dd0d58SMichael Klier array_push($changes, $change); 53163dd0d58SMichael Klier } else { 53263dd0d58SMichael Klier $changes = array_reverse($changes); 53363dd0d58SMichael Klier return ($changes); 53463dd0d58SMichael Klier } 53563dd0d58SMichael Klier } 53663dd0d58SMichael Klier // in case we still have nothing at this point 53763dd0d58SMichael Klier return new IXR_Error(30, 'There are no changes in the specified timeframe'); 5383a1dad2dSDennis Ploeger } 5393a1dad2dSDennis Ploeger 5403a1dad2dSDennis Ploeger /** 54173056168SMichael Klier * Returns a list of available revisions of a given wiki page 54273056168SMichael Klier * 54373056168SMichael Klier * @author Michael Klier <chi@chimeric.de> 54473056168SMichael Klier */ 54573056168SMichael Klier function pageVersions($id, $first) { 54673056168SMichael Klier global $conf; 54773056168SMichael Klier 54873056168SMichael Klier $versions = array(); 54973056168SMichael Klier 55073056168SMichael Klier if(empty($id)) 55173056168SMichael Klier return new IXR_Error(1, 'Empty page ID'); 55273056168SMichael Klier 55373056168SMichael Klier require_once(DOKU_INC.'inc/changelog.php'); 55473056168SMichael Klier 55573056168SMichael Klier $revisions = getRevisions($id, $first, $conf['recent']+1); 55673056168SMichael Klier 55773056168SMichael Klier if(count($revisions)==0 && $first!=0) { 55873056168SMichael Klier $first=0; 55973056168SMichael Klier $revisions = getRevisions($id, $first, $conf['recent']+1); 56073056168SMichael Klier } 56173056168SMichael Klier 56245c63471SMichael Klier if(count($revisions)>0 && $first==0) { 56345c63471SMichael Klier array_unshift($revisions, ''); // include current revision 56445c63471SMichael Klier array_pop($revisions); // remove extra log entry 56545c63471SMichael Klier } 56645c63471SMichael Klier 56773056168SMichael Klier $hasNext = false; 56873056168SMichael Klier if(count($revisions)>$conf['recent']) { 56973056168SMichael Klier $hasNext = true; 57073056168SMichael Klier array_pop($revisions); // remove extra log entry 57173056168SMichael Klier } 57273056168SMichael Klier 57373056168SMichael Klier if(!empty($revisions)) { 57473056168SMichael Klier foreach($revisions as $rev) { 57573056168SMichael Klier $file = wikiFN($id,$rev); 57673056168SMichael Klier $time = @filemtime($file); 57745c63471SMichael Klier // we check if the page actually exists, if this is not the 57845c63471SMichael Klier // case this can lead to less pages being returned than 57945c63471SMichael Klier // specified via $conf['recent'] 58073056168SMichael Klier if($time){ 58173056168SMichael Klier $info = getRevisionInfo($id, $time, 1024); 58273056168SMichael Klier if(!empty($info)) { 58373056168SMichael Klier $data['user'] = $info['user']; 58473056168SMichael Klier $data['ip'] = $info['ip']; 58573056168SMichael Klier $data['type'] = $info['type']; 58673056168SMichael Klier $data['sum'] = $info['sum']; 58773056168SMichael Klier $data['modified'] = new IXR_Date($info['date']); 58873056168SMichael Klier $data['version'] = $info['date']; 58973056168SMichael Klier array_push($versions, $data); 59073056168SMichael Klier } 59173056168SMichael Klier } 59273056168SMichael Klier } 59373056168SMichael Klier return $versions; 59473056168SMichael Klier } else { 59573056168SMichael Klier return array(); 59673056168SMichael Klier } 59773056168SMichael Klier } 59873056168SMichael Klier 59973056168SMichael Klier /** 600797c0d11SAndreas Gohr * The version of Wiki RPC API supported 601797c0d11SAndreas Gohr */ 602797c0d11SAndreas Gohr function wiki_RPCVersion(){ 603797c0d11SAndreas Gohr return 2; 604797c0d11SAndreas Gohr } 605797c0d11SAndreas Gohr} 606797c0d11SAndreas Gohr 607797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server(); 608797c0d11SAndreas Gohr 6092aca132fSMichael Klier// vim:ts=4:sw=4:et:enc=utf-8: 610