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 7445e8084SAndreas Gohr/** 8445e8084SAndreas Gohr * Increased whenever the API is changed 9445e8084SAndreas Gohr */ 10*f71f4f53SAndreas Gohrdefine('DOKU_XMLRPC_API_VERSION',3); 11797c0d11SAndreas Gohr 12797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php'); 13797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/common.php'); 14797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/auth.php'); 15797c0d11SAndreas Gohrsession_write_close(); //close session 16593bf8f6SMichael Klier 173ee5b583SAndreas Gohrif(!$conf['xmlrpc']) die('XML-RPC server not enabled.'); 18593bf8f6SMichael Klier 19797c0d11SAndreas Gohrrequire_once(DOKU_INC.'inc/IXR_Library.php'); 20797c0d11SAndreas Gohr 21797c0d11SAndreas Gohr 22797c0d11SAndreas Gohr/** 23797c0d11SAndreas Gohr * Contains needed wrapper functions and registers all available 24797c0d11SAndreas Gohr * XMLRPC functions. 25797c0d11SAndreas Gohr */ 26797c0d11SAndreas Gohrclass dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { 27797c0d11SAndreas Gohr var $methods = array(); 283ee5b583SAndreas Gohr var $public_methods = array(); 293ee5b583SAndreas Gohr 303ee5b583SAndreas Gohr /** 313ee5b583SAndreas Gohr * Checks if the current user is allowed to execute non anonymous methods 323ee5b583SAndreas Gohr */ 333ee5b583SAndreas Gohr function checkAuth(){ 343ee5b583SAndreas Gohr global $conf; 353ee5b583SAndreas Gohr global $USERINFO; 363ee5b583SAndreas Gohr 373ee5b583SAndreas Gohr if(!$conf['useacl']) return true; //no ACL - then no checks 383ee5b583SAndreas Gohr 393ee5b583SAndreas Gohr $allowed = explode(',',$conf['xmlrpcuser']); 403ee5b583SAndreas Gohr $allowed = array_map('trim', $allowed); 413ee5b583SAndreas Gohr $allowed = array_unique($allowed); 423ee5b583SAndreas Gohr $allowed = array_filter($allowed); 433ee5b583SAndreas Gohr 443ee5b583SAndreas Gohr if(!count($allowed)) return true; //no restrictions 453ee5b583SAndreas Gohr 463ee5b583SAndreas Gohr $user = $_SERVER['REMOTE_USER']; 473ee5b583SAndreas Gohr $groups = (array) $USERINFO['grps']; 483ee5b583SAndreas Gohr 493ee5b583SAndreas Gohr if(in_array($user,$allowed)) return true; //user explicitly mentioned 503ee5b583SAndreas Gohr 513ee5b583SAndreas Gohr //check group memberships 523ee5b583SAndreas Gohr foreach($groups as $group){ 533ee5b583SAndreas Gohr if(in_array('@'.$group,$allowed)) return true; 543ee5b583SAndreas Gohr } 553ee5b583SAndreas Gohr 563ee5b583SAndreas Gohr //still here? no access! 573ee5b583SAndreas Gohr return false; 583ee5b583SAndreas Gohr } 593ee5b583SAndreas Gohr 603ee5b583SAndreas Gohr /** 613ee5b583SAndreas Gohr * Adds a callback, extends parent method 623ee5b583SAndreas Gohr * 633ee5b583SAndreas Gohr * add another parameter to define if anonymous access to 643ee5b583SAndreas Gohr * this method should be granted. 653ee5b583SAndreas Gohr */ 663ee5b583SAndreas Gohr function addCallback($method, $callback, $args, $help, $public=false){ 673ee5b583SAndreas Gohr if($public) $this->public_methods[] = $method; 683ee5b583SAndreas Gohr return parent::addCallback($method, $callback, $args, $help); 693ee5b583SAndreas Gohr } 703ee5b583SAndreas Gohr 713ee5b583SAndreas Gohr /** 723ee5b583SAndreas Gohr * Execute a call, extends parent method 733ee5b583SAndreas Gohr * 743ee5b583SAndreas Gohr * Checks for authentication first 753ee5b583SAndreas Gohr */ 763ee5b583SAndreas Gohr function call($methodname, $args){ 773ee5b583SAndreas Gohr if(!in_array($methodname,$this->public_methods) && !$this->checkAuth()){ 783ee5b583SAndreas Gohr return new IXR_Error(-32603, 'server error. not authorized to call method "'.$methodname.'".'); 793ee5b583SAndreas Gohr } 803ee5b583SAndreas Gohr return parent::call($methodname, $args); 813ee5b583SAndreas Gohr } 82797c0d11SAndreas Gohr 83797c0d11SAndreas Gohr /** 84797c0d11SAndreas Gohr * Constructor. Register methods and run Server 85797c0d11SAndreas Gohr */ 86797c0d11SAndreas Gohr function dokuwiki_xmlrpc_server(){ 87797c0d11SAndreas Gohr $this->IXR_IntrospectionServer(); 88797c0d11SAndreas Gohr 89797c0d11SAndreas Gohr /* DokuWiki's own methods */ 90797c0d11SAndreas Gohr $this->addCallback( 91445e8084SAndreas Gohr 'dokuwiki.getXMLRPCAPIVersion', 92445e8084SAndreas Gohr 'this:getAPIVersion', 93445e8084SAndreas Gohr array('integer'), 943ee5b583SAndreas Gohr 'Returns the XMLRPC API version.', 953ee5b583SAndreas Gohr true 96445e8084SAndreas Gohr ); 97445e8084SAndreas Gohr 98445e8084SAndreas Gohr $this->addCallback( 99797c0d11SAndreas Gohr 'dokuwiki.getVersion', 100797c0d11SAndreas Gohr 'getVersion', 101797c0d11SAndreas Gohr array('string'), 1023ee5b583SAndreas Gohr 'Returns the running DokuWiki version.', 1033ee5b583SAndreas Gohr true 104797c0d11SAndreas Gohr ); 105797c0d11SAndreas Gohr 1061b11c097SAndreas Gohr $this->addCallback( 107445e8084SAndreas Gohr 'dokuwiki.login', 108445e8084SAndreas Gohr 'this:login', 109445e8084SAndreas Gohr array('integer','string','string'), 1103ee5b583SAndreas Gohr 'Tries to login with the given credentials and sets auth cookies.', 1113ee5b583SAndreas Gohr true 112445e8084SAndreas Gohr ); 113445e8084SAndreas Gohr 114445e8084SAndreas Gohr $this->addCallback( 1151b11c097SAndreas Gohr 'dokuwiki.getPagelist', 1161b11c097SAndreas Gohr 'this:readNamespace', 1171b11c097SAndreas Gohr array('struct','string','struct'), 1181b11c097SAndreas Gohr 'List all pages within the given namespace.' 1191b11c097SAndreas Gohr ); 1201b11c097SAndreas Gohr 1211b11c097SAndreas Gohr $this->addCallback( 122*f71f4f53SAndreas Gohr 'dokuwiki.search', 123*f71f4f53SAndreas Gohr 'this:search', 124*f71f4f53SAndreas Gohr array('struct','string'), 125*f71f4f53SAndreas Gohr 'Perform a fulltext search and return a list of matching pages' 126*f71f4f53SAndreas Gohr ); 127*f71f4f53SAndreas Gohr 128*f71f4f53SAndreas Gohr $this->addCallback( 1291b11c097SAndreas Gohr 'dokuwiki.getTime', 1301b11c097SAndreas Gohr 'time', 1311b11c097SAndreas Gohr array('int'), 1321b11c097SAndreas Gohr 'Return the current time at the wiki server.' 1331b11c097SAndreas Gohr ); 1341b11c097SAndreas Gohr 13528ec3c76SAndreas Gohr $this->addCallback( 13628ec3c76SAndreas Gohr 'dokuwiki.setLocks', 13728ec3c76SAndreas Gohr 'this:setLocks', 13828ec3c76SAndreas Gohr array('struct','struct'), 13928ec3c76SAndreas Gohr 'Lock or unlock pages.' 14028ec3c76SAndreas Gohr ); 14128ec3c76SAndreas Gohr 142797c0d11SAndreas Gohr /* Wiki API v2 http://www.jspwiki.org/wiki/WikiRPCInterface2 */ 143797c0d11SAndreas Gohr $this->addCallback( 144797c0d11SAndreas Gohr 'wiki.getRPCVersionSupported', 145797c0d11SAndreas Gohr 'this:wiki_RPCVersion', 146797c0d11SAndreas Gohr array('int'), 1473ee5b583SAndreas Gohr 'Returns 2 with the supported RPC API version.', 1483ee5b583SAndreas Gohr true 149797c0d11SAndreas Gohr ); 150797c0d11SAndreas Gohr $this->addCallback( 151797c0d11SAndreas Gohr 'wiki.getPage', 152797c0d11SAndreas Gohr 'this:rawPage', 153797c0d11SAndreas Gohr array('string','string'), 154797c0d11SAndreas Gohr 'Get the raw Wiki text of page, latest version.' 155797c0d11SAndreas Gohr ); 156797c0d11SAndreas Gohr $this->addCallback( 157797c0d11SAndreas Gohr 'wiki.getPageVersion', 158797c0d11SAndreas Gohr 'this:rawPage', 159797c0d11SAndreas Gohr array('string','string','int'), 160797c0d11SAndreas Gohr 'Get the raw Wiki text of page.' 161797c0d11SAndreas Gohr ); 162797c0d11SAndreas Gohr $this->addCallback( 163797c0d11SAndreas Gohr 'wiki.getPageHTML', 164797c0d11SAndreas Gohr 'this:htmlPage', 165797c0d11SAndreas Gohr array('string','string'), 166797c0d11SAndreas Gohr 'Return page in rendered HTML, latest version.' 167797c0d11SAndreas Gohr ); 168797c0d11SAndreas Gohr $this->addCallback( 169797c0d11SAndreas Gohr 'wiki.getPageHTMLVersion', 170797c0d11SAndreas Gohr 'this:htmlPage', 171797c0d11SAndreas Gohr array('string','string','int'), 172797c0d11SAndreas Gohr 'Return page in rendered HTML.' 173797c0d11SAndreas Gohr ); 174797c0d11SAndreas Gohr $this->addCallback( 175797c0d11SAndreas Gohr 'wiki.getAllPages', 176797c0d11SAndreas Gohr 'this:listPages', 177797c0d11SAndreas Gohr array('struct'), 178797c0d11SAndreas Gohr 'Returns a list of all pages. The result is an array of utf8 pagenames.' 179797c0d11SAndreas Gohr ); 180797c0d11SAndreas Gohr $this->addCallback( 18126bec61eSMichael Klier 'wiki.getAttachments', 18226bec61eSMichael Klier 'this:listAttachments', 183c63d1645SGina Haeussge array('struct', 'string', 'struct'), 18426bec61eSMichael Klier 'Returns a list of all media files.' 18526bec61eSMichael Klier ); 18626bec61eSMichael Klier $this->addCallback( 187797c0d11SAndreas Gohr 'wiki.getBackLinks', 188797c0d11SAndreas Gohr 'this:listBackLinks', 189797c0d11SAndreas Gohr array('struct','string'), 190797c0d11SAndreas Gohr 'Returns the pages that link to this page.' 191797c0d11SAndreas Gohr ); 192797c0d11SAndreas Gohr $this->addCallback( 193797c0d11SAndreas Gohr 'wiki.getPageInfo', 194797c0d11SAndreas Gohr 'this:pageInfo', 195797c0d11SAndreas Gohr array('struct','string'), 196797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 197797c0d11SAndreas Gohr ); 198797c0d11SAndreas Gohr $this->addCallback( 199797c0d11SAndreas Gohr 'wiki.getPageInfoVersion', 200797c0d11SAndreas Gohr 'this:pageInfo', 201797c0d11SAndreas Gohr array('struct','string','int'), 202797c0d11SAndreas Gohr 'Returns a struct with infos about the page.' 203797c0d11SAndreas Gohr ); 2043a1dad2dSDennis Ploeger $this->addCallback( 20573056168SMichael Klier 'wiki.getPageVersions', 20673056168SMichael Klier 'this:pageVersions', 20773056168SMichael Klier array('struct','string','int'), 20873056168SMichael Klier 'Returns the available revisions of the page.' 20973056168SMichael Klier ); 21073056168SMichael Klier $this->addCallback( 2113a1dad2dSDennis Ploeger 'wiki.putPage', 2123a1dad2dSDennis Ploeger 'this:putPage', 213222572bfSMichael Klier array('int', 'string', 'string', 'struct'), 214fdd2e9d6SMichael Klier 'Saves a wiki page.' 2153a1dad2dSDennis Ploeger ); 216beccd742SMichael Klier $this->addCallback( 217beccd742SMichael Klier 'wiki.listLinks', 218beccd742SMichael Klier 'this:listLinks', 219beccd742SMichael Klier array('struct','string'), 220fdd2e9d6SMichael Klier 'Lists all links contained in a wiki page.' 221beccd742SMichael Klier ); 22263dd0d58SMichael Klier $this->addCallback( 22363dd0d58SMichael Klier 'wiki.getRecentChanges', 22463dd0d58SMichael Klier 'this:getRecentChanges', 22563dd0d58SMichael Klier array('struct','int'), 22699c8d7f2Smichael 'Returns a struct about all recent changes since given timestamp.' 22799c8d7f2Smichael ); 22899c8d7f2Smichael $this->addCallback( 22999c8d7f2Smichael 'wiki.getRecentMediaChanges', 23099c8d7f2Smichael 'this:getRecentMediaChanges', 23199c8d7f2Smichael array('struct','int'), 23299c8d7f2Smichael 'Returns a struct about all recent media changes since given timestamp.' 23363dd0d58SMichael Klier ); 234e62b9ea5SMichael Klier $this->addCallback( 235e62b9ea5SMichael Klier 'wiki.aclCheck', 236e62b9ea5SMichael Klier 'this:aclCheck', 237c63d1645SGina Haeussge array('int', 'string'), 238e62b9ea5SMichael Klier 'Returns the permissions of a given wiki page.' 239e62b9ea5SMichael Klier ); 2402aca132fSMichael Klier $this->addCallback( 2412aca132fSMichael Klier 'wiki.putAttachment', 2422aca132fSMichael Klier 'this:putAttachment', 2432aca132fSMichael Klier array('struct', 'string', 'base64', 'struct'), 2442aca132fSMichael Klier 'Upload a file to the wiki.' 2452aca132fSMichael Klier ); 246cfef3001SGina Haeussge $this->addCallback( 247f01ff8c1SGina Haeussge 'wiki.deleteAttachment', 248f01ff8c1SGina Haeussge 'this:deleteAttachment', 249f01ff8c1SGina Haeussge array('int', 'string'), 250f01ff8c1SGina Haeussge 'Delete a file from the wiki.' 251f01ff8c1SGina Haeussge ); 252f01ff8c1SGina Haeussge $this->addCallback( 253cfef3001SGina Haeussge 'wiki.getAttachment', 254cfef3001SGina Haeussge 'this:getAttachment', 255c63d1645SGina Haeussge array('base64', 'string'), 256cfef3001SGina Haeussge 'Download a file from the wiki.' 257cfef3001SGina Haeussge ); 2585672e868SGina Haeussge $this->addCallback( 2595672e868SGina Haeussge 'wiki.getAttachmentInfo', 2605672e868SGina Haeussge 'this:getAttachmentInfo', 261c63d1645SGina Haeussge array('struct', 'string'), 2625672e868SGina Haeussge 'Returns a struct with infos about the attachment.' 2635672e868SGina Haeussge ); 264797c0d11SAndreas Gohr 265bb32615dSMichael Klier /** 266bb32615dSMichael Klier * Trigger XMLRPC_CALLBACK_REGISTER, action plugins can use this event 267bb32615dSMichael Klier * to extend the XMLRPC interface and register their own callbacks. 268bb32615dSMichael Klier * 269bb32615dSMichael Klier * Event data: 270bb32615dSMichael Klier * The XMLRPC server object: 271bb32615dSMichael Klier * 272bb32615dSMichael Klier * $event->data->addCallback() - register a callback, the second 273bb32615dSMichael Klier * paramter has to be of the form "plugin:<pluginname>:<plugin 274bb32615dSMichael Klier * method>" 275bb32615dSMichael Klier * 276bb32615dSMichael Klier * $event->data->callbacks - an array which holds all awaylable 277bb32615dSMichael Klier * callbacks 278bb32615dSMichael Klier */ 279bb32615dSMichael Klier trigger_event('XMLRPC_CALLBACK_REGISTER', $this); 280bb32615dSMichael Klier 281797c0d11SAndreas Gohr $this->serve(); 282797c0d11SAndreas Gohr } 283797c0d11SAndreas Gohr 284797c0d11SAndreas Gohr /** 285797c0d11SAndreas Gohr * Return a raw wiki page 286797c0d11SAndreas Gohr */ 287797c0d11SAndreas Gohr function rawPage($id,$rev=''){ 288797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 289797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 290797c0d11SAndreas Gohr } 2912c176304SMichael Klier $text = rawWiki($id,$rev); 2922c176304SMichael Klier if(!$text) { 2932c176304SMichael Klier $data = array($id); 2942c176304SMichael Klier return trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true); 2952c176304SMichael Klier } else { 2962c176304SMichael Klier return $text; 2972c176304SMichael Klier } 298797c0d11SAndreas Gohr } 299797c0d11SAndreas Gohr 300797c0d11SAndreas Gohr /** 301cfef3001SGina Haeussge * Return a media file encoded in base64 302c63d1645SGina Haeussge * 303c63d1645SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 304cfef3001SGina Haeussge */ 305cfef3001SGina Haeussge function getAttachment($id){ 306c63d1645SGina Haeussge $id = cleanID($id); 307cfef3001SGina Haeussge if (auth_quickaclcheck(getNS($id).':*') < AUTH_READ) 308cfef3001SGina Haeussge return new IXR_Error(1, 'You are not allowed to read this file'); 309cfef3001SGina Haeussge 310cfef3001SGina Haeussge $file = mediaFN($id); 311cfef3001SGina Haeussge if (!@ file_exists($file)) 312cfef3001SGina Haeussge return new IXR_Error(1, 'The requested file does not exist'); 313cfef3001SGina Haeussge 314cfef3001SGina Haeussge $data = io_readFile($file, false); 315cfef3001SGina Haeussge $base64 = base64_encode($data); 316cfef3001SGina Haeussge return $base64; 317cfef3001SGina Haeussge } 318cfef3001SGina Haeussge 319cfef3001SGina Haeussge /** 3205672e868SGina Haeussge * Return info about a media file 3215672e868SGina Haeussge * 3225672e868SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 3235672e868SGina Haeussge */ 3245672e868SGina Haeussge function getAttachmentInfo($id){ 3255672e868SGina Haeussge $id = cleanID($id); 3265672e868SGina Haeussge $info = array( 3275672e868SGina Haeussge 'lastModified' => 0, 3285672e868SGina Haeussge 'size' => 0, 3295672e868SGina Haeussge ); 3305672e868SGina Haeussge 3315672e868SGina Haeussge $file = mediaFN($id); 3325672e868SGina Haeussge if ((auth_quickaclcheck(getNS($id).':*') >= AUTH_READ) && file_exists($file)){ 3335672e868SGina Haeussge $info['lastModified'] = new IXR_Date(filemtime($file)); 3345672e868SGina Haeussge $info['size'] = filesize($file); 3355672e868SGina Haeussge } 3365672e868SGina Haeussge 3375672e868SGina Haeussge return $info; 3385672e868SGina Haeussge } 3395672e868SGina Haeussge 3405672e868SGina Haeussge /** 341797c0d11SAndreas Gohr * Return a wiki page rendered to html 342797c0d11SAndreas Gohr */ 343797c0d11SAndreas Gohr function htmlPage($id,$rev=''){ 344797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 345797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 346797c0d11SAndreas Gohr } 347797c0d11SAndreas Gohr return p_wiki_xhtml($id,$rev,false); 348797c0d11SAndreas Gohr } 349797c0d11SAndreas Gohr 350797c0d11SAndreas Gohr /** 351797c0d11SAndreas Gohr * List all pages - we use the indexer list here 352797c0d11SAndreas Gohr */ 353797c0d11SAndreas Gohr function listPages(){ 354dfd13e55SMichael Klier global $conf; 355dfd13e55SMichael Klier 356dfd13e55SMichael Klier $list = array(); 357dfd13e55SMichael Klier $pages = file($conf['indexdir'] . '/page.idx'); 358dfd13e55SMichael Klier $pages = array_filter($pages, 'isVisiblePage'); 359dfd13e55SMichael Klier 360dfd13e55SMichael Klier foreach(array_keys($pages) as $idx) { 361dfd13e55SMichael Klier if(page_exists($pages[$idx])) { 362dfd13e55SMichael Klier $perm = auth_quickaclcheck($pages[$idx]); 363dfd13e55SMichael Klier if($perm >= AUTH_READ) { 364dfd13e55SMichael Klier $page = array(); 365dfd13e55SMichael Klier $page['id'] = trim($pages[$idx]); 366dfd13e55SMichael Klier $page['perms'] = $perm; 367dfd13e55SMichael Klier $page['size'] = @filesize(wikiFN($pages[$idx])); 368e070c6f3SGina Haeussge $page['lastModified'] = new IXR_Date(@filemtime(wikiFN($pages[$idx]))); 369dfd13e55SMichael Klier $list[] = $page; 370dfd13e55SMichael Klier } 371dfd13e55SMichael Klier } 372dfd13e55SMichael Klier } 373dfd13e55SMichael Klier 374dfd13e55SMichael Klier return $list; 375797c0d11SAndreas Gohr } 376797c0d11SAndreas Gohr 377797c0d11SAndreas Gohr /** 3781b11c097SAndreas Gohr * List all pages in the given namespace (and below) 3791b11c097SAndreas Gohr */ 3801b11c097SAndreas Gohr function readNamespace($ns,$opts){ 3811b11c097SAndreas Gohr global $conf; 3821b11c097SAndreas Gohr 3831b11c097SAndreas Gohr if(!is_array($opts)) $opts=array(); 3841b11c097SAndreas Gohr 3851b11c097SAndreas Gohr $ns = cleanID($ns); 3861b11c097SAndreas Gohr $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 3871b11c097SAndreas Gohr $data = array(); 3881b11c097SAndreas Gohr require_once(DOKU_INC.'inc/search.php'); 3896fc3aa1aSAndreas Gohr $opts['skipacl'] = 0; // no ACL skipping for XMLRPC 3901b11c097SAndreas Gohr search($data, $conf['datadir'], 'search_allpages', $opts, $dir); 3911b11c097SAndreas Gohr return $data; 3921b11c097SAndreas Gohr } 3931b11c097SAndreas Gohr 3941b11c097SAndreas Gohr /** 395*f71f4f53SAndreas Gohr * List all pages in the given namespace (and below) 396*f71f4f53SAndreas Gohr */ 397*f71f4f53SAndreas Gohr function search($query){ 398*f71f4f53SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 399*f71f4f53SAndreas Gohr 400*f71f4f53SAndreas Gohr $regex = ''; 401*f71f4f53SAndreas Gohr $data = ft_pageSearch($query,$regex); 402*f71f4f53SAndreas Gohr $pages = array(); 403*f71f4f53SAndreas Gohr 404*f71f4f53SAndreas Gohr // prepare additional data 405*f71f4f53SAndreas Gohr $idx = 0; 406*f71f4f53SAndreas Gohr foreach($data as $id => $score){ 407*f71f4f53SAndreas Gohr $file = wikiFN($id); 408*f71f4f53SAndreas Gohr 409*f71f4f53SAndreas Gohr if($idx < FT_SNIPPET_NUMBER){ 410*f71f4f53SAndreas Gohr $snippet = ft_snippet($id,$regex); 411*f71f4f53SAndreas Gohr $idx++; 412*f71f4f53SAndreas Gohr }else{ 413*f71f4f53SAndreas Gohr $snippet = ''; 414*f71f4f53SAndreas Gohr } 415*f71f4f53SAndreas Gohr 416*f71f4f53SAndreas Gohr $pages[] = array( 417*f71f4f53SAndreas Gohr 'id' => $id, 418*f71f4f53SAndreas Gohr 'score' => $score, 419*f71f4f53SAndreas Gohr 'rev' => filemtime($file), 420*f71f4f53SAndreas Gohr 'mtime' => filemtime($file), 421*f71f4f53SAndreas Gohr 'size' => filesize($file), 422*f71f4f53SAndreas Gohr 'snippet' => $snippet, 423*f71f4f53SAndreas Gohr ); 424*f71f4f53SAndreas Gohr } 425*f71f4f53SAndreas Gohr return $data; 426*f71f4f53SAndreas Gohr } 427*f71f4f53SAndreas Gohr 428*f71f4f53SAndreas Gohr 429*f71f4f53SAndreas Gohr /** 43026bec61eSMichael Klier * List all media files. 4313275953aSGina Haeussge * 4323275953aSGina Haeussge * Available options are 'recursive' for also including the subnamespaces 4333275953aSGina Haeussge * in the listing, and 'pattern' for filtering the returned files against 4343275953aSGina Haeussge * a regular expression matching their name. 4353275953aSGina Haeussge * 4363275953aSGina Haeussge * @author Gina Haeussge <osd@foosel.net> 43726bec61eSMichael Klier */ 4383275953aSGina Haeussge function listAttachments($ns, $options = array()) { 43926bec61eSMichael Klier global $conf; 44026bec61eSMichael Klier global $lang; 44126bec61eSMichael Klier 44226bec61eSMichael Klier $ns = cleanID($ns); 44326bec61eSMichael Klier 4446fc3aa1aSAndreas Gohr if (!is_array($options)) $options = array(); 4456fc3aa1aSAndreas Gohr $options['skipacl'] = 0; // no ACL skipping for XMLRPC 4463275953aSGina Haeussge 4473275953aSGina Haeussge 44826bec61eSMichael Klier if(auth_quickaclcheck($ns.':*') >= AUTH_READ) { 44926bec61eSMichael Klier $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 45026bec61eSMichael Klier 45126bec61eSMichael Klier $data = array(); 45226bec61eSMichael Klier require_once(DOKU_INC.'inc/search.php'); 453224122cfSAndreas Gohr search($data, $conf['mediadir'], 'search_media', $options, $dir); 454224122cfSAndreas Gohr $len = count($data); 455224122cfSAndreas Gohr if(!$len) return array(); 45626bec61eSMichael Klier 457224122cfSAndreas Gohr for($i=0; $i<$len; $i++) { 458224122cfSAndreas Gohr unset($data[$i]['meta']); 459224122cfSAndreas Gohr $data[$i]['lastModified'] = new IXR_Date($data[$i]['mtime']); 46026bec61eSMichael Klier } 461224122cfSAndreas Gohr return $data; 46226bec61eSMichael Klier } else { 46326bec61eSMichael Klier return new IXR_Error(1, 'You are not allowed to list media files.'); 46426bec61eSMichael Klier } 46526bec61eSMichael Klier } 46626bec61eSMichael Klier 46726bec61eSMichael Klier /** 468797c0d11SAndreas Gohr * Return a list of backlinks 469797c0d11SAndreas Gohr */ 470beccd742SMichael Klier function listBackLinks($id){ 471797c0d11SAndreas Gohr require_once(DOKU_INC.'inc/fulltext.php'); 472797c0d11SAndreas Gohr return ft_backlinks($id); 473797c0d11SAndreas Gohr } 474797c0d11SAndreas Gohr 475797c0d11SAndreas Gohr /** 47663dd0d58SMichael Klier * Return some basic data about a page 477797c0d11SAndreas Gohr */ 478797c0d11SAndreas Gohr function pageInfo($id,$rev=''){ 479797c0d11SAndreas Gohr if(auth_quickaclcheck($id) < AUTH_READ){ 480797c0d11SAndreas Gohr return new IXR_Error(1, 'You are not allowed to read this page'); 481797c0d11SAndreas Gohr } 482797c0d11SAndreas Gohr $file = wikiFN($id,$rev); 483797c0d11SAndreas Gohr $time = @filemtime($file); 484797c0d11SAndreas Gohr if(!$time){ 485797c0d11SAndreas Gohr return new IXR_Error(10, 'The requested page does not exist'); 486797c0d11SAndreas Gohr } 487797c0d11SAndreas Gohr 488797c0d11SAndreas Gohr $info = getRevisionInfo($id, $time, 1024); 489797c0d11SAndreas Gohr 490797c0d11SAndreas Gohr $data = array( 491797c0d11SAndreas Gohr 'name' => $id, 492797c0d11SAndreas Gohr 'lastModified' => new IXR_Date($time), 493797c0d11SAndreas Gohr 'author' => (($info['user']) ? $info['user'] : $info['ip']), 494797c0d11SAndreas Gohr 'version' => $time 495797c0d11SAndreas Gohr ); 49663dd0d58SMichael Klier 49763dd0d58SMichael Klier return ($data); 498797c0d11SAndreas Gohr } 499797c0d11SAndreas Gohr 500797c0d11SAndreas Gohr /** 5013a1dad2dSDennis Ploeger * Save a wiki page 502222572bfSMichael Klier * 503222572bfSMichael Klier * @author Michael Klier <chi@chimeric.de> 5043a1dad2dSDennis Ploeger */ 505222572bfSMichael Klier function putPage($id, $text, $params) { 5063a1dad2dSDennis Ploeger global $TEXT; 507a6a229ceSMichael Klier global $lang; 508593bf8f6SMichael Klier global $conf; 5093a1dad2dSDennis Ploeger 510222572bfSMichael Klier $id = cleanID($id); 51156523eecSAndreas Gohr $TEXT = cleanText($text); 512222572bfSMichael Klier $sum = $params['sum']; 513222572bfSMichael Klier $minor = $params['minor']; 514222572bfSMichael Klier 515222572bfSMichael Klier if(empty($id)) 516fdd2e9d6SMichael Klier return new IXR_Error(1, 'Empty page ID'); 517222572bfSMichael Klier 51856523eecSAndreas Gohr if(!page_exists($id) && trim($TEXT) == '' ) { 51951597811SMichael Klier return new IXR_ERROR(1, 'Refusing to write an empty new wiki page'); 52051597811SMichael Klier } 52151597811SMichael Klier 522055b0144SChris Smith if(auth_quickaclcheck($id) < AUTH_EDIT) 523222572bfSMichael Klier return new IXR_Error(1, 'You are not allowed to edit this page'); 5243a1dad2dSDennis Ploeger 5253a1dad2dSDennis Ploeger // Check, if page is locked 526222572bfSMichael Klier if(checklock($id)) 527222572bfSMichael Klier return new IXR_Error(1, 'The page is currently locked'); 528222572bfSMichael Klier 529a6a229ceSMichael Klier // SPAM check 5303a1dad2dSDennis Ploeger if(checkwordblock()) 531222572bfSMichael Klier return new IXR_Error(1, 'Positive wordblock check'); 5323a1dad2dSDennis Ploeger 533a6a229ceSMichael Klier // autoset summary on new pages 534a6a229ceSMichael Klier if(!page_exists($id) && empty($sum)) { 535a6a229ceSMichael Klier $sum = $lang['created']; 536a6a229ceSMichael Klier } 537a6a229ceSMichael Klier 538a6a229ceSMichael Klier // autoset summary on deleted pages 539a6a229ceSMichael Klier if(page_exists($id) && empty($TEXT) && empty($sum)) { 540a6a229ceSMichael Klier $sum = $lang['deleted']; 541a6a229ceSMichael Klier } 542a6a229ceSMichael Klier 543222572bfSMichael Klier lock($id); 5443a1dad2dSDennis Ploeger 545222572bfSMichael Klier saveWikiText($id,$TEXT,$sum,$minor); 5463a1dad2dSDennis Ploeger 547222572bfSMichael Klier unlock($id); 5483a1dad2dSDennis Ploeger 549593bf8f6SMichael Klier // run the indexer if page wasn't indexed yet 550593bf8f6SMichael Klier if(!@file_exists(metaFN($id, '.indexed'))) { 551593bf8f6SMichael Klier // try to aquire a lock 552593bf8f6SMichael Klier $lock = $conf['lockdir'].'/_indexer.lock'; 553593bf8f6SMichael Klier while(!@mkdir($lock,$conf['dmode'])){ 554593bf8f6SMichael Klier usleep(50); 555593bf8f6SMichael Klier if(time()-@filemtime($lock) > 60*5){ 556593bf8f6SMichael Klier // looks like a stale lock - remove it 557593bf8f6SMichael Klier @rmdir($lock); 558593bf8f6SMichael Klier }else{ 559593bf8f6SMichael Klier return false; 560593bf8f6SMichael Klier } 561593bf8f6SMichael Klier } 562593bf8f6SMichael Klier if($conf['dperm']) chmod($lock, $conf['dperm']); 563593bf8f6SMichael Klier 564593bf8f6SMichael Klier require_once(DOKU_INC.'inc/indexer.php'); 565593bf8f6SMichael Klier 566593bf8f6SMichael Klier // do the work 567593bf8f6SMichael Klier idx_addPage($id); 568593bf8f6SMichael Klier 569593bf8f6SMichael Klier // we're finished - save and free lock 570593bf8f6SMichael Klier io_saveFile(metaFN($id,'.indexed'),INDEXER_VERSION); 571593bf8f6SMichael Klier @rmdir($lock); 572593bf8f6SMichael Klier } 573593bf8f6SMichael Klier 5743a1dad2dSDennis Ploeger return 0; 575beccd742SMichael Klier } 5763a1dad2dSDennis Ploeger 577beccd742SMichael Klier /** 5782aca132fSMichael Klier * Uploads a file to the wiki. 5792aca132fSMichael Klier * 5802aca132fSMichael Klier * Michael Klier <chi@chimeric.de> 5812aca132fSMichael Klier */ 582f01ff8c1SGina Haeussge function putAttachment($id, $file, $params) { 5832aca132fSMichael Klier global $conf; 5842aca132fSMichael Klier global $lang; 5852aca132fSMichael Klier 586f01ff8c1SGina Haeussge $auth = auth_quickaclcheck(getNS($id).':*'); 5872aca132fSMichael Klier if($auth >= AUTH_UPLOAD) { 588f01ff8c1SGina Haeussge if(!isset($id)) { 5892aca132fSMichael Klier return new IXR_ERROR(1, 'Filename not given.'); 5902aca132fSMichael Klier } 5912aca132fSMichael Klier 592f01ff8c1SGina Haeussge $ftmp = $conf['tmpdir'] . '/' . $id; 5932aca132fSMichael Klier 5942aca132fSMichael Klier // save temporary file 5952aca132fSMichael Klier @unlink($ftmp); 5962aca132fSMichael Klier $buff = base64_decode($file); 5972aca132fSMichael Klier io_saveFile($ftmp, $buff); 5982aca132fSMichael Klier 5992aca132fSMichael Klier // get filename 600ecebf3a8SAndreas Gohr list($iext, $imime,$dl) = mimetype($id); 601f01ff8c1SGina Haeussge $id = cleanID($id); 6022aca132fSMichael Klier $fn = mediaFN($id); 6032aca132fSMichael Klier 6042aca132fSMichael Klier // get filetype regexp 6052aca132fSMichael Klier $types = array_keys(getMimeTypes()); 6062aca132fSMichael Klier $types = array_map(create_function('$q','return preg_quote($q,"/");'),$types); 6072aca132fSMichael Klier $regex = join('|',$types); 6082aca132fSMichael Klier 6092aca132fSMichael Klier // because a temp file was created already 6102aca132fSMichael Klier if(preg_match('/\.('.$regex.')$/i',$fn)) { 6112aca132fSMichael Klier //check for overwrite 61299c8d7f2Smichael $overwrite = @file_exists($fn); 61399c8d7f2Smichael if($overwrite && (!$params['ow'] || $auth < AUTH_DELETE)) { 614224122cfSAndreas Gohr return new IXR_ERROR(1, $lang['uploadexist'].'1'); 6152aca132fSMichael Klier } 6162aca132fSMichael Klier // check for valid content 6172aca132fSMichael Klier @require_once(DOKU_INC.'inc/media.php'); 6182aca132fSMichael Klier $ok = media_contentcheck($ftmp, $imime); 6192aca132fSMichael Klier if($ok == -1) { 620224122cfSAndreas Gohr return new IXR_ERROR(1, sprintf($lang['uploadexist'].'2', ".$iext")); 6212aca132fSMichael Klier } elseif($ok == -2) { 6222aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadspam']); 6232aca132fSMichael Klier } elseif($ok == -3) { 6242aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadxss']); 6252aca132fSMichael Klier } 6262aca132fSMichael Klier 6272aca132fSMichael Klier // prepare event data 6282aca132fSMichael Klier $data[0] = $ftmp; 6292aca132fSMichael Klier $data[1] = $fn; 6302aca132fSMichael Klier $data[2] = $id; 6312aca132fSMichael Klier $data[3] = $imime; 63299c8d7f2Smichael $data[4] = $overwrite; 6332aca132fSMichael Klier 6342aca132fSMichael Klier // trigger event 6352aca132fSMichael Klier require_once(DOKU_INC.'inc/events.php'); 6362aca132fSMichael Klier return trigger_event('MEDIA_UPLOAD_FINISH', $data, array($this, '_media_upload_action'), true); 6372aca132fSMichael Klier 6382aca132fSMichael Klier } else { 6392aca132fSMichael Klier return new IXR_ERROR(1, $lang['uploadwrong']); 6402aca132fSMichael Klier } 6412aca132fSMichael Klier } else { 6422aca132fSMichael Klier return new IXR_ERROR(1, "You don't have permissions to upload files."); 6432aca132fSMichael Klier } 6442aca132fSMichael Klier } 6452aca132fSMichael Klier 6462aca132fSMichael Klier /** 647f01ff8c1SGina Haeussge * Deletes a file from the wiki. 648f01ff8c1SGina Haeussge * 649f01ff8c1SGina Haeussge * @author Gina Haeussge <osd@foosel.net> 650f01ff8c1SGina Haeussge */ 651f01ff8c1SGina Haeussge function deleteAttachment($id){ 652f01ff8c1SGina Haeussge $auth = auth_quickaclcheck(getNS($id).':*'); 653f01ff8c1SGina Haeussge if($auth < AUTH_DELETE) return new IXR_ERROR(1, "You don't have permissions to delete files."); 654f01ff8c1SGina Haeussge global $conf; 655f01ff8c1SGina Haeussge global $lang; 656f01ff8c1SGina Haeussge 657f01ff8c1SGina Haeussge // check for references if needed 658f01ff8c1SGina Haeussge $mediareferences = array(); 659f01ff8c1SGina Haeussge if($conf['refcheck']){ 660f01ff8c1SGina Haeussge require_once(DOKU_INC.'inc/fulltext.php'); 661f01ff8c1SGina Haeussge $mediareferences = ft_mediause($id,$conf['refshow']); 662f01ff8c1SGina Haeussge } 663f01ff8c1SGina Haeussge 664f01ff8c1SGina Haeussge if(!count($mediareferences)){ 665f01ff8c1SGina Haeussge $file = mediaFN($id); 666f01ff8c1SGina Haeussge if(@unlink($file)){ 66799c8d7f2Smichael require_once(DOKU_INC.'inc/changelog.php'); 66899c8d7f2Smichael addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_DELETE); 669f01ff8c1SGina Haeussge io_sweepNS($id,'mediadir'); 670f01ff8c1SGina Haeussge return 0; 671f01ff8c1SGina Haeussge } 672f01ff8c1SGina Haeussge //something went wrong 673f01ff8c1SGina Haeussge return new IXR_ERROR(1, 'Could not delete file'); 674f01ff8c1SGina Haeussge } else { 675f01ff8c1SGina Haeussge return new IXR_ERROR(1, 'File is still referenced'); 676f01ff8c1SGina Haeussge } 677f01ff8c1SGina Haeussge } 678f01ff8c1SGina Haeussge 679f01ff8c1SGina Haeussge /** 6802aca132fSMichael Klier * Moves the temporary file to its final destination. 6812aca132fSMichael Klier * 6822aca132fSMichael Klier * Michael Klier <chi@chimeric.de> 6832aca132fSMichael Klier */ 6842aca132fSMichael Klier function _media_upload_action($data) { 6852aca132fSMichael Klier global $conf; 6862aca132fSMichael Klier 68799c8d7f2Smichael if(is_array($data) && count($data)===5) { 6882aca132fSMichael Klier io_createNamespace($data[2], 'media'); 6892aca132fSMichael Klier if(rename($data[0], $data[1])) { 6902aca132fSMichael Klier chmod($data[1], $conf['fmode']); 6912aca132fSMichael Klier media_notify($data[2], $data[1], $data[3]); 69299c8d7f2Smichael // add a log entry to the media changelog 69399c8d7f2Smichael require_once(DOKU_INC.'inc/changelog.php'); 69499c8d7f2Smichael if ($data[4]) { 69599c8d7f2Smichael addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_EDIT); 69699c8d7f2Smichael } else { 69799c8d7f2Smichael addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_CREATE); 69899c8d7f2Smichael } 6992aca132fSMichael Klier return $data[2]; 7002aca132fSMichael Klier } else { 7012aca132fSMichael Klier return new IXR_ERROR(1, 'Upload failed.'); 7022aca132fSMichael Klier } 7032aca132fSMichael Klier } else { 7042aca132fSMichael Klier return new IXR_ERROR(1, 'Upload failed.'); 7052aca132fSMichael Klier } 7062aca132fSMichael Klier } 7072aca132fSMichael Klier 7082aca132fSMichael Klier /** 709e62b9ea5SMichael Klier * Returns the permissions of a given wiki page 710e62b9ea5SMichael Klier */ 711e62b9ea5SMichael Klier function aclCheck($id) { 712e62b9ea5SMichael Klier return auth_quickaclcheck($id); 713e62b9ea5SMichael Klier } 714e62b9ea5SMichael Klier 715e62b9ea5SMichael Klier /** 716beccd742SMichael Klier * Lists all links contained in a wiki page 71763dd0d58SMichael Klier * 71863dd0d58SMichael Klier * @author Michael Klier <chi@chimeric.de> 719beccd742SMichael Klier */ 720beccd742SMichael Klier function listLinks($id) { 721beccd742SMichael Klier if(auth_quickaclcheck($id) < AUTH_READ){ 722beccd742SMichael Klier return new IXR_Error(1, 'You are not allowed to read this page'); 723beccd742SMichael Klier } 724beccd742SMichael Klier $links = array(); 725beccd742SMichael Klier 726beccd742SMichael Klier // resolve page instructions 727beccd742SMichael Klier $ins = p_cached_instructions(wikiFN(cleanID($id))); 728beccd742SMichael Klier 729beccd742SMichael Klier // instantiate new Renderer - needed for interwiki links 730beccd742SMichael Klier include(DOKU_INC.'inc/parser/xhtml.php'); 731beccd742SMichael Klier $Renderer = new Doku_Renderer_xhtml(); 732beccd742SMichael Klier $Renderer->interwiki = getInterwiki(); 733beccd742SMichael Klier 734beccd742SMichael Klier // parse parse instructions 735beccd742SMichael Klier foreach($ins as $in) { 736beccd742SMichael Klier $link = array(); 737beccd742SMichael Klier switch($in[0]) { 738beccd742SMichael Klier case 'internallink': 739beccd742SMichael Klier $link['type'] = 'local'; 740beccd742SMichael Klier $link['page'] = $in[1][0]; 741beccd742SMichael Klier $link['href'] = wl($in[1][0]); 742beccd742SMichael Klier array_push($links,$link); 743beccd742SMichael Klier break; 744beccd742SMichael Klier case 'externallink': 745beccd742SMichael Klier $link['type'] = 'extern'; 746beccd742SMichael Klier $link['page'] = $in[1][0]; 747beccd742SMichael Klier $link['href'] = $in[1][0]; 748beccd742SMichael Klier array_push($links,$link); 749beccd742SMichael Klier break; 750beccd742SMichael Klier case 'interwikilink': 751beccd742SMichael Klier $url = $Renderer->_resolveInterWiki($in[1][2],$in[1][3]); 752beccd742SMichael Klier $link['type'] = 'extern'; 753beccd742SMichael Klier $link['page'] = $url; 754beccd742SMichael Klier $link['href'] = $url; 755beccd742SMichael Klier array_push($links,$link); 756beccd742SMichael Klier break; 757beccd742SMichael Klier } 758beccd742SMichael Klier } 759beccd742SMichael Klier 76063dd0d58SMichael Klier return ($links); 76163dd0d58SMichael Klier } 76263dd0d58SMichael Klier 76363dd0d58SMichael Klier /** 76463dd0d58SMichael Klier * Returns a list of recent changes since give timestamp 76563dd0d58SMichael Klier * 76699c8d7f2Smichael * @author Michael Hamann <michael@content-space.de> 76763dd0d58SMichael Klier * @author Michael Klier <chi@chimeric.de> 76863dd0d58SMichael Klier */ 76963dd0d58SMichael Klier function getRecentChanges($timestamp) { 77063dd0d58SMichael Klier if(strlen($timestamp) != 10) 77163dd0d58SMichael Klier return new IXR_Error(20, 'The provided value is not a valid timestamp'); 77263dd0d58SMichael Klier 77363dd0d58SMichael Klier require_once(DOKU_INC.'inc/changelog.php'); 77463dd0d58SMichael Klier require_once(DOKU_INC.'inc/pageutils.php'); 77563dd0d58SMichael Klier 77699c8d7f2Smichael $recents = getRecentsSince($timestamp); 77763dd0d58SMichael Klier 77899c8d7f2Smichael $changes = array(); 77963dd0d58SMichael Klier 78099c8d7f2Smichael foreach ($recents as $recent) { 78199c8d7f2Smichael $change = array(); 78299c8d7f2Smichael $change['name'] = $recent['id']; 78399c8d7f2Smichael $change['lastModified'] = new IXR_Date($recent['date']); 78499c8d7f2Smichael $change['author'] = $recent['user']; 78599c8d7f2Smichael $change['version'] = $recent['date']; 78699c8d7f2Smichael $change['perms'] = $recent['perms']; 78799c8d7f2Smichael $change['size'] = @filesize(wikiFN($recent['id'])); 78863dd0d58SMichael Klier array_push($changes, $change); 78999c8d7f2Smichael } 79099c8d7f2Smichael 79199c8d7f2Smichael if (!empty($changes)) { 79299c8d7f2Smichael return $changes; 79363dd0d58SMichael Klier } else { 79463dd0d58SMichael Klier // in case we still have nothing at this point 79563dd0d58SMichael Klier return new IXR_Error(30, 'There are no changes in the specified timeframe'); 7963a1dad2dSDennis Ploeger } 79799c8d7f2Smichael } 79899c8d7f2Smichael 79999c8d7f2Smichael /** 80099c8d7f2Smichael * Returns a list of recent media changes since give timestamp 80199c8d7f2Smichael * 80299c8d7f2Smichael * @author Michael Hamann <michael@content-space.de> 80399c8d7f2Smichael * @author Michael Klier <chi@chimeric.de> 80499c8d7f2Smichael */ 80599c8d7f2Smichael function getRecentMediaChanges($timestamp) { 80699c8d7f2Smichael if(strlen($timestamp) != 10) 80799c8d7f2Smichael return new IXR_Error(20, 'The provided value is not a valid timestamp'); 80899c8d7f2Smichael 80999c8d7f2Smichael require_once(DOKU_INC.'inc/changelog.php'); 81099c8d7f2Smichael require_once(DOKU_INC.'inc/pageutils.php'); 81199c8d7f2Smichael 81299c8d7f2Smichael $recents = getRecentsSince($timestamp, null, '', RECENTS_MEDIA_CHANGES); 81399c8d7f2Smichael 81499c8d7f2Smichael $changes = array(); 81599c8d7f2Smichael 81699c8d7f2Smichael foreach ($recents as $recent) { 81799c8d7f2Smichael $change = array(); 81899c8d7f2Smichael $change['name'] = $recent['id']; 81999c8d7f2Smichael $change['lastModified'] = new IXR_Date($recent['date']); 82099c8d7f2Smichael $change['author'] = $recent['user']; 82199c8d7f2Smichael $change['version'] = $recent['date']; 82299c8d7f2Smichael $change['perms'] = $recent['perms']; 823a4da2756Smichael $change['size'] = @filesize(mediaFN($recent['id'])); 82499c8d7f2Smichael array_push($changes, $change); 82599c8d7f2Smichael } 82699c8d7f2Smichael 82799c8d7f2Smichael if (!empty($changes)) { 82899c8d7f2Smichael return $changes; 82999c8d7f2Smichael } else { 83099c8d7f2Smichael // in case we still have nothing at this point 83199c8d7f2Smichael return new IXR_Error(30, 'There are no changes in the specified timeframe'); 83299c8d7f2Smichael } 83399c8d7f2Smichael } 8343a1dad2dSDennis Ploeger 8353a1dad2dSDennis Ploeger /** 83673056168SMichael Klier * Returns a list of available revisions of a given wiki page 83773056168SMichael Klier * 83873056168SMichael Klier * @author Michael Klier <chi@chimeric.de> 83973056168SMichael Klier */ 84073056168SMichael Klier function pageVersions($id, $first) { 84173056168SMichael Klier global $conf; 84273056168SMichael Klier 84373056168SMichael Klier $versions = array(); 84473056168SMichael Klier 84573056168SMichael Klier if(empty($id)) 84673056168SMichael Klier return new IXR_Error(1, 'Empty page ID'); 84773056168SMichael Klier 84873056168SMichael Klier require_once(DOKU_INC.'inc/changelog.php'); 84973056168SMichael Klier 85073056168SMichael Klier $revisions = getRevisions($id, $first, $conf['recent']+1); 85173056168SMichael Klier 85273056168SMichael Klier if(count($revisions)==0 && $first!=0) { 85373056168SMichael Klier $first=0; 85473056168SMichael Klier $revisions = getRevisions($id, $first, $conf['recent']+1); 85573056168SMichael Klier } 85673056168SMichael Klier 85745c63471SMichael Klier if(count($revisions)>0 && $first==0) { 85845c63471SMichael Klier array_unshift($revisions, ''); // include current revision 85945c63471SMichael Klier array_pop($revisions); // remove extra log entry 86045c63471SMichael Klier } 86145c63471SMichael Klier 86273056168SMichael Klier $hasNext = false; 86373056168SMichael Klier if(count($revisions)>$conf['recent']) { 86473056168SMichael Klier $hasNext = true; 86573056168SMichael Klier array_pop($revisions); // remove extra log entry 86673056168SMichael Klier } 86773056168SMichael Klier 86873056168SMichael Klier if(!empty($revisions)) { 86973056168SMichael Klier foreach($revisions as $rev) { 87073056168SMichael Klier $file = wikiFN($id,$rev); 87173056168SMichael Klier $time = @filemtime($file); 87245c63471SMichael Klier // we check if the page actually exists, if this is not the 87345c63471SMichael Klier // case this can lead to less pages being returned than 87445c63471SMichael Klier // specified via $conf['recent'] 87573056168SMichael Klier if($time){ 87673056168SMichael Klier $info = getRevisionInfo($id, $time, 1024); 87773056168SMichael Klier if(!empty($info)) { 87873056168SMichael Klier $data['user'] = $info['user']; 87973056168SMichael Klier $data['ip'] = $info['ip']; 88073056168SMichael Klier $data['type'] = $info['type']; 88173056168SMichael Klier $data['sum'] = $info['sum']; 88273056168SMichael Klier $data['modified'] = new IXR_Date($info['date']); 88373056168SMichael Klier $data['version'] = $info['date']; 88473056168SMichael Klier array_push($versions, $data); 88573056168SMichael Klier } 88673056168SMichael Klier } 88773056168SMichael Klier } 88873056168SMichael Klier return $versions; 88973056168SMichael Klier } else { 89073056168SMichael Klier return array(); 89173056168SMichael Klier } 89273056168SMichael Klier } 89373056168SMichael Klier 89473056168SMichael Klier /** 895797c0d11SAndreas Gohr * The version of Wiki RPC API supported 896797c0d11SAndreas Gohr */ 897797c0d11SAndreas Gohr function wiki_RPCVersion(){ 898797c0d11SAndreas Gohr return 2; 899797c0d11SAndreas Gohr } 9001b11c097SAndreas Gohr 90128ec3c76SAndreas Gohr 90228ec3c76SAndreas Gohr /** 90328ec3c76SAndreas Gohr * Locks or unlocks a given batch of pages 90428ec3c76SAndreas Gohr * 90528ec3c76SAndreas Gohr * Give an associative array with two keys: lock and unlock. Both should contain a 90628ec3c76SAndreas Gohr * list of pages to lock or unlock 90728ec3c76SAndreas Gohr * 90828ec3c76SAndreas Gohr * Returns an associative array with the keys locked, lockfail, unlocked and 90928ec3c76SAndreas Gohr * unlockfail, each containing lists of pages. 91028ec3c76SAndreas Gohr */ 91128ec3c76SAndreas Gohr function setLocks($set){ 91228ec3c76SAndreas Gohr $locked = array(); 91328ec3c76SAndreas Gohr $lockfail = array(); 91428ec3c76SAndreas Gohr $unlocked = array(); 91528ec3c76SAndreas Gohr $unlockfail = array(); 91628ec3c76SAndreas Gohr 91728ec3c76SAndreas Gohr foreach((array) $set['lock'] as $id){ 91828ec3c76SAndreas Gohr if(checklock($id)){ 91928ec3c76SAndreas Gohr $lockfail[] = $id; 92028ec3c76SAndreas Gohr }else{ 92128ec3c76SAndreas Gohr lock($id); 92228ec3c76SAndreas Gohr $locked[] = $id; 92328ec3c76SAndreas Gohr } 92428ec3c76SAndreas Gohr } 92528ec3c76SAndreas Gohr 92628ec3c76SAndreas Gohr foreach((array) $set['unlock'] as $id){ 92728ec3c76SAndreas Gohr if(unlock($id)){ 92828ec3c76SAndreas Gohr $unlocked[] = $id; 92928ec3c76SAndreas Gohr }else{ 93028ec3c76SAndreas Gohr $unlockfail[] = $id; 93128ec3c76SAndreas Gohr } 93228ec3c76SAndreas Gohr } 93328ec3c76SAndreas Gohr 93428ec3c76SAndreas Gohr return array( 93528ec3c76SAndreas Gohr 'locked' => $locked, 93628ec3c76SAndreas Gohr 'lockfail' => $lockfail, 93728ec3c76SAndreas Gohr 'unlocked' => $unlocked, 93828ec3c76SAndreas Gohr 'unlockfail' => $unlockfail, 93928ec3c76SAndreas Gohr ); 94028ec3c76SAndreas Gohr } 94128ec3c76SAndreas Gohr 942445e8084SAndreas Gohr function getAPIVersion(){ 943445e8084SAndreas Gohr return DOKU_XMLRPC_API_VERSION; 944445e8084SAndreas Gohr } 945445e8084SAndreas Gohr 946445e8084SAndreas Gohr function login($user,$pass){ 947445e8084SAndreas Gohr global $conf; 948445e8084SAndreas Gohr global $auth; 949445e8084SAndreas Gohr if(!$conf['useacl']) return 0; 950445e8084SAndreas Gohr if(!$auth) return 0; 951445e8084SAndreas Gohr if($auth->canDo('external')){ 952445e8084SAndreas Gohr return $auth->trustExternal($user,$pass,false); 953445e8084SAndreas Gohr }else{ 954445e8084SAndreas Gohr return auth_login($user,$pass,false,true); 955445e8084SAndreas Gohr } 956445e8084SAndreas Gohr } 9573ee5b583SAndreas Gohr 9583ee5b583SAndreas Gohr 959797c0d11SAndreas Gohr} 960797c0d11SAndreas Gohr 961797c0d11SAndreas Gohr$server = new dokuwiki_xmlrpc_server(); 962797c0d11SAndreas Gohr 9632aca132fSMichael Klier// vim:ts=4:sw=4:et:enc=utf-8: 964