diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php index cd25a3d3335c5e13ef0702a769538bcc8d4c1058..b752183c6e49c551f4d477271822d07e7a9e1b62 100644 --- a/lib/exe/xmlrpc.php +++ b/lib/exe/xmlrpc.php @@ -75,6 +75,12 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { array('struct'), 'Returns a list of all pages. The result is an array of utf8 pagenames.' ); + $this->addCallback( + 'wiki.getAttachments', + 'this:listAttachments', + array('struct'), + 'Returns a list of all media files.' + ); $this->addCallback( 'wiki.getBackLinks', 'this:listBackLinks', @@ -161,6 +167,44 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { return ft_pageLookup(''); } + /** + * List all media files. + */ + function listAttachments($ns) { + global $conf; + global $lang; + + $ns = cleanID($ns); + + if(auth_quickaclcheck($ns.':*') >= AUTH_READ) { + $dir = utf8_encodeFN(str_replace(':', '/', $ns)); + + $data = array(); + require_once(DOKU_INC.'inc/search.php'); + search($data, $conf['mediadir'], 'search_media', array(), $dir); + + if(!count($data)) { + return array(); + } + + $files = array(); + foreach($data as $item) { + $file = array(); + $file['id'] = $item['id']; + $file['size'] = $item['size']; + $file['mtime'] = $item['mtime']; + $file['isimg'] = $item['isimg']; + $file['writable'] = $item['writeable']; + array_push($files, $file); + } + + return $files; + + } else { + return new IXR_Error(1, 'You are not allowed to list media files.'); + } + } + /** * Return a list of backlinks */