From 26bec61e9e45fa53d4c3ac5426eae19943c8aea6 Mon Sep 17 00:00:00 2001
From: Michael Klier <chi@chimeric.de>
Date: Sun, 13 Jul 2008 18:52:10 +0200
Subject: [PATCH] XML-RPC: added getAttachments()

darcs-hash:20080713165210-23886-d28593ac62f3471a4dc4a5410263edb0e48986bc.gz
---
 lib/exe/xmlrpc.php | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php
index cd25a3d33..b752183c6 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
      */
-- 
GitLab