Index: /extensions/MostCommented/language/en_UK/index.php
===================================================================
--- /extensions/MostCommented/language/en_UK/index.php	(revision 3299)
+++ /extensions/MostCommented/language/en_UK/index.php	(revision 3299)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/MostCommented/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/en_UK/plugin.lang.php	(revision 3299)
+++ /extensions/MostCommented/language/en_UK/plugin.lang.php	(revision 3299)
@@ -0,0 +1,6 @@
+<?php
+
+$lang['most_commented_cat'] = 'Most commented';
+$lang['most_commented_cat_hint'] = 'displays most commented pictures';
+
+?>
Index: /extensions/MostCommented/language/fr_FR/index.php
===================================================================
--- /extensions/MostCommented/language/fr_FR/index.php	(revision 3299)
+++ /extensions/MostCommented/language/fr_FR/index.php	(revision 3299)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/MostCommented/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/MostCommented/language/fr_FR/plugin.lang.php	(revision 3299)
+++ /extensions/MostCommented/language/fr_FR/plugin.lang.php	(revision 3299)
@@ -0,0 +1,6 @@
+<?php
+
+$lang['most_commented_cat'] = 'Plus commentées';
+$lang['most_commented_cat_hint'] = 'afficher les images les plus commentées';
+
+?>
Index: /extensions/MostCommented/main.inc.php
===================================================================
--- /extensions/MostCommented/main.inc.php	(revision 3299)
+++ /extensions/MostCommented/main.inc.php	(revision 3299)
@@ -0,0 +1,47 @@
+<?php
+/*
+Plugin Name: Most Commented
+Version: 2.0.a
+Description: Ajoute un lien "Plus commentées" dans le menu "Spéciales"/ Add a "Most Commented" link in "Specials" menu.
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=145
+Author: P@t
+Author URI: http://www.gauchon.com
+*/
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+define('MOSTCOMMENTED_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
+
+function add_link_mostcommented($menu_ref_arr)
+{
+  global $conf;
+
+  $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 )
+  {
+    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')
+        )
+      )
+    );
+  }
+}
+
+function section_init_most_commented()
+{
+  global $tokens;
+  if (in_array('most_commented', $tokens))
+    include(MOSTCOMMENTED_PATH . 'most_commented.php');
+}
+
+add_event_handler('blockmanager_apply' , 'add_link_mostcommented');
+add_event_handler('loc_end_section_init', 'section_init_most_commented');
+
+?>
Index: /extensions/MostCommented/maintain.inc.php
===================================================================
--- /extensions/MostCommented/maintain.inc.php	(revision 3299)
+++ /extensions/MostCommented/maintain.inc.php	(revision 3299)
@@ -0,0 +1,15 @@
+<?php
+
+function plugin_install()
+{
+  $q = pwg_query('SHOW COLUMNS FROM ' . HISTORY_TABLE . ' LIKE "section"');
+  $section = mysql_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: /extensions/MostCommented/most_commented.php
===================================================================
--- /extensions/MostCommented/most_commented.php	(revision 3299)
+++ /extensions/MostCommented/most_commented.php	(revision 3299)
@@ -0,0 +1,65 @@
+<?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;
+}
+?>
