From 035e07f1301d5d7a13de017640d80db14d300ac3 Mon Sep 17 00:00:00 2001
From: Kate Arzamastseva <pshns@ukr.net>
Date: Wed, 24 Aug 2011 22:34:06 +0300
Subject: [PATCH] issue #57, function names, params, html fixes

---
 inc/html.php                     | 29 +++++++++++---------
 inc/media.php                    | 46 +++++++++++++++++++-------------
 inc/template.php                 |  8 +++---
 lib/exe/ajax.php                 |  6 ++---
 lib/exe/css.php                  |  4 +--
 lib/tpl/default/mediamanager.css |  2 +-
 6 files changed, 53 insertions(+), 42 deletions(-)

diff --git a/inc/html.php b/inc/html.php
index 1c38104d7..51afe24f4 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -485,10 +485,12 @@ function html_revisions($first=0, $media_id = false){
 
         if ($media_id) $form->addElement(form_makeOpenTag('div'));
 
-        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
-        if (!$media_id) $form->addElement(' &ndash; ');
-        if (!$media_id) $form->addElement(htmlspecialchars($INFO['sum']));
-        $form->addElement(form_makeCloseTag('span'));
+        if (!$media_id) {
+            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
+            $form->addElement(' &ndash; ');
+            $form->addElement(htmlspecialchars($INFO['sum']));
+            $form->addElement(form_makeCloseTag('span'));
+        }
 
         $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
         if (!$media_id) $editor = $INFO['editor'];
@@ -562,10 +564,12 @@ function html_revisions($first=0, $media_id = false){
 
         if ($media_id) $form->addElement(form_makeOpenTag('div'));
 
-        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
-        if (!$media_id) $form->addElement(' &ndash; ');
-        $form->addElement(htmlspecialchars($info['sum']));
-        $form->addElement(form_makeCloseTag('span'));
+        if ($info['sum']) {
+            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
+            if (!$media_id) $form->addElement(' &ndash; ');
+            $form->addElement(htmlspecialchars($info['sum']));
+            $form->addElement(form_makeCloseTag('span'));
+        }
 
         $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
         if($info['user']){
@@ -599,8 +603,7 @@ function html_revisions($first=0, $media_id = false){
         if ($first < 0) $first = 0;
         print '<div class="pagenav-prev">';
         if ($media_id) {
-            echo '<form class="button btn_newer" method="post" action="'.media_managerURL(array('first' => $first)).'">';
-            echo '<div class="no"><input type="submit" value="'.$lang['btn_newer'].'" class="button" /></div></form>';
+            print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
         } else {
             print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
         }
@@ -609,8 +612,7 @@ function html_revisions($first=0, $media_id = false){
     if ($hasNext) {
         print '<div class="pagenav-next">';
         if ($media_id) {
-            echo '<form class="button btn_older" method="post" action="'.media_managerURL(array('first' => $last)).'">';
-            echo '<div class="no"><input type="submit" value="'.$lang['btn_older'].'" class="button" /></div></form>';
+            print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
         } else {
             print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
         }
@@ -746,7 +748,8 @@ function html_recent($first=0, $show_changes='both'){
 
         if ($recent['media']) {
             $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
-            $form->addElement(form_makeOpenTag('a', array('class' => 'wikilink1', 'href' => $href)));
+            $class = (file_exists(mediaFN($recent['id']))) ? 'wikilink1' : $class = 'wikilink2';
+            $form->addElement(form_makeOpenTag('a', array('class' => $class, 'href' => $href)));
             $form->addElement($recent['id']);
             $form->addElement(form_makeCloseTag('a'));
         } else {
diff --git a/inc/media.php b/inc/media.php
index 7e8caa19c..37d8275f5 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -112,7 +112,7 @@ function media_metaform($id,$auth,$fullscreen = false){
         echo '<h1>'.hsc(noNS($id)).'</h1>'.NL;
         $action = DOKU_BASE.'lib/exe/mediamanager.php';
     } else {
-        $action = media_managerURL(array('tab_details' => 'view'), '&');
+        $action = media_managerURL(array('tab_details' => 'view'));
     }
     echo '<form action="'.$action.'" id="mediamanager__save_meta" accept-charset="utf-8" method="post" class="meta">'.NL;
 
@@ -623,13 +623,13 @@ function media_filelist($ns,$auth=null,$jump='',$fullscreenview=false,$sort=fals
  * Prints mediamanager tab
  *
  * @author Kate Arzamastseva <pshns@ukr.net>
- * @param string $link
- * @param string $class
- * @param string $name
- * @param string $selected
+ * @param string $link - tab href
+ * @param string $class - tab css class
+ * @param string $name - tab caption
+ * @param boolean $selected - is tab selected
  */
 function media_tab($link, $class, $name, $selected=false) {
-    if (!empty($selected) && $selected == $class) $class .= ' selected';
+    if ($selected) $class .= ' selected';
     $tab = '<a href="'.$link.'" class="'.$class.'" >'.$name.'</a>';
     echo $tab;
 }
@@ -638,16 +638,19 @@ function media_tab($link, $class, $name, $selected=false) {
  * Prints tabs for files list actions
  *
  * @author Kate Arzamastseva <pshns@ukr.net>
- * @param string $selected - opened tab
+ * @param string $selected_tab - opened tab
  */
-function media_tabs_files($selected=false){
+function media_tabs_files($selected_tab = ''){
     global $lang;
 
     echo '<div class="mediamanager-tabs" id="mediamanager__tabs_files">';
 
-    media_tab(media_managerURL(array('tab_files' => 'files')), 'files', $lang['mediaselect'], $selected);
-    media_tab(media_managerURL(array('tab_files' => 'upload')), 'upload', $lang['media_uploadtab'], $selected);
-    media_tab(media_managerURL(array('tab_files' => 'search')), 'search', $lang['media_searchtab'], $selected);
+    media_tab(media_managerURL(array('tab_files' => 'files')),
+        'files', $lang['mediaselect'], ($selected_tab == 'files'));
+    media_tab(media_managerURL(array('tab_files' => 'upload')),
+        'upload', $lang['media_uploadtab'], ($selected_tab == 'upload'));
+    media_tab(media_managerURL(array('tab_files' => 'search')),
+        'search', $lang['media_searchtab'], ($selected_tab == 'search'));
 
     echo '<div class="clearer"></div>';
     echo '</div>';
@@ -657,21 +660,24 @@ function media_tabs_files($selected=false){
  * Prints tabs for files details actions
  *
  * @author Kate Arzamastseva <pshns@ukr.net>
- * @param string $selected - opened tab
+ * @param string $selected_tab - opened tab
  */
-function media_tabs_details($image, $selected=false){
+function media_tabs_details($image, $selected_tab = ''){
     global $lang, $conf;
 
     echo '<div class="mediamanager-tabs" id="mediamanager__tabs_details">';
 
-    media_tab(media_managerURL(array('tab_details' => 'view')), 'view', $lang['media_viewtab'], $selected);
+    media_tab(media_managerURL(array('tab_details' => 'view')),
+        'view', $lang['media_viewtab'], ($selected_tab == 'view'));
 
     list($ext, $mime) = mimetype($image);
     if ($mime == 'image/jpeg' && @file_exists(mediaFN($image))) {
-        media_tab(media_managerURL(array('tab_details' => 'edit')), 'edit', $lang['media_edittab'], $selected);
+        media_tab(media_managerURL(array('tab_details' => 'edit')),
+            'edit', $lang['media_edittab'], ($selected_tab == 'edit'));
     }
     if ($conf['mediarevisions']) {
-        media_tab(media_managerURL(array('tab_details' => 'history')), 'history', $lang['media_historytab'], $selected);
+        media_tab(media_managerURL(array('tab_details' => 'history')),
+            'history', $lang['media_historytab'], ($selected_tab == 'history'));
     }
 
     echo '<div class="clearer"></div>';
@@ -799,7 +805,7 @@ function media_tab_view($image, $ns, $auth=null, $rev=false) {
     list($ext,$mime,$dl) = mimetype($image,false);
     $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
     $class = 'select mediafile mf_'.$class;
-    echo '<a class="'.$class.'" >'.$image.'</a>';
+    echo '<span class="'.$class.'" >'.$image.'</span>';
     echo '</div>';
 
     echo '<div class="scroll-container">';
@@ -1532,7 +1538,7 @@ function media_printimgdetail($item, $fullscreen=false){
 
         // output
         if ($fullscreen) {
-            echo '<a name="d_:'.$item['id'].'" class="image'.$index.'" title="'.$item['id'].'" href="'.
+            echo '<a name="'.($index ? 'd' : 'l').'_:'.$item['id'].'" class="image'.$index.'" title="'.$item['id'].'" href="'.
                 media_managerURL(array('image' => hsc($item['id']), 'ns' => getNS($item['id']))).'">';
             echo '<span><img src="'.$src.'" '.$att.' /></span>';
             echo '</a>';
@@ -1576,7 +1582,7 @@ function media_printimgdetail($item, $fullscreen=false){
  * @param string $amp - separator
  * @return string - link
  */
-function media_managerURL($params=false, $amp='&amp;', $abs=false) {
+function media_managerURL($params=false, $amp='&amp;', $abs=false, $params_array=false) {
     global $conf;
     global $ID;
 
@@ -1597,6 +1603,8 @@ function media_managerURL($params=false, $amp='&amp;', $abs=false) {
         unset($gets['tab_details']);
     }
 
+    if ($params_array) return $gets;
+
     return wl($ID,$gets,$abs,$amp);
 }
 
diff --git a/inc/template.php b/inc/template.php
index 569e211b1..c0c83d640 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -1134,7 +1134,7 @@ function tpl_mediaContent($fromajax=false){
  *
  * @author Kate Arzamastseva <pshns@ukr.net>
  */
-function tpl_fileList(){
+function tpl_mediaFileList(){
     global $AUTH;
     global $NS;
     global $JUMPTO;
@@ -1171,7 +1171,7 @@ function tpl_fileList(){
  *
  * @author Kate Arzamastseva <pshns@ukr.net>
  */
-function tpl_fileDetails($image, $rev){
+function tpl_mediaFileDetails($image, $rev){
     global $AUTH, $NS, $conf, $DEL;
 
     $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']);
@@ -1483,11 +1483,11 @@ function tpl_media() {
     echo '</div>';
 
     echo '<div id="mediamanager__layout_list" class="layout-resizable" >';
-    tpl_fileList();
+    tpl_mediaFileList();
     echo '</div>';
 
     echo '<div id="mediamanager__layout_detail" class="layout" >';
-    tpl_fileDetails($image, $rev);
+    tpl_mediaFileDetails($image, $rev);
     echo '</div>';
 
     echo '<div class="clearer"></div>';
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php
index 7fcccd4d9..a6e45c4de 100644
--- a/lib/exe/ajax.php
+++ b/lib/exe/ajax.php
@@ -209,7 +209,7 @@ function ajax_medialist(){
 
     $NS = $_POST['ns'];
     if ($_POST['do'] == 'media') {
-        tpl_fileList();
+        tpl_mediaFileList();
     } else {
         tpl_mediaContent(true);
     }
@@ -232,7 +232,7 @@ function ajax_mediadetails(){
     if (isset($REV) && !$JUMPTO) $rev = $REV;
 
     html_msgarea();
-    tpl_fileDetails($image, $rev);
+    tpl_mediaFileDetails($image, $rev);
 }
 
 /**
@@ -268,7 +268,7 @@ function ajax_mediaupload(){
     $id = cleanID($id, false, true);
 
     if ($res) $result = array('success' => true,
-        'link' => media_managerURL(array('ns' => $NS, 'image' => $id), '&'),
+        'link' => media_managerURL(array('ns' => $NS, 'image' => $NS.':'.$id), '&'),
         'id' => $NS.':'.$id, 'ns' => $NS);
 
     if (!$result) {
diff --git a/lib/exe/css.php b/lib/exe/css.php
index 8f86f2433..81f47d8fa 100644
--- a/lib/exe/css.php
+++ b/lib/exe/css.php
@@ -189,7 +189,7 @@ function css_interwiki(){
 function css_filetypes(){
 
     // default style
-    echo 'a.mediafile {';
+    echo '.mediafile {';
     echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/file.png) 0px 1px no-repeat;';
     echo ' padding-left: 18px;';
     echo ' padding-bottom: 1px;';
@@ -212,7 +212,7 @@ function css_filetypes(){
     }
     foreach($exts as $ext=>$type){
         $class = preg_replace('/[^_\-a-z0-9]+/','_',$ext);
-        echo "a.mf_$class {";
+        echo ".mf_$class {";
         echo '  background-image: url('.DOKU_BASE.'lib/images/fileicons/'.$ext.$type.')';
         echo '}';
     }
diff --git a/lib/tpl/default/mediamanager.css b/lib/tpl/default/mediamanager.css
index 245bb5550..16982d98d 100644
--- a/lib/tpl/default/mediamanager.css
+++ b/lib/tpl/default/mediamanager.css
@@ -291,7 +291,7 @@
 }
 
 #media__content #mediamanager__uploader {
-    border-bottom: 1px solid #8CACBB;
+    border-bottom: 1px solid __border__;
     padding-bottom: 0.5em;
 }
 
-- 
GitLab