diff options
author | Andreas Gohr <andi@splitbrain.org> | 2009-02-23 18:27:46 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2009-02-23 18:27:46 +0100 |
commit | 224122cf976599e1fc256224095d84c4e0827e1a (patch) | |
tree | 0979e26685dd2a962c88665c3c9dbe8b5d6aa0e2 | |
parent | ef47e2988384a280584ec93d3e302dd48743db50 (diff) | |
download | rpg-224122cf976599e1fc256224095d84c4e0827e1a.tar.gz rpg-224122cf976599e1fc256224095d84c4e0827e1a.tar.bz2 |
streamlined media listing
Some parameters of media_search where changed, parts using this function
need to be identified and fixed.
darcs-hash:20090223172746-7ad00-d07951739fba17d0c8925b28b947f7cbb7fc7e1a.gz
-rw-r--r-- | inc/search.php | 80 | ||||
-rw-r--r-- | lib/exe/xmlrpc.php | 32 |
2 files changed, 57 insertions, 55 deletions
diff --git a/inc/search.php b/inc/search.php index a5637fff0..dd5bda9be 100644 --- a/inc/search.php +++ b/inc/search.php @@ -185,38 +185,52 @@ function search_namespaces(&$data,$base,$file,$type,$lvl,$opts){ * @author Andreas Gohr <andi@splitbrain.org> */ function search_media(&$data,$base,$file,$type,$lvl,$opts){ - //we do nothing with directories - if($type == 'd') { - return ($opts['recursive']); - } + //we do nothing with directories + if($type == 'd') { + if(!$opts['depth']) return true; // recurse forever + $parts = explode('/',$file); + if(count($parts) == $opts['depth']) return false; // depth reached + return true; + return ($opts['recursive']); + } - $info = array(); - $info['id'] = pathID($file,true); - if($info['id'] != cleanID($info['id'])){ - if($opts['showmsg']) - msg(hsc($info['id']).' is not a valid file name for DokuWiki - skipped',-1); - return false; // skip non-valid files - } + $info = array(); + $info['id'] = pathID($file,true); + if($info['id'] != cleanID($info['id'])){ + if($opts['showmsg']) + msg(hsc($info['id']).' is not a valid file name for DokuWiki - skipped',-1); + return false; // skip non-valid files + } - //check ACL for namespace (we have no ACL for mediafiles) - if(auth_quickaclcheck(getNS($info['id']).':*') < AUTH_READ){ - return false; - } + //check ACL for namespace (we have no ACL for mediafiles) + $info['perm'] = auth_quickaclcheck(getNS($info['id']).':*'); + if(!$opts['skipacl'] && $info['perm'] < AUTH_READ){ + return false; + } - $info['file'] = basename($file); - $info['size'] = filesize($base.'/'.$file); - $info['mtime'] = filemtime($base.'/'.$file); - $info['writable'] = is_writable($base.'/'.$file); - if(preg_match("/\.(jpe?g|gif|png)$/",$file)){ - $info['isimg'] = true; - require_once(DOKU_INC.'inc/JpegMeta.php'); - $info['meta'] = new JpegMeta($base.'/'.$file); - }else{ - $info['isimg'] = false; - } - $data[] = $info; + //check pattern filter + if($opts['pattern'] && !@preg_match($opts['pattern'], $info['id'])){ + return false; + } - return false; + $info['file'] = basename($file); + $info['size'] = filesize($base.'/'.$file); + $info['mtime'] = filemtime($base.'/'.$file); + $info['writable'] = is_writable($base.'/'.$file); + if(preg_match("/\.(jpe?g|gif|png)$/",$file)){ + $info['isimg'] = true; + require_once(DOKU_INC.'inc/JpegMeta.php'); + $info['meta'] = new JpegMeta($base.'/'.$file); + }else{ + $info['isimg'] = false; + } + if($opts['hash']){ + $info['hash'] = md5(io_readFile(wikiFN($info['id']),false)); + } + + $data[] = $info; + + return false; } /** @@ -269,8 +283,9 @@ function search_pagename(&$data,$base,$file,$type,$lvl,$opts){ /** * Just lists all documents * - * $opts['depth'] recursion level, 0 for all - * $opts['hash'] do md5 sum of content? + * $opts['depth'] recursion level, 0 for all + * $opts['hash'] do md5 sum of content? + * $opts['skipacl'] list everything regardless of ACL * * @author Andreas Gohr <andi@splitbrain.org> */ @@ -291,8 +306,9 @@ function search_allpages(&$data,$base,$file,$type,$lvl,$opts){ return false; } - $item['rev'] = filemtime($base.'/'.$file); - $item['size'] = filesize($base.'/'.$file); + $item['rev'] = filemtime($base.'/'.$file); + $item['mtime'] = $item['rev']; + $item['size'] = filesize($base.'/'.$file); if($opts['hash']){ $item['hash'] = md5(trim(rawWiki($item['id']))); } diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php index 351b039e9..4bdd78c45 100644 --- a/lib/exe/xmlrpc.php +++ b/lib/exe/xmlrpc.php @@ -330,35 +330,21 @@ dbglog($data); if (!is_array($options)) $options = array(); - if (!isset($options['recursive'])) $options['recursive'] = false; 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('recursive' => $options['recursive']), $dir); + search($data, $conf['mediadir'], 'search_media', $options, $dir); + $len = count($data); + if(!$len) return array(); - if(!count($data)) { - return array(); + for($i=0; $i<$len; $i++) { + unset($data[$i]['meta']); + $data[$i]['lastModified'] = new IXR_Date($data[$i]['mtime']); } - - $files = array(); - foreach($data as $item) { - if (isset($options['pattern']) && !@preg_match($options['pattern'], $item['id'])) - continue; - $file = array(); - $file['id'] = $item['id']; - $file['size'] = $item['size']; - $file['lastModified'] = new IXR_Date($item['mtime']); - $file['isimg'] = $item['isimg']; - $file['writable'] = $item['writeable']; - $file['perms'] = auth_quickaclcheck(getNS($item['id']).':*'); - array_push($files, $file); - } - - return $files; - + return $data; } else { return new IXR_Error(1, 'You are not allowed to list media files.'); } @@ -511,13 +497,13 @@ dbglog($data); //check for overwrite $overwrite = @file_exists($fn); if($overwrite && (!$params['ow'] || $auth < AUTH_DELETE)) { - return new IXR_ERROR(1, $lang['uploadexist']); + return new IXR_ERROR(1, $lang['uploadexist'].'1'); } // check for valid content @require_once(DOKU_INC.'inc/media.php'); $ok = media_contentcheck($ftmp, $imime); if($ok == -1) { - return new IXR_ERROR(1, sprintf($lang['uploadexist'], ".$iext")); + return new IXR_ERROR(1, sprintf($lang['uploadexist'].'2', ".$iext")); } elseif($ok == -2) { return new IXR_ERROR(1, $lang['uploadspam']); } elseif($ok == -3) { |