DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:mediamanager_filesize

Media Manager and File Size

When you click on a file in the media manager the link to the file is inserted in the parent window textarea as in

{{some:namespace:some_image.gif|}}

I wanted the file size to also be appended:

{{some:namespace:some_image.gif|}} 1.8 KB

The following two patches for lib/scripts/media.js and inc/media.php (for DokuWiki ver-rc2007-05-24) did the trick.

Patch for lib/scripts/media.js

--- lib/scripts/media.js-00000000       Thu May 24 20:32:29 2007
+++ lib/scripts/media.js        Thu Jun 21 16:47:27 2007
@@ -169,7 +169,22 @@
      * @author Andreas Gohr <andi@splitbrain.org>
      */
     select: function(event,link){
-        var id = link.name.substr(2);
+        var inputdata = link.name.substr(2);
+        var temp = new Array();
+        temp = inputdata.split(' ');
+        var id = temp[0];
+        var filesize = temp[1];
+        var sizeunits = temp[2];
+        if (typeof filesize == 'undefined'){
+          filesize = '';
+        }else{
+          filesize = ' '+filesize;
+        }
+        if (typeof sizeunits == 'undefined'){
+          sizeunits = '';
+        }else{
+          sizeunits = ' '+sizeunits;
+        }

         if(!opener){
             // if we don't run in popup display example
@@ -181,7 +196,7 @@
             }
             return false;
         }
-        opener.insertTags('wiki__text','{{'+id+'|','}}','');
+        opener.insertTags('wiki__text','{{'+id+'|','}}'+filesize+sizeunits,'');

         if(!media.keepopen) window.close();
         opener.focus();

Patch for inc/media.php

--- inc/media.php-00000000 Thu May 24 20:32:28 2007
+++ inc/media.php  Thu Jun 21 17:29:19 2007
@@ -439,7 +439,7 @@

     // ouput
     echo '<div class="'.$zebra.'"'.$jump.'>'.NL;
-    echo '<a name="h_'.$item['id'].'" class="'.$class.'">'.$file.'</a> ';
+    echo '<a name="h_'.$item['id'].' '.filesize_h($item['size']).'" class="'.$class.'">'.$file.'</a> ';
     echo '<span class="info">('.$info.')</span>'.NL;
     media_fileactions($item,$auth);
     echo '<div class="example" id="ex_'.str_replace(':','_',$item['id']).'">';
@@ -473,7 +473,7 @@
     // output
     echo '<div class="detail">';
     echo '<div class="thumb">';
-    echo '<a name="d_'.$item['id'].'" class="select">';
+    echo '<a name="d_'.$item['id'].' '.filesize_h($item['size']).'" class="select">';
     echo '<img src="'.$src.'" '.$att.' />';
     echo '</a>';
     echo '</div>';

Warning

I haven't tested this extensively, so be cautious.

Thanos Massias 2007-06-21 16:17

tips/mediamanager_filesize.txt · Last modified: 2012-10-07 06:39 by Matt2

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki