From bf1f3ac4f72c26ff386c08c920dda651d91c6898 Mon Sep 17 00:00:00 2001 From: sarnowski Date: Mon, 24 Aug 2009 13:22:30 +0200 Subject: Search capabilities for the media manager added. darcs-hash:20090824112230-8c5bd-7b8d8ba14e7533c1035b7b732983a0e3de8251a1.gz --- inc/lang/en/lang.php | 3 ++ inc/media.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++-- inc/template.php | 7 +++-- 3 files changed, 93 insertions(+), 4 deletions(-) (limited to 'inc') diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php index 04ec3170e..121b0fec2 100644 --- a/inc/lang/en/lang.php +++ b/inc/lang/en/lang.php @@ -94,6 +94,8 @@ $lang['resendpwdsuccess'] = 'Your new password has been sent by email.'; $lang['license'] = 'Except where otherwise noted, content on this wiki is licensed under the following license:'; $lang['licenseok'] = 'Note: By editing this page you agree to license your content under the following license:'; +$lang['txt_searchmediakey'] = 'Search for file'; +$lang['txt_searchrelative'] = 'Only search in namespace :%s'; $lang['txt_upload'] = 'Select file to upload'; $lang['txt_filename'] = 'Upload as (optional)'; $lang['txt_overwrt'] = 'Overwrite existing file'; @@ -121,6 +123,7 @@ $lang['mediainuse'] = 'The file "%s" hasn\'t been deleted - it is still in use. $lang['namespaces'] = 'Namespaces'; $lang['mediafiles'] = 'Available files in'; +$lang['js']['searchmedia'] = 'Search for files'; $lang['js']['keepopen'] = 'Keep window open on selection'; $lang['js']['hidedetails'] = 'Hide Details'; $lang['mediausage'] = 'Use the following syntax to reference this file:'; diff --git a/inc/media.php b/inc/media.php index 1d584db70..84b11b65e 100644 --- a/inc/media.php +++ b/inc/media.php @@ -460,6 +460,56 @@ function media_filelist($ns,$auth=null,$jump=''){ } } +/** + * List all files found by the search request + */ +function media_searchlist($ns,$auth=null,$jump=''){ + global $conf; + global $lang; + $ns = cleanID($ns); + + // check auth our self if not given (needed for ajax calls) + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '

Search

'.NL; + + if($auth < AUTH_READ){ + // FIXME: print permission warning here instead? + echo '
'.$lang['nothingfound'].'
'.NL; + return; + } + + media_searchform($ns, $auth); + + if (isset($_REQUEST['key']) && strlen($_REQUEST['key']) > 2) { + + if (isset($_REQUEST['key_relative'])) { + $dir = utf8_encodeFN(str_replace(':','/',$ns)); + } else { + $dir = ''; + } + + $data = array(); + $evt = new Doku_Event('ACTION_MEDIA_SEARCH', $dir); + if ($evt->advise_before()) { + $pattern = '#'.str_replace('#', '\#', $_REQUEST['key']).'#'; + search($data,$conf['mediadir'],'search_media', array('showmsg'=>true,'pattern'=>$pattern),$dir); + + } + $evt->advise_after(); + unset($evt); + + if(!count($data)){ + echo '
'.$lang['nothingfound'].'
'.NL; + return; + } + + foreach($data as $item){ + media_printfile($item,$auth,$jump,$display_namespace=true); + } + } +} + /** * Print action links for a file depending on filetype * and available permissions @@ -498,7 +548,7 @@ function media_fileactions($item,$auth){ /** * Formats and prints one file in the list */ -function media_printfile($item,$auth,$jump){ +function media_printfile($item,$auth,$jump,$display_namespace=false){ global $lang; global $conf; @@ -537,7 +587,7 @@ function media_printfile($item,$auth,$jump){ // ouput echo '
'.NL; - echo ''.$file.' '; + echo ''.$file.' '; echo '('.$info.')'.NL; media_fileactions($item,$auth); echo '
'; @@ -662,6 +712,39 @@ function media_uploadform($ns, $auth){ + */ +function media_searchform($ns, $auth){ + global $lang; + + if (!isset($_REQUEST['key'])) { + $default = ''; + } else { + $default = htmlspecialchars($_REQUEST['key']); + } + + // The default HTML search form + $form = new Doku_Form('dw__mediasearch', DOKU_BASE.'lib/exe/mediamanager.php', false); + $form->addElement('
' . $lang['mediasearch'] . '
'); + $form->addElement(formSecurityToken()); + $form->addHidden('ns', hsc($ns)); + $form->addHidden('call', 'mediasearchlist'); + $form->addElement(form_makeOpenTag('p')); + $form->addElement(form_makeTextField('key', $default, $lang['txt_searchmediakey'].':', 'searchmedia__key')); + $form->addElement(form_makeButton('submit', '', $lang['btn_search'])); + $form->addElement(form_makeCloseTag('p')); + if ($ns) { + $form->addElement(form_makeOpenTag('p')); + $form->addElement(form_makeCheckboxField('key_relative', true, sprintf($lang['txt_searchrelative'], $ns), 'dw__relative', 'check', isset($_REQUEST['key_relative'])?array('checked' => 'checked'):array())); + $form->addElement(form_makeCloseTag('p')); + } + + html_form('searchmedia', $form); +} + /** * Build a tree outline of available media namespaces * diff --git a/inc/template.php b/inc/template.php index e1b253f96..9564dcef8 100644 --- a/inc/template.php +++ b/inc/template.php @@ -1190,8 +1190,11 @@ function tpl_mediaContent($fromajax=false){ global $NS; global $JUMPTO; - if(is_array($_REQUEST['do'])){ - $do = array_shift(array_keys($_REQUEST['do'])); + ptln('
'); + if($_REQUEST['edit']){ + media_metaform($IMG,$AUTH); + }elseif(is_array($INUSE)){ + media_filesinuse($INUSE,$IMG); }else{ $do = $_REQUEST['do']; } -- cgit v1.2.3