summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatthiasgrimm <matthiasgrimm@users.sourceforge.net>2005-06-16 18:34:25 +0200
committermatthiasgrimm <matthiasgrimm@users.sourceforge.net>2005-06-16 18:34:25 +0200
commitd67ca2c0f7f6b75608386c226d33afdda872757c (patch)
tree6865ecca6d30cf4ae70a68ca85f8f22161176f33
parentb59a406b93334a3a9ba2c1f2529a3bc7123361f4 (diff)
downloadrpg-d67ca2c0f7f6b75608386c226d33afdda872757c.tar.gz
rpg-d67ca2c0f7f6b75608386c226d33afdda872757c.tar.bz2
media reference check part 2
Part 1 only checks for the existance of references. Part 2 will show where this references are so that the user could easily find them. Both parts are configurable: refcheck darcs-hash:20050616163425-7ef76-a7fce6cd1ef5d2cc2e4ac3b869969a65c671770a.gz
-rw-r--r--conf/dokuwiki.php1
-rw-r--r--inc/html.php30
-rw-r--r--inc/lang/de/lang.php5
-rw-r--r--inc/lang/en/lang.php5
-rw-r--r--inc/search.php2
-rw-r--r--inc/template.php47
-rw-r--r--lib/exe/media.php16
-rw-r--r--lib/tpl/default/layout.css24
8 files changed, 115 insertions, 15 deletions
diff --git a/conf/dokuwiki.php b/conf/dokuwiki.php
index bd4eccfb5..47b427fa3 100644
--- a/conf/dokuwiki.php
+++ b/conf/dokuwiki.php
@@ -37,6 +37,7 @@ $conf['camelcase'] = 0; //Use CamelCase for linking? (I don't
$conf['deaccent'] = 1; //convert accented chars to unaccented ones in pagenames?
$conf['useheading'] = 0; //use the first heading in a page as its name
$conf['refcheck'] = 1; //check references before deleting media files
+$conf['refshow'] = 0; //show where media files are still used
$conf['refcount'] = 5; //search only no of references to satisfy the refcheck
/* Antispam Features */
diff --git a/inc/html.php b/inc/html.php
index 785172b84..3c724865d 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -171,7 +171,35 @@ function html_topbtn(){
}
/**
- * Displays a button (using it's own form)
+ * Just the back to media window button in its own form
+ *
+ * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
+ */
+function html_backtomedia_button($params,$akey=''){
+ global $conf;
+ global $lang;
+
+ $ret = '<form class="button" method="get" action="'.DOKU_BASE.'lib/exe/media.php">';
+
+ reset($params);
+ while (list($key, $val) = each($params)) {
+ $ret .= '<input type="hidden" name="'.$key.'" ';
+ $ret .= 'value="'.htmlspecialchars($val).'" />';
+ }
+
+ $ret .= '<input type="submit" value="'.htmlspecialchars($lang['btn_backtomedia']).'" class="button" ';
+ if($akey){
+ $ret .= 'title="ALT+'.strtoupper($akey).'" ';
+ $ret .= 'accesskey="'.$akey.'" ';
+ }
+ $ret .= '/>';
+ $ret .= '</form>';
+
+ return $ret;
+}
+
+/**
+ * Displays a button (using its own form)
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
diff --git a/inc/lang/de/lang.php b/inc/lang/de/lang.php
index 7e3e46469..ae7932806 100644
--- a/inc/lang/de/lang.php
+++ b/inc/lang/de/lang.php
@@ -32,6 +32,7 @@ $lang['btn_admin'] = 'Admin';
$lang['btn_update'] = 'Updaten';
$lang['btn_delete'] = 'Löschen';
$lang['btn_back'] = 'Zurück';
+$lang['btn_backtomedia'] = 'Zurück zur Dateiauswahl';
$lang['loggedinas'] = 'Angemeldet als';
$lang['user'] = 'Benutzername';
@@ -77,6 +78,10 @@ $lang['mediainuse'] = 'Die Datei "%s" wurde nicht gelöscht - sie wird noch ver
$lang['namespaces'] = 'Namensräume';
$lang['mediafiles'] = 'Vorhandene Dateien in';
+$lang['reference'] = 'Verwendung von';
+$lang['ref_inuse'] = 'Diese Datei kann nicht gelöscht werden, da sie noch von folgenden Seiten benutzt wird:';
+$lang['ref_hidden'] = 'Einige Verweise sind auf Seiten für die Sie keine Leseberechtigung haben.';
+
$lang['hits'] = 'Treffer';
$lang['quickhits'] = 'Passende Seitennamen';
$lang['toc'] = 'Inhaltsverzeichnis';
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php
index 235eeff80..93f43d089 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -31,6 +31,7 @@ $lang['btn_admin'] = 'Admin';
$lang['btn_update'] = 'Update';
$lang['btn_delete'] = 'Delete';
$lang['btn_back'] = 'Back';
+$lang['btn_backtomedia'] = 'Back to Mediafile Selection';
$lang['loggedinas'] = 'Logged in as';
$lang['user'] = 'Username';
@@ -75,6 +76,10 @@ $lang['mediainuse'] = 'The file "%s" hasn\'t been deleted - it is still in use.
$lang['namespaces'] = 'Namespaces';
$lang['mediafiles'] = 'Available files in';
+$lang['reference'] = 'References for';
+$lang['ref_inuse'] = 'The file can\'t be deleted, because it\'s still used by the following pages:';
+$lang['ref_hidden'] = 'Some references are on pages you don\'t have permission to read';
+
$lang['hits'] = 'Hits';
$lang['quickhits'] = 'Matching pagenames';
$lang['toc'] = 'Table of Contents';
diff --git a/inc/search.php b/inc/search.php
index 0caae3d7c..e61d04491 100644
--- a/inc/search.php
+++ b/inc/search.php
@@ -355,7 +355,7 @@ function search_reference(&$data,$base,$file,$type,$lvl,$opts){
//'false' will skip subdirectories to speed search up.
if(count($data) >= $conf['refcount']) return false;
- $reg = '{{ *'.$opts['query'].' *(\|.*)?}}';
+ $reg = '\{\{ *\:?'.$opts['query'].' *(\|.*)?\}\}';
search_regex($data,$base,$file,$reg,array($opts['query']));
return true;
}
diff --git a/inc/template.php b/inc/template.php
index bc2bc561b..b37d335a8 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -247,17 +247,20 @@ function tpl_getparent($ID){
* edit - edit/create/show button
* history - old revisions
* recent - recent changes
- * login - login/logout button - if ACL enabled
- * index - The index
- * admin - admin page - if enough rights
- * top - a back to top button
- * back - a back to parent button - if available
+ * login - login/logout button - if ACL enabled
+ * index - The index
+ * admin - admin page - if enough rights
+ * top - a back to top button
+ * back - a back to parent button - if available
+ * backtomedia - returns to the mediafile upload dialog
+ * after references have been displayed
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function tpl_button($type){
global $ID;
+ global $NS;
global $INFO;
global $conf;
@@ -295,6 +298,9 @@ function tpl_button($type){
if($INFO['perm'] == AUTH_ADMIN)
print html_btn(admin,$ID,'',array('do' => 'admin'));
break;
+ case 'backtomedia':
+ print html_backtomedia_button(array('ns' => $NS),'b');
+ break;
default:
print '[unknown button type]';
}
@@ -589,7 +595,6 @@ function tpl_mediafilelist(){
$del = '';
}
-
if($item['isimg']){
$w = $item['info'][0];
$h = $item['info'][1];
@@ -615,6 +620,36 @@ function tpl_mediafilelist(){
}
/**
+ * show references to a media file
+ * References uses the same visual as search results and share
+ * their CSS tags except pagenames won't be links.
+ *
+ * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
+ */
+function tpl_showreferences(&$data){
+ global $lang;
+
+ $hidden=0; //count of hits without read permission
+
+ if(count($data)){
+ usort($data,'sort_search_fulltext');
+ foreach($data as $row){
+ if(auth_quickaclcheck($row['id']) >= AUTH_READ){
+ print '<div class="search_result">';
+ print '<span class="mediaref_ref">'.$row['id'].'</span>';
+ print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
+ print '<div class="search_snippet">'.$row['snippet'].'</div>';
+ print '</div>';
+ }else
+ $hidden++;
+ }
+ if ($hidden){
+ print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
+ }
+ }
+}
+
+/**
* Print the media upload form if permissions are correct
*
* @author Andreas Gohr <andi@splitbrain.org>
diff --git a/lib/exe/media.php b/lib/exe/media.php
index f0d0795ad..27975a493 100644
--- a/lib/exe/media.php
+++ b/lib/exe/media.php
@@ -41,9 +41,8 @@
}
if(!count($mediareferences)){
media_delete($DEL);
- }else{
- $text = str_replace('%s',noNS($DEL),$lang['mediainuse']);
- msg($text,0);
+ }elseif(!$conf['refshow']){
+ msg(str_replace('%s',noNS($DEL),$lang['mediainuse']),0);
}
}
@@ -54,8 +53,12 @@
//start output and load template
header('Content-Type: text/html; charset=utf-8');
- include(DOKU_INC.'lib/tpl/'.$conf['template'].'/media.php');
-
+ if($conf['refshow'] && count($mediareferences)){
+ include(DOKU_INC.'lib/tpl/'.$conf['template'].'/mediaref.php');
+ }else{
+ include(DOKU_INC.'lib/tpl/'.$conf['template'].'/media.php');
+ }
+
//restore old umask
umask($conf['oldumask']);
@@ -75,8 +78,7 @@ function media_delete($delid){
return true;
}
//something went wrong
- $text = str_replace('%s',$file,$lang['deletefail']);
- msg($text,-1);
+ msg(str_replace('%s',$file,$lang['deletefail']),-1);
return false;
}
diff --git a/lib/tpl/default/layout.css b/lib/tpl/default/layout.css
index fea7c58ab..45fed3d49 100644
--- a/lib/tpl/default/layout.css
+++ b/lib/tpl/default/layout.css
@@ -107,3 +107,27 @@ div.uploadform {
padding: 0.5em;
width:65%;
}
+
+div.mediaref_head {
+ margin-left:0.5em;
+}
+
+div.mediaref .search_result {
+ padding-left:1em;
+}
+
+.mediaref_ref {
+ color:#009900;
+}
+
+div.mediaref_hidden {
+ margin-top:1em;
+ text-align:center;
+ font-size:1.2em;
+ color:#BB0000;
+}
+
+div.mediaref_footer {
+ margin-top:1em;
+ text-align:center;
+}