Index: /extensions/MostCommented/language/cs_CZ/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/cs_CZ/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/cs_CZ/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Nejcasteji hodnocený';
-$lang['most_commented_cat_hint'] = 'Zobraz nejcasteji hodnocené fotky';
+$lang['Most commented'] = 'Nejcasteji hodnocený';
+$lang['displays most commented pictures'] = 'Zobraz nejcasteji hodnocené fotky';
 
 ?>
Index: /extensions/MostCommented/language/de_DE/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/de_DE/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/de_DE/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Am häufigsten kommentiert';
-$lang['most_commented_cat_hint'] = 'Zeigt die am häufigsten kommentierte Bilder an';
+$lang['Most commented'] = 'Am häufigsten kommentiert';
+$lang['displays most commented pictures'] = 'Zeigt die am häufigsten kommentierte Bilder an';
 
 ?>
Index: /extensions/MostCommented/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/en_UK/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/en_UK/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Most commented';
-$lang['most_commented_cat_hint'] = 'displays most commented pictures';
+$lang['Most commented'] = 'Most commented';
+$lang['displays most commented pictures'] = 'displays most commented pictures';
 
 ?>
Index: /extensions/MostCommented/language/es_ES/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/es_ES/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/es_ES/plugin.lang.php	(revision 27196)
@@ -1,4 +1,4 @@
 <?php
-$lang['most_commented_cat'] = 'Las más comentadas';
-$lang['most_commented_cat_hint'] = 'Visualizar las imágenes más comentadas';
+$lang['Most commented'] = 'Las más comentadas';
+$lang['displays most commented pictures'] = 'Visualizar las imágenes más comentadas';
 ?>
Index: /extensions/MostCommented/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/fr_FR/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/fr_FR/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Plus commentées';
-$lang['most_commented_cat_hint'] = 'afficher les images les plus commentées';
+$lang['Most commented'] = 'Plus commentées';
+$lang['displays most commented pictures'] = 'afficher les images les plus commentées';
 
 ?>
Index: /extensions/MostCommented/language/hu_HU/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/hu_HU/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/hu_HU/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Legtöbb hozzászólás';
-$lang['most_commented_cat_hint'] = 'Megjeleníti a legtöbb hozzászólással rendelkező képeket';
+$lang['Most commented'] = 'Legtöbb hozzászólás';
+$lang['displays most commented pictures'] = 'Megjeleníti a legtöbb hozzászólással rendelkező képeket';
 
 ?>
Index: /extensions/MostCommented/language/it_IT/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/it_IT/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/it_IT/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Le più commentate';
-$lang['most_commented_cat_hint'] = 'visualizzare le immagini le più commentate';
+$lang['Most commented'] = 'Le più commentate';
+$lang['displays most commented pictures'] = 'visualizzare le immagini le più commentate';
 
 ?>
Index: /extensions/MostCommented/language/lv_LV/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/lv_LV/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/lv_LV/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Visvairāk komentētais';
-$lang['most_commented_cat_hint'] = 'rāda visvairāk komentētos attēlus';
+$lang['Most commented'] = 'Visvairāk komentētais';
+$lang['displays most commented pictures'] = 'rāda visvairāk komentētos attēlus';
 
 ?>
Index: /extensions/MostCommented/language/nb_NO/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/nb_NO/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/nb_NO/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Mest kommenterte';
-$lang['most_commented_cat_hint'] = 'vis de mest kommenterte bilder';
+$lang['Most commented'] = 'Mest kommenterte';
+$lang['displays most commented pictures'] = 'vis de mest kommenterte bilder';
 
 ?>
Index: /extensions/MostCommented/language/nl_NL/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/nl_NL/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/nl_NL/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Meeste commentaar';
-$lang['most_commented_cat_hint'] = 'toont meest becommentarieerde afbeeldingen';
+$lang['Most commented'] = 'Meeste commentaar';
+$lang['displays most commented pictures'] = 'toont meest becommentarieerde afbeeldingen';
 
 ?>
Index: /extensions/MostCommented/language/pl_PL/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/pl_PL/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/pl_PL/plugin.lang.php	(revision 27196)
@@ -1,4 +1,4 @@
 <?php
-$lang['most_commented_cat'] = 'Najczęściej komentowane';
-$lang['most_commented_cat_hint'] = 'wyświetla najczęściej komentowane zdjęcia';
+$lang['Most commented'] = 'Najczęściej komentowane';
+$lang['displays most commented pictures'] = 'wyświetla najczęściej komentowane zdjęcia';
 ?>
Index: /extensions/MostCommented/language/ru_RU/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/ru_RU/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/ru_RU/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Самые комментируемые';
-$lang['most_commented_cat_hint'] = 'Смотреть часто комментируемые фотографии';
+$lang['Most commented'] = 'Самые комментируемые';
+$lang['displays most commented pictures'] = 'Смотреть часто комментируемые фотографии';
 
 ?>
Index: /extensions/MostCommented/language/sk_SK/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/sk_SK/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/sk_SK/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Najviac komentované';
-$lang['most_commented_cat_hint'] = 'zobraziť najviac komentované fotografie';
+$lang['Most commented'] = 'Najviac komentované';
+$lang['displays most commented pictures'] = 'zobraziť najviac komentované fotografie';
 
 ?>
Index: /extensions/MostCommented/language/sv_SE/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/sv_SE/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/sv_SE/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Mest kommenterade';
-$lang['most_commented_cat_hint'] = 'Visar mest kommenterade bilder';
+$lang['Most commented'] = 'Mest kommenterade';
+$lang['displays most commented pictures'] = 'Visar mest kommenterade bilder';
 
 ?>
Index: /extensions/MostCommented/language/tr_TR/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/tr_TR/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/tr_TR/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'En çok yorumlananlar';
-$lang['most_commented_cat_hint'] = 'En çok yorumlanan resimleri gösterir';
+$lang['Most commented'] = 'En çok yorumlananlar';
+$lang['displays most commented pictures'] = 'En çok yorumlanan resimleri gösterir';
 
 ?>
Index: /extensions/MostCommented/language/vi_VN/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/vi_VN/plugin.lang.php	(revision 27195)
+++ /extensions/MostCommented/language/vi_VN/plugin.lang.php	(revision 27196)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['most_commented_cat'] = 'Bình luận nhiều nhất';
-$lang['most_commented_cat_hint'] = 'hiển thị ảnh được bình luận nhiều nhất';
+$lang['Most commented'] = 'Bình luận nhiều nhất';
+$lang['displays most commented pictures'] = 'hiển thị ảnh được bình luận nhiều nhất';
 
 ?>
Index: /extensions/MostCommented/main.inc.php
===================================================================
--- /extensions/MostCommented/main.inc.php	(revision 27195)
+++ /extensions/MostCommented/main.inc.php	(revision 27196)
@@ -2,14 +2,31 @@
 /*
 Plugin Name: Most Commented
-Version: 2.0.a
+Version: auto
 Description: Add a "Most Commented" link in "Specials" menu.
-Plugin URI: http://piwigo.org/ext/extension_view.php?eid=145
+Plugin URI: auto
 Author: P@t
 Author URI: http://www.gauchon.com
 */
 
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
 
 define('MOSTCOMMENTED_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
+
+
+add_event_handler('init', 'init_mostcommented');
+
+
+function init_mostcommented()
+{
+  global $conf;
+  
+  if ($conf['activate_comments'])
+  {
+    load_language('plugin.lang', MOSTCOMMENTED_PATH);
+
+    add_event_handler('blockmanager_apply' , 'add_link_mostcommented');
+    add_event_handler('loc_end_section_init', 'section_init_mostcommented');
+  }
+}
 
 function add_link_mostcommented($menu_ref_arr)
@@ -17,16 +34,14 @@
   global $conf;
 
-  $menu = & $menu_ref_arr[0];
+  $menu = &$menu_ref_arr[0];
   $position = (isset($conf['mostcommented_position']) and is_numeric($conf['mostcommented_position'])) ? $conf['mostcommented_position'] : 3;
   
-  if (($block = $menu->get_block('mbSpecials')) != null )
+  if (($block = $menu->get_block('mbSpecials')) != null)
   {
-    load_language('plugin.lang', MOSTCOMMENTED_PATH);
-
     array_splice($block->data, $position-1, 0, array('most_commented' =>
       array(
         'URL' => make_index_url(array('section' => 'most_commented')),
-        'TITLE' => l10n('most_commented_cat_hint'),
-        'NAME' => l10n('most_commented_cat')
+        'TITLE' => l10n('displays most commented pictures'),
+        'NAME' => l10n('Most commented')
         )
       )
@@ -35,13 +50,87 @@
 }
 
-function section_init_most_commented()
+function section_init_mostcommented()
 {
-  global $tokens;
-  if (in_array('most_commented', $tokens))
-    include(MOSTCOMMENTED_PATH . 'most_commented.php');
+  global $tokens, $page, $conf;
+  
+  if (!in_array('most_commented', $tokens))
+  {
+    return;
+  }
+  
+  $page['section'] = 'most_commented';
+  $page['title'] = '<a href="' . duplicate_index_url() . '">' . l10n('Most commented') . '</a>';
+  $page['section_title'] = '<a href="'.get_gallery_home_url().'">' . l10n('Home') . '</a>'
+    . $conf['level_separator'] . $page['title'];
+
+  $query = '
+SELECT DISTINCT image_id
+    FROM ' . IMAGE_CATEGORY_TABLE . '
+    WHERE ' .  
+      get_sql_condition_FandF(
+        array(
+          'forbidden_categories' => 'category_id',
+          'visible_categories' => 'category_id',
+          'visible_images' => 'image_id',
+          ),
+        '', true
+        )
+    . '
+;';
+
+  $img = query2array($query, null, 'image_id');
+
+  if (empty($img))
+  {
+    $page['items'] = array();
+  }
+  else
+  {
+    $query = '
+SELECT
+    img.id,
+    COUNT(*) AS count
+  FROM ' . IMAGES_TABLE . ' AS img
+    INNER JOIN ' . COMMENTS_TABLE . ' AS com
+    ON com.image_id = img.id
+  WHERE
+    img.id IN (' . implode(',', $img) . ')
+    AND com.validated = "true"
+  GROUP BY img.id
+  ORDER BY count DESC, img.hit DESC
+  LIMIT ' . $conf['top_number'] . '
+;';
+    $page['items'] = query2array($query, null, 'id');
+  }
+  
+  add_event_handler('loc_end_index_thumbnails', 'add_nb_comments_mostcommented');
 }
 
-add_event_handler('blockmanager_apply' , 'add_link_mostcommented');
-add_event_handler('loc_end_section_init', 'section_init_most_commented');
+function add_nb_comments_mostcommented($tpl_thumbnails_var)
+{
+  global $template, $user, $selection;
 
-?>
+  // unsed sort order
+  $template->clear_assign('image_orders');
+
+  // display nb comments if hidden by user
+  if (!$user['show_nb_comments'])
+  {
+    $query = '
+SELECT image_id, COUNT(*) AS nb_comments
+  FROM '.COMMENTS_TABLE.'
+  WHERE validated = \'true\'
+    AND image_id IN ('.implode(',', $selection).')
+  GROUP BY image_id
+;';
+    $nb_comments_of = query2array($query, 'image_id', 'nb_comments');
+    
+    foreach ($tpl_thumbnails_var as &$row)
+    {
+      $row['NB_COMMENTS'] = $nb_comments_of[$row['id']];
+    }
+    unset($row);
+  }
+
+  return $tpl_thumbnails_var;
+}
Index: /extensions/MostCommented/maintain.inc.php
===================================================================
--- /extensions/MostCommented/maintain.inc.php	(revision 27195)
+++ /extensions/MostCommented/maintain.inc.php	(revision 27196)
@@ -4,12 +4,12 @@
 {
   $q = pwg_query('SHOW COLUMNS FROM ' . HISTORY_TABLE . ' LIKE "section"');
-  $section = mysql_fetch_array($q);
+  $section = pwg_db_fetch_array($q);
   $type = $section['Type'];
 
   if (substr_count($type, 'most_commented') == 0)
+  {
     $type = strtr($type , array(')' => ',\'most_commented\')'));
+  }
 
   pwg_query('ALTER TABLE ' . HISTORY_TABLE . ' CHANGE section section ' . $type . ' DEFAULT NULL');
 }
-
-?>
Index: tensions/MostCommented/most_commented.php
===================================================================
--- /extensions/MostCommented/most_commented.php	(revision 27195)
+++ 	(revision )
@@ -1,65 +1,0 @@
-<?php
-
-load_language('plugin.lang', MOSTCOMMENTED_PATH);
-
-global $page, $conf;
-
-$page['section'] = 'most_commented';
-
-$forbidden = get_sql_condition_FandF (
-    			array ('forbidden_categories' => 'category_id',
-        			 'visible_categories' => 'category_id',
-        			 'visible_images' => 'image_id'), '', true);
-
-$query = 'SELECT DISTINCT image_id
-    FROM ' . IMAGE_CATEGORY_TABLE . '
-    WHERE ' .  $forbidden . ';';
-
-$img = array_from_query($query, 'image_id');
-
-if (empty($img)) $img = array(0);
-
-$query = 'SELECT img.id, COUNT(*)
-  FROM ' . IMAGES_TABLE . ' AS img
-  INNER JOIN ' . COMMENTS_TABLE . ' AS com
-  ON com.image_id = img.id
-  AND com.validated = "true"
-  WHERE img.id IN (' . implode(',', $img) . ')
-  GROUP BY img.id
-  ORDER BY 2 DESC, img.hit DESC
-  LIMIT 0, ' . $conf['top_number'] . ';';
-
-$page = array_merge($page,
-    array('title' => '<a href="' . duplicate_index_url() . '">'
-         . $conf['top_number'] . ' ' . l10n('most_commented_cat') . '</a>',
-        'items' => array_from_query($query, 'id')));
-
-
-add_event_handler('loc_end_index_thumbnails', 'add_mostcommented_nb_comments');
-
-function add_mostcommented_nb_comments($tpl_thumbnails_var)
-{
-  global $template, $user;
-
-  // Suppression de l'ordre de trie
-  $template->clear_assign('image_orders');
-
-  // Affichage du nombre de commentaires si désactivé pour l'utilisateur
-  if (!$user['show_nb_comments'])
-  {
-    foreach ($tpl_thumbnails_var as $key => $row)
-    {
-      $query = 'SELECT COUNT(*) AS nb_comments
-        FROM '.COMMENTS_TABLE.'
-        WHERE image_id = '.$row['ID'].'
-        AND validated = "true";';
-
-      list($nb_comments) = mysql_fetch_array(pwg_query($query));
-
-      $tpl_thumbnails_var[$key]['NAME'] = '(' . $nb_comments . ') ' . $tpl_thumbnails_var[$key]['NAME'];
-    }
-  }
-
-  return $tpl_thumbnails_var;
-}
-?>
