added option to limit listings to certain file extensions

This commit is contained in:
Andreas Gohr
2009-12-03 13:27:59 +01:00
committed by Adrian Lang
parent 30f6a886d8
commit a269b44c6a
4 changed files with 12 additions and 0 deletions

View File

@@ -7,3 +7,4 @@ $conf['allow_in_comments'] = 0;
$conf['allowed_absolute_paths'] = DOKU_INC; $conf['allowed_absolute_paths'] = DOKU_INC;
$conf['web_paths'] = DOKU_URL; $conf['web_paths'] = DOKU_URL;
$conf['defaults'] = ''; $conf['defaults'] = '';
$conf['extensions'] = '';

View File

@@ -10,4 +10,5 @@ $meta['allow_in_comments'] = array('onoff');
$meta['allowed_absolute_paths'] = array(''); $meta['allowed_absolute_paths'] = array('');
$meta['web_paths'] = array(''); $meta['web_paths'] = array('');
$meta['defaults'] = array('string'); $meta['defaults'] = array('string');
$meta['extensions'] = array('string');

View File

@@ -4,3 +4,4 @@ $lang['allow_in_comments'] = 'Whether to allow the filelist syntax to be used in
$lang['allowed_absolute_paths'] = 'Comma-separated list of absolute paths allowed for globbing.'; $lang['allowed_absolute_paths'] = 'Comma-separated list of absolute paths allowed for globbing.';
$lang['web_paths'] = 'Comma-separated list of urls by which to reach the corresponding absolute path from the previous list. MUST have the exact same number of entries as allowed_absolute_paths.'; $lang['web_paths'] = 'Comma-separated list of urls by which to reach the corresponding absolute path from the previous list. MUST have the exact same number of entries as allowed_absolute_paths.';
$lang['defaults'] = 'Default options. Use the same syntax as in inline configuration'; $lang['defaults'] = 'Default options. Use the same syntax as in inline configuration';
$lang['extensions'] = 'Comma-separated listof allowed file extensions to list';

View File

@@ -582,6 +582,11 @@ class syntax_plugin_filelist extends DokuWiki_Syntax_Plugin {
return false; return false;
} }
$ext = explode(',',$this->getConf('extensions'));
$ext = array_map('trim',$ext);
$ext = array_map('preg_quote_cb',$ext);
$ext = join('|',$ext);
if (($dir = opendir($path)) !== false) { if (($dir = opendir($path)) !== false) {
$result = array(); $result = array();
while (($file = readdir($dir)) !== false) { while (($file = readdir($dir)) !== false) {
@@ -600,6 +605,10 @@ class syntax_plugin_filelist extends DokuWiki_Syntax_Plugin {
$filepath = $path . '/' . $file; $filepath = $path . '/' . $file;
if ($this->_fnmatch($match, $file) || (is_dir($filepath) && $params['recursive'])) { if ($this->_fnmatch($match, $file) || (is_dir($filepath) && $params['recursive'])) {
if(!is_dir($filepath) && !preg_match('/('.$ext.')$/i',$file)){
continue;
}
if (!$params['direct']) { if (!$params['direct']) {
// exclude prohibited media files via ACLs // exclude prohibited media files via ACLs
$mid = str_replace('/', ':', substr($filepath, strlen($this->mediadir))); $mid = str_replace('/', ':', substr($filepath, strlen($this->mediadir)));