diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index bd00c8ae2ccc980c73646234bfdd4f945a4f394e..0787f27d630e52a9751272cda9e723524bea818e 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -12,6 +12,7 @@ Drupal x.x.x, xxxx-xx-xx
 - flood control mechanism:
     * added a mechanism to throttle certain operations.
 - usability:
+    * refactored the statistics and log pages.
     * refactored the throttle module configuration.
     * added a 'add child page' link to book pages.
 - multi-site configuration:
diff --git a/cron.php b/cron.php
index 01e10eb3b1da6a6c84c49032ff3246472759fc01..889ea00d42ca872c8e91827a7d8745167bfb4a15 100644
--- a/cron.php
+++ b/cron.php
@@ -16,7 +16,7 @@
 
 // Check if the last cron run completed
 if (variable_get('cron_busy', false)) {
-  watchdog('warning', t('Last cron run did not complete.'));
+  watchdog('cron', t('Last cron run did not complete.'));
 }
 else {
   variable_set('cron_busy', true);
@@ -27,6 +27,6 @@
 
 // Clean up
 variable_set('cron_busy', false);
-watchdog('regular', t('Cron run completed'));
+watchdog('cron', t('Cron run completed'));
 
 ?>
diff --git a/database/database.mysql b/database/database.mysql
index 9f2ef285f07a669852b2fb29681b50aeeef4e977..0be5db11ffdedb427f65d0c946aaa99af0f6ac73 100644
--- a/database/database.mysql
+++ b/database/database.mysql
@@ -20,13 +20,15 @@ CREATE TABLE access (
 --
 
 CREATE TABLE accesslog (
+  aid tinyint(10) NOT NULL auto_increment,
   title varchar(255) default NULL,
   path varchar(255) default NULL,
   url varchar(255) default NULL,
   hostname varchar(128) default NULL,
   uid int(10) unsigned default '0',
   timestamp int(11) unsigned NOT NULL default '0',
-  KEY accesslog_timestamp (timestamp)
+  KEY accesslog_timestamp (timestamp),
+  PRIMARY KEY  (aid)
 ) TYPE=MyISAM;
 
 --
diff --git a/database/database.pgsql b/database/database.pgsql
index 92ba88c674cbb9aa3827d79cdc185c28fbbfd975..df50d5d84ca5d58e4ec51bdc78bd0b8a395a0b26 100644
--- a/database/database.pgsql
+++ b/database/database.pgsql
@@ -18,12 +18,15 @@ CREATE TABLE access (
 --
 
 CREATE TABLE accesslog (
+  aid SERIAL,
+  mask varchar(255) NOT NULL default '',
   title varchar(255) default NULL,
   path varchar(255) default NULL,
   url varchar(255) default NULL,
   hostname varchar(128) default NULL,
   uid integer default '0',
-  timestamp integer NOT NULL default '0'
+  timestamp integer NOT NULL default '0',
+  PRIMARY KEY (aid)
 );
 CREATE INDEX accesslog_timestamp_idx ON accesslog (timestamp);
 
diff --git a/database/updates.inc b/database/updates.inc
index c5881f8d3dbf3d9dfcb6cfe6fac6484a0b6f9d3e..a0b1097e9bd11ffe00981ac333ad79b83bcaa415 100644
--- a/database/updates.inc
+++ b/database/updates.inc
@@ -88,7 +88,8 @@
   "2004-10-18" => "update_109",
   "2004-10-31: first update since Drupal 4.5.0 release" => "update_110",
   "2004-11-07" => "update_111",
-  "2004-11-15" => "update_112"
+  "2004-11-15" => "update_112",
+  "2004-11-28" => "update_113"
 );
 
 function update_32() {
@@ -1991,6 +1992,29 @@ function update_112() {
   return $ret;
 }
 
+function update_113() {
+  $ret = array();
+
+  if ($GLOBALS['db_type'] == 'mysql') {
+    $ret[] = update_sql('DROP TABLE {accesslog}');
+    $ret[] = update_sql("CREATE TABLE {accesslog} (
+        aid tinyint(10) NOT NULL auto_increment,
+        title varchar(255) default NULL,
+        path varchar(255) default NULL,
+        url varchar(255) default NULL,
+        hostname varchar(128) default NULL,
+        uid int(10) unsigned default '0',
+        timestamp int(11) unsigned NOT NULL default '0',
+        KEY accesslog_timestamp (timestamp),
+        PRIMARY KEY  (aid))");
+  }
+
+  // Flush the menu cache:
+  cache_clear_all('menu:', TRUE);
+
+  return $ret;
+}
+
 function update_sql($sql) {
   $edit = $_POST["edit"];
   $result = db_query($sql);
diff --git a/includes/common.inc b/includes/common.inc
index 87ac73d4b2d5147c41a8090c5ce5f3b2a534cc25..c7b22d1ebec02439553aa7f3299475e6500d5c78 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -166,7 +166,7 @@ function drupal_goto($path = '', $query = NULL, $fragment = NULL) {
  */
 function drupal_not_found() {
   header('HTTP/1.0 404 Not Found');
-  watchdog('httpd', t('404 error: %page not found.', array('%page' => '<em>'. db_escape_string($_GET['q']) .'</em>')));
+  watchdog('page not found', t('%page not found.', array('%page' => '<em>'. db_escape_string($_GET['q']) .'</em>')));
 
   $path = drupal_get_normal_path(variable_get('site_404', ''));
   $status = MENU_NOT_FOUND;
@@ -185,6 +185,7 @@ function drupal_not_found() {
  */
 function drupal_access_denied() {
   header('HTTP/1.0 403 Forbidden');
+  watchdog('access denied', t('%page denied access.', array('%page' => '<em>'. db_escape_string($_GET['q']) .'</em>')));
 
   $path = drupal_get_normal_path(variable_get('site_403', ''));
   $status = MENU_NOT_FOUND;
@@ -339,7 +340,7 @@ function error_handler($errno, $message, $filename, $line, $variables) {
     $types = array(1 => 'error', 2 => 'warning', 4 => 'parse error', 8 => 'notice', 16 => 'core error', 32 => 'core warning', 64 => 'compile error', 128 => 'compile warning', 256 => 'user error', 512 => 'user warning', 1024 => 'user notice', 2048 => 'strict warning');
     $entry = $types[$errno] .': '. $message .' in '. $filename .' on line '. $line .'.';
 
-    watchdog('error', t('%error: %message in %file on line %line.', array('%error' => $types[$errno], '%message' => $message, '%file' => $filename, '%line' => $line)));
+    watchdog('error', t('%message in %file on line %line.', array('%error' => $types[$errno], '%message' => $message, '%file' => $filename, '%line' => $line)));
 
     if (variable_get('error_level', 1) == 1) {
       print '<pre>'. $entry .'</pre>';
diff --git a/modules/aggregator.module b/modules/aggregator.module
index b9436b975d617578b36762faab508e3faf397d93..83f8d61138f35fa875c1ee1ec34ecac83dc06968 100644
--- a/modules/aggregator.module
+++ b/modules/aggregator.module
@@ -388,7 +388,7 @@ function aggregator_refresh($feed) {
 
         cache_clear_all();
 
-        watchdog('regular', t('Aggregator: syndicated content from %site.', array('%site' => '<em>'. $feed[title] .'</em>')));
+        watchdog('status', t('Aggregator: syndicated content from %site.', array('%site' => '<em>'. $feed[title] .'</em>')));
         drupal_set_message(t('Syndicated content from %site.', array('%site' => '<em>'. $feed['title'] .'</em>')));
       }
       break;
diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module
index b9436b975d617578b36762faab508e3faf397d93..83f8d61138f35fa875c1ee1ec34ecac83dc06968 100644
--- a/modules/aggregator/aggregator.module
+++ b/modules/aggregator/aggregator.module
@@ -388,7 +388,7 @@ function aggregator_refresh($feed) {
 
         cache_clear_all();
 
-        watchdog('regular', t('Aggregator: syndicated content from %site.', array('%site' => '<em>'. $feed[title] .'</em>')));
+        watchdog('status', t('Aggregator: syndicated content from %site.', array('%site' => '<em>'. $feed[title] .'</em>')));
         drupal_set_message(t('Syndicated content from %site.', array('%site' => '<em>'. $feed['title'] .'</em>')));
       }
       break;
diff --git a/modules/drupal.module b/modules/drupal.module
index 8ad5395dd38ccb2d449ee53860c5666100b957a3..64844c21573da04ebadb7e0e4727309806d0c443 100644
--- a/modules/drupal.module
+++ b/modules/drupal.module
@@ -95,7 +95,7 @@ function drupal_directory_ping($arguments) {
     db_query("DELETE FROM {directory} WHERE link = '%s' OR mail = '%s'", $link, $mail);
     db_query("INSERT INTO {directory} (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time());
 
-    watchdog('regular', t('Directory: ping from %name (%link).', array('%name' => "<em>$name</em>", '%link' => "<em>$link</em>")));
+    watchdog('drectory ping', t('ping from %name (%link).', array('%name' => "<em>$name</em>", '%link' => "<em>$link</em>")));
 
     return new xmlrpcresp(new xmlrpcval(1, 'int'));
   }
diff --git a/modules/drupal/drupal.module b/modules/drupal/drupal.module
index 8ad5395dd38ccb2d449ee53860c5666100b957a3..64844c21573da04ebadb7e0e4727309806d0c443 100644
--- a/modules/drupal/drupal.module
+++ b/modules/drupal/drupal.module
@@ -95,7 +95,7 @@ function drupal_directory_ping($arguments) {
     db_query("DELETE FROM {directory} WHERE link = '%s' OR mail = '%s'", $link, $mail);
     db_query("INSERT INTO {directory} (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time());
 
-    watchdog('regular', t('Directory: ping from %name (%link).', array('%name' => "<em>$name</em>", '%link' => "<em>$link</em>")));
+    watchdog('drectory ping', t('ping from %name (%link).', array('%name' => "<em>$name</em>", '%link' => "<em>$link</em>")));
 
     return new xmlrpcresp(new xmlrpcval(1, 'int'));
   }
diff --git a/modules/statistics.module b/modules/statistics.module
index a9a59e2632ade282d468ac82f88c2886c6325ef4..11163a5aaee44e8b14e4c27b0f4a2262f195bcb9 100644
--- a/modules/statistics.module
+++ b/modules/statistics.module
@@ -27,50 +27,26 @@ function statistics_help($section) {
       <li>If you enable the access log, this adds 1 database query for each page that Drupal displays.  Logged information includes:  HTTP referrer (if any), node being accessed (if any), user ID (if any), the IP address of the user, and the time the page was viewed.</li>
       </ul>
       <p>As with any new module, the statistics module needs to be <a href=\"%modules\">enabled</a> before you can use it.  Also refer to the <a href=\"%permissions\">permissions section</a>, as this module supports four separate permissions.</p>
-      <h3><a href=\"%referers\">referrers log</a></h3>
-      <p>This admin page shows you site-wide referrer statistics.  You can see <em>'all'</em> statistics, <em>'external'</em> statistics or <em>'internal'</em> statistics.  Default is 'all'.</p>
-      <h3><a href=\"%access\">access log</a></h3>
-      <p>This admin page gives you an at-a-glance look at your most popular content.  It is useful for understanding what content on your Drupal site is the most popular.  Also on this page are links to the referrer statistics for each listed node.</p>
       <h3>Configuring the statistics module</h3>
       <p>There are some configuration options added to the main <a href=\"%configuration\">administer &raquo; settings &raquo; statistics</a> section:</p>
       <ul>
       <li><em>enable access log</em> -- allows you to turn the access log on and off.  This log is used to store data about every page accessed, such as the remote host's IP address, where they came from (referrer), what node they've viewed, and their user name.  Enabling the log adds one database call per page displayed by Drupal.</li>
       <li><em>discard access logs older than</em> -- allows you to configure how long an access log entry is saved, after which time it is deleted from the database table. To use this you need to run \"cron.php\"</li>
       <li><em>enable node view counter</em> -- allows you to turn on and off the node-counting functionality of this module.  If it is turned on, an extra database query is added for each node displayed, which increments a counter.</li>
-      <li><em>display node view counters</em> -- allows you to globally disable the displaying of node view counters.  Additionally, a user group must have 'access statistics' permissions to view the counters.</li>
+      <li><em>display node view counters</em> -- allows you to globally disable the displaying of node view counters.</li>
       </ul>
       <h3>Popular content block</h3>
       <p>This module creates a block that can display the day's top viewed content, the all time top viewed content, and the last content viewed.  Each of these links can be enabled or disabled individually, and the number of posts displayed for each can be configured with a drop down menu.  If you disable all sections of this block, it will not appear.</p>
-      <p>Don't forget to <a href=\"%block\">enable the block</a>.</p>
-      <h3>Popular content page</h3>
-      <p>This module creates a user page that can display summaries of the day's most popular viewed content, the all time most popular content, and the last content viewed.  Each of these summaries can be enabled or disabled individually, and the number of posts displayed for each can be configured with a drop down menu.  You can also assign a name for the automatically generated link to the user page.  If no name is set, the link will not be displayed.</p>
-      <h3>Permissions</h3><p>This module has four permissions that need to be configured in the <a href=\"%permissions\">permissions section</a>.</p>
-      <ul>
-      <li><em>access statistics</em> - enable for user roles that get to see view counts for individual content.  (This does not define access to the block)</li>
-      <li><em>administer statistics module</em> - enable for user roles that get to configure the statistics module.</li><li><em>administer statistics</em> - enable for user roles that get to view the referrer statistics.</li>
-      </ul>
-      <p>If '<em>administer statistics</em>' and '<em>access statistics</em>' are both enabled, the user will see a link from each node to that node's referrer statistics (if enabled).</p>",
-      array('%modules' => url('admin/modules'), '%permissions' => url('admin/user/configure/permission'), '%referer' => url('admin/logs/hits/referrers'), '%access' => url('admin/logs/access'), '%configuration' => url('admin/settings/statistics'), '%block' => url('admin/block')));
+      <p>Don't forget to <a href=\"%block\">enable the block</a>.</p>",
+      array('%modules' => url('admin/modules'), '%permissions' => url('admin/user/configure/permission'), '%referer' => url('admin/logs/referrers'), '%configuration' => url('admin/settings/statistics'), '%block' => url('admin/block')));
     case 'admin/modules#description':
       return t('Logs access statistics for your site.');
     case 'admin/settings/statistics':
       return t('Settings for the statistical information that Drupal will keep about the site. See <a href="%statistics">site statistics</a> for the actual information.', array('%statistics' => url('admin/logs/hits')));
-    case 'admin/logs/hits/posts':
-      return t('This page gives you an at-a-glance look at your most popular content.');
-    case 'admin/logs/hits/pages':
-      return t('This page shows access statistics for each page of your website.');
-    case 'admin/logs/hits/users':
-      return t('This page shows access statistics for each user of your website.');
-    case 'admin/logs/hits/hostnames':
-      return t('This page shows access statistics for each hostname visiting your website.');
+    case 'admin/logs/hits':
+      return t('This page shows you the most recent hits.');
     case 'admin/logs/referrers':
-      return t('This page shows your site-wide referrer statistics.  You can optionally view just the "external referrers" or the "internal referrers". Referrers are web pages, both local and on other sites, that point to your web site.');
-    case 'admin/logs/referrers/internal':
-      return t('This page shows you only "internal referrers". These are links pointing to your web site from within your web site.');
-    case 'admin/logs/referrers/external':
-      return t('This page shows you only "external referrers". These are links pointing to your web site from outside your web site.');
-    case strstr($section, 'admin/logs/hits'):
-      return t("This page shows you who is accessing your web site.  You can see the hostnames and referrers.  For example, it is easy to inspect a user's navigation history/trail by clicking on <em>track user</em>.");
+      return t('This page shows you all external referrers. These are links pointing to your web site from outside your web site.');
   }
 }
 
@@ -107,15 +83,9 @@ function statistics_exit() {
 
 /**
  * Implementation of hook_perm().
- *
- * The following permissions are defined:
- * - "administer statistics module": full administrative control of module
- * - "administer statistics": view statistics / referrer log
- * - "access statistics": see how many times individual nodes have been
- *   viewed (if enabled)
  */
 function statistics_perm() {
-  return array('administer statistics module', 'administer statistics', 'access statistics');
+  return array('access statistics');
 }
 
 /**
@@ -126,15 +96,10 @@ function statistics_link($type, $node = 0, $main = 0) {
 
   $links = array();
 
-  if ($type != 'comment' && user_access('access statistics') && variable_get('statistics_display_counter', 0)) {
+  if ($type != 'comment' && variable_get('statistics_display_counter', 0)) {
     $statistics = statistics_get($node->nid);
     if ($statistics) {
-      if (user_access('administer statistics')) {
-        $links[] = l(format_plural($statistics['totalcount'], '1 read', '%count reads'), 'admin/logs/hits/page/'. urlencode($node->title));
-      }
-      else {
-        $links[] = format_plural($statistics['totalcount'], '1 read', '%count reads');
-      }
+      $links[] = format_plural($statistics['totalcount'], '1 read', '%count reads');
     }
   }
   return $links;
@@ -146,290 +111,216 @@ function statistics_link($type, $node = 0, $main = 0) {
 function statistics_menu($may_cache) {
   $items = array();
 
+  $access = user_access('access statistics');
   if ($may_cache) {
-    $items[] = array('path' => 'statistics', 'title' => t('most popular content'),
-      'callback' => 'statistics_page',
-      'access' => user_access('access content'),
-      'type' => MENU_SUGGESTED_ITEM);
-
-    $access = user_access('administer statistics module') || user_access('administer statistics');
-    $items[] = array('path' => 'admin/logs/hits', 'title' => t('hits'),
-      'callback' => 'statistics_admin_displaylog', 'access' => $access,
+    $items[] = array('path' => 'admin/logs/hits', 'title' => t('recent hits'),
+      'callback' => 'statistics_recent_hits', 'access' => $access,
       'weight' => 3);
-    $items[] = array('path' => 'admin/logs/hits/posts', 'title' => t('posts'),
-      'callback' => 'statistics_admin_content', 'access' => $access,
-      'weight' => 1);
-    $items[] = array('path' => 'admin/logs/hits/pages', 'title' => t('pages'),
-      'callback' => 'statistics_top_titles', 'access' => $access,
+    $items[] = array('path' => 'admin/logs/pages', 'title' => t('top pages'),
+      'callback' => 'statistics_top_pages', 'access' => $access,
       'weight' => 1);
-    $items[] = array('path' => 'admin/logs/hits/users', 'title' => t('users'),
+    $items[] = array('path' => 'admin/logs/users', 'title' => t('top users'),
       'callback' => 'statistics_top_users', 'access' => $access,
       'weight' => 2);
-    $items[] = array('path' => 'admin/logs/hits/hostnames',
-      'title' => t('hostnames'), 'callback' => 'statistics_top_hostnames',
-      'access' => $access, 'weight' => 3);
-    $items[] = array('path' => 'admin/logs/referrers',
-      'title' => t('referrers'), 'callback' => 'statistics_top_referrers',
-      'access' => $access, 'weight' => 4);
-    $items[] = array('path' => 'admin/logs/referrers/internal',
-      'title' => t('internal'), 'access' => $access);
-    $items[] = array('path' => 'admin/logs/referrers/external',
-      'title' => t('external'), 'access' => $access);
+    $items[] = array('path' => 'admin/logs/referrers', 'title' => t('referrers'),
+      'callback' => 'statistics_top_referrers', 'access' => $access);
+    $items[] = array('path' => 'admin/logs/access', 'title' => t('details'),
+      'callback' => 'statistics_access_log', 'access' => $access,
+      'type' => MENU_CALLBACK);
+  }
+  else {
+    if (arg(0) == 'user' && is_numeric(arg(1))) {
+      $items[] = array('path' => 'user/'. arg(1) .'/track/navigation', 'title' => t('track page visits'),
+        'callback' => 'statistics_user_tracker', 'access' => $access,
+        'type' => MENU_LOCAL_TASK, 'weight' => 2);
+    }
+    if (arg(0) == 'node' && is_numeric(arg(1))) {
+      $items[] = array('path' => 'node/'. arg(1) .'/track', 'title' => t('track'),
+        'callback' => 'statistics_node_tracker', 'access' => $access,
+        'type' => MENU_LOCAL_TASK, 'weight' => 2);
+    }
   }
 
   return $items;
 }
 
-/**
- * Menu callback; presents the "Access logs" page.
- *
- * @param $type
- *   - "user":  display accesses for a particular user.
- *   - "title": display accesses of a particular title.
- *   - "host":  display accesses originated at a given IP.
- *   - "all":   display all accesses.
- *
- * @param $value
- *   The user, host, or node to filter by.
- */
-function statistics_admin_displaylog($type = 'all', $id = 0) {
-  switch ($type) {
-    case 'user':
-      if ($id) {
-        // retrieve recent access logs for specific user $id
-        $user = user_load(array('uid' => $id));
-        $page_title = t('Recent hits for "%username"', array('%username' => $user->name));
-        $sql = 'SELECT title, path, url, hostname, uid, timestamp FROM {accesslog} WHERE uid = \''. db_escape_string($id) ."'";
-      }
-      else {
-        // retrieve recent access logs for all users (not guests)
-        $page_title = t('Recent hits for all users');
-        $sql = 'SELECT title, path, url, hostname, uid, MAX(timestamp) AS timestamp FROM {accesslog} WHERE uid <> 0 GROUP BY uid, title, path, url, hostname';
-      }
-      break;
-    case 'page':
-      // retrieve recent access logs for title $id
-      $page_title = t('Recent hits for "%title"', array('%title' => $id));
-      $sql = 'SELECT title, path, url, hostname, uid, timestamp FROM {accesslog} WHERE title = \''. db_escape_string($id) ."'";
-      break;
-    case 'host':
-      // retrieve recent access logs for hostname $id
-      $page_title = t('Recent hits for "%hostname"', array('%hostname' => $id));
-      $sql = 'SELECT title, path, url, hostname, uid, timestamp, title FROM {accesslog} WHERE hostname = \''. db_escape_string($id) ."'";
-      break;
-    case 'all':
-    default:
-      // retrieve all recent access logs
-      $page_title = t('Recent hits');
-      $sql = 'SELECT title, path, url, hostname, uid, timestamp FROM {accesslog}';
+function statistics_access_log($aid) {
+  $result = db_query('SELECT a.*, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE aid = %d', $aid);
+  if ($access = db_fetch_object($result)) {
+    $output  = '<table border="1" cellpadding="2" cellspacing="2">';
+    $output .= ' <tr><th>'. t('Page URL') ."</th><td>". l(url($access->path, NULL, NULL, TRUE), $access->url) ."</td></tr>";
+    $output .= ' <tr><th>'. t('Page title') ."</th><td>$access->title</td></tr>";
+    $output .= ' <tr><th>'. t('Referrer') ."</th><td>". ($access->url ? l($access->url, $access->url) : '') ."</td></tr>";
+    $output .= ' <tr><th>'. t('Date') .'</th><td>'. format_date($access->timestamp, 'large') .'</td></tr>';
+    $output .= ' <tr><th>'. t('User') .'</th><td>'. format_name($access) .'</td></tr>';
+    $output .= ' <tr><th>'. t('Hostname') ."</th><td>$watchdog->hostname</td></tr>";
+    $output .= '</table>';
+    print theme('page', $output);
+  }
+  else {
+    drupal_not_found();
   }
+}
 
-  $header = array(
-    array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
-    array('data' => t('Page'), 'field' => 'title'),
-    array('data' => t('User'), 'field' => 'uid'),
-    array('data' => t('Hostname'), 'field' => 'hostname'),
-    array('data' => t('Referrer'), 'field' => 'url'),
-    array('data' => t('Operations'), 'colspan' => '3')
-  );
+function statistics_node_tracker() {
+  if ($node = node_load(array('nid' => arg(1)))) {
+
+    $header = array(
+        array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'),
+        array('data' => t('Referrer'), 'field' => 'a.url'),
+        array('data' => t('User'), 'field' => 'u.name'),
+        array('data' => t('Operations')));
+
+    $result = pager_query('SELECT a.aid, a.timestamp, a.url, a.uid, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE a.path LIKE \'node/'. db_escape_string($node->nid) ."%'" . tablesort_sql($header), 30);
+    while ($log = db_fetch_object($result)) {
+      $rows[] = array(
+        array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'),
+        l($log->url, $log->url),
+        format_name($log),
+        l(t('details'), "admin/logs/access/$log->aid"));
+    }
 
-  $sql .= tablesort_sql($header);
+    if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+      $rows[] = array(array('data' => $pager, 'colspan' => '4'));
+    }
 
-  $result = pager_query($sql, 50);
-  while ($log = db_fetch_object($result)) {
+    print theme('page', theme('table', $header, $rows), $node->title);
+  }
+  else {
+    drupal_not_found();
+  }
+}
 
-    // display title if possible, otherwise display path
-    if ($log->title)
-      $title = l(_statistics_column_width($log->title), $log->path, array('title' => $log->path));
-    else
-      $title = '('. l(_statistics_column_width($log->path), $log->path, array('title' => $log->path)) .')';
+function statistics_user_tracker() {
+  if ($account = user_load(array('uid' => arg(1)))) {
 
-    // display url if possible, constructing our own link as may not be local
-    if ($log->url)
-      $url = "<a href=\"$log->url\" title=\"$log->url\">". _statistics_column_width($log->url) .'</a>';
-    else
-      $url = message_na();
+    $header = array(
+        array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
+        array('data' => t('Page'), 'field' => 'path'),
+        array('data' => t('Operations')));
 
-    $user = user_load(array('uid' => $log->uid));
-    $rows[] = array(array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'), $title, format_name($user), $log->hostname ? $log->hostname : message_na(), $url, ($user->uid ? l(t('track user'), "admin/logs/hits/user/$user->uid") : ''), ($log->title ? l(t('track title'), 'admin/logs/hits/page/'. urlencode($log->title)) : ''), ($log->hostname ? l(t('track host'), "admin/logs/hits/host/$log->hostname") : ''));
-  }
+    $result = pager_query('SELECT aid, timestamp, path, title FROM {accesslog} WHERE uid = \''. db_escape_string($account->uid) ."'" . tablesort_sql($header), 30);
+    while ($log = db_fetch_object($result)) {
+      $rows[] = array(
+        array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'),
+        $log->title ."<br />". l($log->path, $log->path),
+        l(t('details'), "admin/logs/access/$log->aid"));
+    }
 
-  if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '8'));
-  }
+    if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+      $rows[] = array(array('data' => $pager, 'colspan' => '3'));
+    }
 
-  $output = theme('table', $header, $rows);
-  print theme('page', $output, $page_title);
+    print theme('page', theme('table', $header, $rows), $account->name);
+  }
+  else {
+    drupal_not_found();
+  }
 }
 
 /**
- * Menu callback; presents the "Top pages" page.
+ * Menu callback; presents the "Recent hits" page.
  */
-function statistics_top_titles() {
-  $sql = "SELECT title, path, MAX(timestamp) AS last_hit, COUNT(title) AS hits FROM {accesslog} WHERE title <> '' GROUP BY title, path";
-  $sql_cnt = "SELECT COUNT(DISTINCT(title)) FROM {accesslog} WHERE title <> ''";
-  $describe = t('Top pages in the past %interval');
-
-  $page_title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
+function statistics_recent_hits($type = 'all', $id = 0) {
 
   $header = array(
-    array('data' => t('Page'), 'field' => 'title'),
-    array('data' => t('Path'), 'field' => 'path'),
-    array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
-    array('data' => t('Last hit'), 'field' => 'last_hit'),
+    array('data' => t('Timestamp'), 'field' => 'a.timestamp', 'sort' => 'desc'),
+    array('data' => t('Page'), 'field' => 'a.path'),
+    array('data' => t('User'), 'field' => 'u.name'),
     array('data' => t('Operations'))
   );
-  $sql .= tablesort_sql($header);
-  $result = pager_query($sql, 50, 0, $sql_cnt);
 
-  while ($title = db_fetch_object($result)) {
-    $rows[] = array(l(_statistics_column_width($title->title, '_title', 56), $title->path), _statistics_column_width($title->path, '_title', 56), $title->hits, format_date($title->last_hit, 'small'), ($title->title ? l(t('track title'), 'admin/logs/hits/page/'. urlencode($title->title)) : ''));
+  $sql = 'SELECT a.aid, a.path, a.title, a.uid, u.name, a.timestamp FROM {accesslog} a LEFT JOIN {users} u ON u.uid = a.uid' . tablesort_sql($header);
+
+  $result = pager_query($sql, 30);
+  while ($log = db_fetch_object($result)) {
+    $rows[] = array(
+      array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'),
+      $log->title .'<br />'. l($log->path, $log->path),
+      format_name($log),
+      l(t('details'), "admin/logs/access/$log->aid"));
   }
-  if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '5'));
+
+  if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+    $rows[] = array(array('data' => $pager, 'colspan' => '4'));
   }
 
-  $output = theme('table', $header, $rows);
-  print theme('page', $output, $page_title);
+  print theme('page', theme('table', $header, $rows), t('Recent hits'));
 }
 
 /**
- * Menu callback; presents the "Top users" page.
+ * Menu callback; presents the "Top pages" page.
  */
-function statistics_top_users() {
-  $sql = "SELECT uid, hostname, MAX(timestamp) AS last_hit, COUNT(uid) AS hits FROM {accesslog} GROUP BY uid, hostname";
-  $sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {accesslog}";
-  $describe = t('Top users in the past %interval');
-
-  $page_title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
+function statistics_top_pages() {
+  $sql = "SELECT COUNT(path) AS hits, path, title FROM {accesslog} GROUP BY path";
+  $sql_cnt = "SELECT COUNT(DISTINCT(path)) FROM {accesslog}";
 
   $header = array(
-    array('data' => t('User'), 'field' => 'user'),
-    array('data' => t('Hostname'), 'field' => 'hostname'),
     array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
-    array('data' => t('Last hit'), 'field' => 'last_hit'),
-    array('data' => t('Operations'), 'colspan' => '2')
+    array('data' => t('Page'), 'field' => 'path')
   );
   $sql .= tablesort_sql($header);
-  $result = pager_query($sql, 50, 0, $sql_cnt);
+  $result = pager_query($sql, 30, 0, $sql_cnt);
 
-  while ($u = db_fetch_object($result)) {
-    $user = user_load(array('uid' => $u->uid));
-    $rows[] = array(format_name($user), $u->hostname, $u->hits, format_date($u->last_hit, 'small'), ($u->uid ? l(t('track user'), "admin/logs/hits/user/$user->uid") : ''), ($u->hostname ? l(t('track host'), "admin/logs/hits/host/$u->hostname") : ''));
+  while ($page = db_fetch_object($result)) {
+    $rows[] = array($page->hits, $page->title .'<br />'. l($page->path, $page->path));
   }
-  if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '6'));
+  if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+    $rows[] = array(array('data' => $pager, 'colspan' => '2'));
   }
 
-  $output = theme('table', $header, $rows);
-  print theme('page', $output, $page_title);
+  print theme('page', theme('table', $header, $rows), t('Top pages in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
 }
 
 /**
- * Menu callback; presents the "Top hostnames" page.
+ * Menu callback; presents the "Top users" page.
  */
-function statistics_top_hostnames() {
-  $sql = "SELECT hostname, uid, MAX(timestamp) AS last_hit, COUNT(hostname) AS hits FROM {accesslog} GROUP BY hostname, uid";
-  $sql_cnt = "SELECT COUNT(DISTINCT(hostname)) FROM {accesslog}";
-  $describe = t('Top hostnames in the past %interval');
-
-  $page_title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
+function statistics_top_users() {
 
   $header = array(
-    array('data' => t('Hostname'), 'field' => 'hostname'),
-    array('data' => t('User'), 'field' => 'user'),
     array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
-    array('data' => t('Last hit'), 'field' => 'last_hit'),
-    array('data' => t('Operations'), 'colspan' => '2')
+    array('data' => t('User'), 'field' => 'u.name'),
   );
-  $sql .= tablesort_sql($header);
-  $result = pager_query($sql, 50, 0, $sql_cnt);
 
-  while ($hostname = db_fetch_object($result)) {
-    $user = user_load(array('uid' => $hostname->uid));
-    $rows[] = array($hostname->hostname, format_name($user), $hostname->hits, format_date($hostname->last_hit, 'small'), ($hostname->hostname ? l(t('track host'), "admin/logs/hits/host/$hostname->hostname") : ''), ($hostname->uid ? l(t('track user'), "admin/logs/hits/user/$hostname->uid") :''));
+  $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.uid". tablesort_sql($header);
+  $sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {accesslog}";
+  $result = pager_query($sql, 30, 0, $sql_cnt);
+
+  while ($account = db_fetch_object($result)) {
+    $rows[] = array($account->hits, format_name($account));
   }
-  if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '3'));
+
+  if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+    $rows[] = array(array('data' => $pager, 'colspan' => '2'));
   }
 
-  $output = theme('table', $header, $rows);
-  print theme('page', $output, $page_title);
+  print theme('page', theme('table', $header, $rows), t('Top users in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
 }
 
 /**
  * Menu callback; presents the "Top referrers" page.
- *
- * @param $view
- *   - "internal": Only display internal links.
- *   - "external": Only display links from off-site.
- *   - "all": Display all referrers.
  */
-function statistics_top_referrers($view = 'all') {
-  if ($view == 'all') {
-    $query = "SELECT url, MAX(timestamp) AS last_hit, COUNT(url) AS hits FROM {accesslog} WHERE url <> '' GROUP BY url";
-    $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> ''";
-    $describe = t('Top referrers in the past %interval');
-  }
-  elseif ($view == 'internal') {
-    $query = "SELECT url, MAX(timestamp) AS last_hit, COUNT(url) AS hits FROM {accesslog} WHERE url LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%' GROUP BY url";
-    $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%'";
-    $describe = t('Top internal referrers in the past %interval');
-  }
-  else {
-    /* default to external */
-    $query = "SELECT url, MAX(timestamp) AS last_hit, COUNT(url) AS hits FROM {accesslog} WHERE url NOT LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%' AND url <> '' GROUP BY url";
-    $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%'";
-    $describe = t('Top external referrers in the past %interval');
-  }
-
-  $title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
+function statistics_top_referrers() {
+  $query = "SELECT url, COUNT(url) AS hits FROM {accesslog} WHERE url NOT LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%' AND url <> '' GROUP BY url";
+  $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%'";
+  $title = t('Top referrers in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
 
   $header = array(
-    array('data' => t('Url'), 'field' => 'url'),
     array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
-    array('data' => t('Last hit'), 'field' => 'last_hit')
+    array('data' => t('Url'), 'field' => 'url')
   );
-  $query .= tablesort_sql($header);
 
-  $result = pager_query($query, 50, 0, $query_cnt);
+  $query .= tablesort_sql($header);
+  $result = pager_query($query, 30, 0, $query_cnt);
 
   while ($referrer = db_fetch_object($result)) {
-    $rows[] = array('<a href="'. $referrer->url .'">'. _statistics_column_width($referrer->url, '_refer', 75) .'</a>', $referrer->hits, format_date($referrer->last_hit, 'small'));
+    $rows[] = array($referrer->hits, '<a href="'. $referrer->url .'">'. _statistics_column_width($referrer->url, '_refer', 75) .'</a>');
   }
-  if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '3'));
+  if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+    $rows[] = array(array('data' => $pager, 'colspan' => '2'));
   }
 
-  $output .= theme('table', $header, $rows);
-
-  print theme('page', $output, $title);
-}
-
-/**
- * Menu callback; presents the "Most Popular Content" page.
- */
-function statistics_admin_content() {
-  $header = array(
-    array('data' => t('Post'), 'field' => 'n.title'),
-    array('data' => t('Today'), 'field' => 's.daycount', 'sort' => 'desc'),
-    array('data' => t('All time'), 'field' => 's.totalcount'),
-    array('data' => t('Last hit'), 'field' => 's.timestamp'),
-    array('data' => t('Operations'))
-  );
-  $sql = 'SELECT s.nid, s.daycount, s.totalcount, s.timestamp, n.title FROM {node_counter} s INNER JOIN {node} n ON s.nid = n.nid';
-  $sql .= tablesort_sql($header);
-  $result = pager_query($sql, 20); // WHERE s.%s <> '0'
-
-  while ($nid = db_fetch_object($result)) {
-    $rows[] = array(l($nid->title, 'node/'. $nid->nid, array('title' => t('View this posting.'))), $nid->daycount, $nid->totalcount, format_date($nid->timestamp, 'small'), l(t('track title'), 'admin/logs/hits/page/'. urlencode($nid->title)));
-  }
-  if ($pager = theme('pager', NULL, 20, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '5'));
-  }
-
-  $output = theme('table', $header, $rows);
-  print theme('page', $output, t('Top posts'));
+  print theme('page', theme('table', $header, $rows), $title);
 }
 
 /**
@@ -445,17 +336,9 @@ function statistics_settings() {
 
   // count content views settings
   $group = form_radios(t('Count content views'), 'statistics_count_content_views', variable_get('statistics_count_content_views', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Increment a counter each time content is viewed.'));
-  $group .= form_radios(t('Display counter values'), 'statistics_display_counter', variable_get('statistics_display_counter', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Display how many times given content has been viewed.  User must have the "access statistics" permissions to be able to view these counts.'));
+  $group .= form_radios(t('Display counter values'), 'statistics_display_counter', variable_get('statistics_display_counter', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Display how many times given content has been viewed.'));
   $output .= form_group(t('Content viewing counter settings'), $group);
 
-  // Popular content page settings
-  $numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25));
-  $group = form_textfield(t('Name for link to user page'), 'statistics_userpage_link', variable_get('statistics_userpage_link', ''), 20, 40, t("This node generates a user page listing your site's most popular content.  If you specify a name here, a link to the \"Popular content\" page will be added automatically."));
-  $group .= form_select(t("Number of day's top views to display"), 'statistics_userpage_day_cnt', variable_get('statistics_userpage_day_cnt', 0), $numbers, t('How many content items to display in the "day" list.  Requires enabled content viewing counters.'));
-  $group .= form_select(t('Number of all time top views to display'), 'statistics_userpage_all_cnt', variable_get('statistics_userpage_all_cnt', 0), $numbers, t('How many content items to display in the "all time" list.  Requires enabled content viewing counters.'));
-  $group .= form_select(t('Number of most recent views to display'), 'statistics_userpage_last_cnt', variable_get('statistics_userpage_last_cnt', 0), $numbers, t('How many posts to display in the "recently viewed" list.  Requires enabled content viewing counters.'));
-  $output .= form_group(t('"Popular content" page settings'), $group);
-
   return $output;
 }
 
@@ -578,42 +461,6 @@ function statistics_block($op = 'list', $delta = 0, $edit = array()) {
   }
 }
 
-/**
- * Menu callback; presents the "Top Nodes" summary page.
- */
-function statistics_page() {
-  $output = '';
-
-  // build day's most popular content list if enabled
-  if ($displaycount = variable_get('statistics_userpage_day_cnt', 0)) {
-    $table = '<table border="0" cellpadding="4" cellspacing="4" style="width: 100%;">';
-    $table .= statistics_summary('daycount', $displaycount);
-    $table .= '</table>';
-
-    $output .= theme('box', t("Day's most popular content:"), $table, 'main');
-  }
-
-  // build all time most popular content list if enabled
-  if ($displaycount = variable_get('statistics_userpage_all_cnt', 0)) {
-    $table = '<table border="0" cellpadding="4" cellspacing="4" style="width: 100%;">';
-    $table .= statistics_summary('totalcount', $displaycount);
-    $table .= '</table>';
-
-    $output .= theme('box', t('All time most popular content:'), $table, 'main');
-  }
-
-  // build last viewed content list if enabled
-  if ($displaycount = variable_get('statistics_userpage_last_cnt', 0)) {
-    $table = '<table border="0" cellpadding="4" cellspacing="4" style="width: 100%;">';
-    $table .= statistics_summary('timestamp', $displaycount);
-    $table .= '</table>';
-
-    $output .= theme('box', t('Last viewed content:'), $table, 'main');
-  }
-
-  print theme('page', $output);
-}
-
 function statistics_summary($dbfield, $dbrows) {
   /* valid dbfields: totalcount, daycount, timestamp */
 
@@ -656,8 +503,8 @@ function _statistics_column_width($column, $type = "", $default = 26) {
 function statistics_nodeapi(&$node, $op, $arg = 0) {
   switch ($op) {
     case 'delete':
-    // clean up statistics table when node is deleted
-    db_query('DELETE FROM {node_counter} WHERE nid = %d', $node->nid);
+      // clean up statistics table when node is deleted
+      db_query('DELETE FROM {node_counter} WHERE nid = %d', $node->nid);
   }
 }
 
diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module
index a9a59e2632ade282d468ac82f88c2886c6325ef4..11163a5aaee44e8b14e4c27b0f4a2262f195bcb9 100644
--- a/modules/statistics/statistics.module
+++ b/modules/statistics/statistics.module
@@ -27,50 +27,26 @@ function statistics_help($section) {
       <li>If you enable the access log, this adds 1 database query for each page that Drupal displays.  Logged information includes:  HTTP referrer (if any), node being accessed (if any), user ID (if any), the IP address of the user, and the time the page was viewed.</li>
       </ul>
       <p>As with any new module, the statistics module needs to be <a href=\"%modules\">enabled</a> before you can use it.  Also refer to the <a href=\"%permissions\">permissions section</a>, as this module supports four separate permissions.</p>
-      <h3><a href=\"%referers\">referrers log</a></h3>
-      <p>This admin page shows you site-wide referrer statistics.  You can see <em>'all'</em> statistics, <em>'external'</em> statistics or <em>'internal'</em> statistics.  Default is 'all'.</p>
-      <h3><a href=\"%access\">access log</a></h3>
-      <p>This admin page gives you an at-a-glance look at your most popular content.  It is useful for understanding what content on your Drupal site is the most popular.  Also on this page are links to the referrer statistics for each listed node.</p>
       <h3>Configuring the statistics module</h3>
       <p>There are some configuration options added to the main <a href=\"%configuration\">administer &raquo; settings &raquo; statistics</a> section:</p>
       <ul>
       <li><em>enable access log</em> -- allows you to turn the access log on and off.  This log is used to store data about every page accessed, such as the remote host's IP address, where they came from (referrer), what node they've viewed, and their user name.  Enabling the log adds one database call per page displayed by Drupal.</li>
       <li><em>discard access logs older than</em> -- allows you to configure how long an access log entry is saved, after which time it is deleted from the database table. To use this you need to run \"cron.php\"</li>
       <li><em>enable node view counter</em> -- allows you to turn on and off the node-counting functionality of this module.  If it is turned on, an extra database query is added for each node displayed, which increments a counter.</li>
-      <li><em>display node view counters</em> -- allows you to globally disable the displaying of node view counters.  Additionally, a user group must have 'access statistics' permissions to view the counters.</li>
+      <li><em>display node view counters</em> -- allows you to globally disable the displaying of node view counters.</li>
       </ul>
       <h3>Popular content block</h3>
       <p>This module creates a block that can display the day's top viewed content, the all time top viewed content, and the last content viewed.  Each of these links can be enabled or disabled individually, and the number of posts displayed for each can be configured with a drop down menu.  If you disable all sections of this block, it will not appear.</p>
-      <p>Don't forget to <a href=\"%block\">enable the block</a>.</p>
-      <h3>Popular content page</h3>
-      <p>This module creates a user page that can display summaries of the day's most popular viewed content, the all time most popular content, and the last content viewed.  Each of these summaries can be enabled or disabled individually, and the number of posts displayed for each can be configured with a drop down menu.  You can also assign a name for the automatically generated link to the user page.  If no name is set, the link will not be displayed.</p>
-      <h3>Permissions</h3><p>This module has four permissions that need to be configured in the <a href=\"%permissions\">permissions section</a>.</p>
-      <ul>
-      <li><em>access statistics</em> - enable for user roles that get to see view counts for individual content.  (This does not define access to the block)</li>
-      <li><em>administer statistics module</em> - enable for user roles that get to configure the statistics module.</li><li><em>administer statistics</em> - enable for user roles that get to view the referrer statistics.</li>
-      </ul>
-      <p>If '<em>administer statistics</em>' and '<em>access statistics</em>' are both enabled, the user will see a link from each node to that node's referrer statistics (if enabled).</p>",
-      array('%modules' => url('admin/modules'), '%permissions' => url('admin/user/configure/permission'), '%referer' => url('admin/logs/hits/referrers'), '%access' => url('admin/logs/access'), '%configuration' => url('admin/settings/statistics'), '%block' => url('admin/block')));
+      <p>Don't forget to <a href=\"%block\">enable the block</a>.</p>",
+      array('%modules' => url('admin/modules'), '%permissions' => url('admin/user/configure/permission'), '%referer' => url('admin/logs/referrers'), '%configuration' => url('admin/settings/statistics'), '%block' => url('admin/block')));
     case 'admin/modules#description':
       return t('Logs access statistics for your site.');
     case 'admin/settings/statistics':
       return t('Settings for the statistical information that Drupal will keep about the site. See <a href="%statistics">site statistics</a> for the actual information.', array('%statistics' => url('admin/logs/hits')));
-    case 'admin/logs/hits/posts':
-      return t('This page gives you an at-a-glance look at your most popular content.');
-    case 'admin/logs/hits/pages':
-      return t('This page shows access statistics for each page of your website.');
-    case 'admin/logs/hits/users':
-      return t('This page shows access statistics for each user of your website.');
-    case 'admin/logs/hits/hostnames':
-      return t('This page shows access statistics for each hostname visiting your website.');
+    case 'admin/logs/hits':
+      return t('This page shows you the most recent hits.');
     case 'admin/logs/referrers':
-      return t('This page shows your site-wide referrer statistics.  You can optionally view just the "external referrers" or the "internal referrers". Referrers are web pages, both local and on other sites, that point to your web site.');
-    case 'admin/logs/referrers/internal':
-      return t('This page shows you only "internal referrers". These are links pointing to your web site from within your web site.');
-    case 'admin/logs/referrers/external':
-      return t('This page shows you only "external referrers". These are links pointing to your web site from outside your web site.');
-    case strstr($section, 'admin/logs/hits'):
-      return t("This page shows you who is accessing your web site.  You can see the hostnames and referrers.  For example, it is easy to inspect a user's navigation history/trail by clicking on <em>track user</em>.");
+      return t('This page shows you all external referrers. These are links pointing to your web site from outside your web site.');
   }
 }
 
@@ -107,15 +83,9 @@ function statistics_exit() {
 
 /**
  * Implementation of hook_perm().
- *
- * The following permissions are defined:
- * - "administer statistics module": full administrative control of module
- * - "administer statistics": view statistics / referrer log
- * - "access statistics": see how many times individual nodes have been
- *   viewed (if enabled)
  */
 function statistics_perm() {
-  return array('administer statistics module', 'administer statistics', 'access statistics');
+  return array('access statistics');
 }
 
 /**
@@ -126,15 +96,10 @@ function statistics_link($type, $node = 0, $main = 0) {
 
   $links = array();
 
-  if ($type != 'comment' && user_access('access statistics') && variable_get('statistics_display_counter', 0)) {
+  if ($type != 'comment' && variable_get('statistics_display_counter', 0)) {
     $statistics = statistics_get($node->nid);
     if ($statistics) {
-      if (user_access('administer statistics')) {
-        $links[] = l(format_plural($statistics['totalcount'], '1 read', '%count reads'), 'admin/logs/hits/page/'. urlencode($node->title));
-      }
-      else {
-        $links[] = format_plural($statistics['totalcount'], '1 read', '%count reads');
-      }
+      $links[] = format_plural($statistics['totalcount'], '1 read', '%count reads');
     }
   }
   return $links;
@@ -146,290 +111,216 @@ function statistics_link($type, $node = 0, $main = 0) {
 function statistics_menu($may_cache) {
   $items = array();
 
+  $access = user_access('access statistics');
   if ($may_cache) {
-    $items[] = array('path' => 'statistics', 'title' => t('most popular content'),
-      'callback' => 'statistics_page',
-      'access' => user_access('access content'),
-      'type' => MENU_SUGGESTED_ITEM);
-
-    $access = user_access('administer statistics module') || user_access('administer statistics');
-    $items[] = array('path' => 'admin/logs/hits', 'title' => t('hits'),
-      'callback' => 'statistics_admin_displaylog', 'access' => $access,
+    $items[] = array('path' => 'admin/logs/hits', 'title' => t('recent hits'),
+      'callback' => 'statistics_recent_hits', 'access' => $access,
       'weight' => 3);
-    $items[] = array('path' => 'admin/logs/hits/posts', 'title' => t('posts'),
-      'callback' => 'statistics_admin_content', 'access' => $access,
-      'weight' => 1);
-    $items[] = array('path' => 'admin/logs/hits/pages', 'title' => t('pages'),
-      'callback' => 'statistics_top_titles', 'access' => $access,
+    $items[] = array('path' => 'admin/logs/pages', 'title' => t('top pages'),
+      'callback' => 'statistics_top_pages', 'access' => $access,
       'weight' => 1);
-    $items[] = array('path' => 'admin/logs/hits/users', 'title' => t('users'),
+    $items[] = array('path' => 'admin/logs/users', 'title' => t('top users'),
       'callback' => 'statistics_top_users', 'access' => $access,
       'weight' => 2);
-    $items[] = array('path' => 'admin/logs/hits/hostnames',
-      'title' => t('hostnames'), 'callback' => 'statistics_top_hostnames',
-      'access' => $access, 'weight' => 3);
-    $items[] = array('path' => 'admin/logs/referrers',
-      'title' => t('referrers'), 'callback' => 'statistics_top_referrers',
-      'access' => $access, 'weight' => 4);
-    $items[] = array('path' => 'admin/logs/referrers/internal',
-      'title' => t('internal'), 'access' => $access);
-    $items[] = array('path' => 'admin/logs/referrers/external',
-      'title' => t('external'), 'access' => $access);
+    $items[] = array('path' => 'admin/logs/referrers', 'title' => t('referrers'),
+      'callback' => 'statistics_top_referrers', 'access' => $access);
+    $items[] = array('path' => 'admin/logs/access', 'title' => t('details'),
+      'callback' => 'statistics_access_log', 'access' => $access,
+      'type' => MENU_CALLBACK);
+  }
+  else {
+    if (arg(0) == 'user' && is_numeric(arg(1))) {
+      $items[] = array('path' => 'user/'. arg(1) .'/track/navigation', 'title' => t('track page visits'),
+        'callback' => 'statistics_user_tracker', 'access' => $access,
+        'type' => MENU_LOCAL_TASK, 'weight' => 2);
+    }
+    if (arg(0) == 'node' && is_numeric(arg(1))) {
+      $items[] = array('path' => 'node/'. arg(1) .'/track', 'title' => t('track'),
+        'callback' => 'statistics_node_tracker', 'access' => $access,
+        'type' => MENU_LOCAL_TASK, 'weight' => 2);
+    }
   }
 
   return $items;
 }
 
-/**
- * Menu callback; presents the "Access logs" page.
- *
- * @param $type
- *   - "user":  display accesses for a particular user.
- *   - "title": display accesses of a particular title.
- *   - "host":  display accesses originated at a given IP.
- *   - "all":   display all accesses.
- *
- * @param $value
- *   The user, host, or node to filter by.
- */
-function statistics_admin_displaylog($type = 'all', $id = 0) {
-  switch ($type) {
-    case 'user':
-      if ($id) {
-        // retrieve recent access logs for specific user $id
-        $user = user_load(array('uid' => $id));
-        $page_title = t('Recent hits for "%username"', array('%username' => $user->name));
-        $sql = 'SELECT title, path, url, hostname, uid, timestamp FROM {accesslog} WHERE uid = \''. db_escape_string($id) ."'";
-      }
-      else {
-        // retrieve recent access logs for all users (not guests)
-        $page_title = t('Recent hits for all users');
-        $sql = 'SELECT title, path, url, hostname, uid, MAX(timestamp) AS timestamp FROM {accesslog} WHERE uid <> 0 GROUP BY uid, title, path, url, hostname';
-      }
-      break;
-    case 'page':
-      // retrieve recent access logs for title $id
-      $page_title = t('Recent hits for "%title"', array('%title' => $id));
-      $sql = 'SELECT title, path, url, hostname, uid, timestamp FROM {accesslog} WHERE title = \''. db_escape_string($id) ."'";
-      break;
-    case 'host':
-      // retrieve recent access logs for hostname $id
-      $page_title = t('Recent hits for "%hostname"', array('%hostname' => $id));
-      $sql = 'SELECT title, path, url, hostname, uid, timestamp, title FROM {accesslog} WHERE hostname = \''. db_escape_string($id) ."'";
-      break;
-    case 'all':
-    default:
-      // retrieve all recent access logs
-      $page_title = t('Recent hits');
-      $sql = 'SELECT title, path, url, hostname, uid, timestamp FROM {accesslog}';
+function statistics_access_log($aid) {
+  $result = db_query('SELECT a.*, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE aid = %d', $aid);
+  if ($access = db_fetch_object($result)) {
+    $output  = '<table border="1" cellpadding="2" cellspacing="2">';
+    $output .= ' <tr><th>'. t('Page URL') ."</th><td>". l(url($access->path, NULL, NULL, TRUE), $access->url) ."</td></tr>";
+    $output .= ' <tr><th>'. t('Page title') ."</th><td>$access->title</td></tr>";
+    $output .= ' <tr><th>'. t('Referrer') ."</th><td>". ($access->url ? l($access->url, $access->url) : '') ."</td></tr>";
+    $output .= ' <tr><th>'. t('Date') .'</th><td>'. format_date($access->timestamp, 'large') .'</td></tr>';
+    $output .= ' <tr><th>'. t('User') .'</th><td>'. format_name($access) .'</td></tr>';
+    $output .= ' <tr><th>'. t('Hostname') ."</th><td>$watchdog->hostname</td></tr>";
+    $output .= '</table>';
+    print theme('page', $output);
+  }
+  else {
+    drupal_not_found();
   }
+}
 
-  $header = array(
-    array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
-    array('data' => t('Page'), 'field' => 'title'),
-    array('data' => t('User'), 'field' => 'uid'),
-    array('data' => t('Hostname'), 'field' => 'hostname'),
-    array('data' => t('Referrer'), 'field' => 'url'),
-    array('data' => t('Operations'), 'colspan' => '3')
-  );
+function statistics_node_tracker() {
+  if ($node = node_load(array('nid' => arg(1)))) {
+
+    $header = array(
+        array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'),
+        array('data' => t('Referrer'), 'field' => 'a.url'),
+        array('data' => t('User'), 'field' => 'u.name'),
+        array('data' => t('Operations')));
+
+    $result = pager_query('SELECT a.aid, a.timestamp, a.url, a.uid, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE a.path LIKE \'node/'. db_escape_string($node->nid) ."%'" . tablesort_sql($header), 30);
+    while ($log = db_fetch_object($result)) {
+      $rows[] = array(
+        array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'),
+        l($log->url, $log->url),
+        format_name($log),
+        l(t('details'), "admin/logs/access/$log->aid"));
+    }
 
-  $sql .= tablesort_sql($header);
+    if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+      $rows[] = array(array('data' => $pager, 'colspan' => '4'));
+    }
 
-  $result = pager_query($sql, 50);
-  while ($log = db_fetch_object($result)) {
+    print theme('page', theme('table', $header, $rows), $node->title);
+  }
+  else {
+    drupal_not_found();
+  }
+}
 
-    // display title if possible, otherwise display path
-    if ($log->title)
-      $title = l(_statistics_column_width($log->title), $log->path, array('title' => $log->path));
-    else
-      $title = '('. l(_statistics_column_width($log->path), $log->path, array('title' => $log->path)) .')';
+function statistics_user_tracker() {
+  if ($account = user_load(array('uid' => arg(1)))) {
 
-    // display url if possible, constructing our own link as may not be local
-    if ($log->url)
-      $url = "<a href=\"$log->url\" title=\"$log->url\">". _statistics_column_width($log->url) .'</a>';
-    else
-      $url = message_na();
+    $header = array(
+        array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
+        array('data' => t('Page'), 'field' => 'path'),
+        array('data' => t('Operations')));
 
-    $user = user_load(array('uid' => $log->uid));
-    $rows[] = array(array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'), $title, format_name($user), $log->hostname ? $log->hostname : message_na(), $url, ($user->uid ? l(t('track user'), "admin/logs/hits/user/$user->uid") : ''), ($log->title ? l(t('track title'), 'admin/logs/hits/page/'. urlencode($log->title)) : ''), ($log->hostname ? l(t('track host'), "admin/logs/hits/host/$log->hostname") : ''));
-  }
+    $result = pager_query('SELECT aid, timestamp, path, title FROM {accesslog} WHERE uid = \''. db_escape_string($account->uid) ."'" . tablesort_sql($header), 30);
+    while ($log = db_fetch_object($result)) {
+      $rows[] = array(
+        array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'),
+        $log->title ."<br />". l($log->path, $log->path),
+        l(t('details'), "admin/logs/access/$log->aid"));
+    }
 
-  if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '8'));
-  }
+    if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+      $rows[] = array(array('data' => $pager, 'colspan' => '3'));
+    }
 
-  $output = theme('table', $header, $rows);
-  print theme('page', $output, $page_title);
+    print theme('page', theme('table', $header, $rows), $account->name);
+  }
+  else {
+    drupal_not_found();
+  }
 }
 
 /**
- * Menu callback; presents the "Top pages" page.
+ * Menu callback; presents the "Recent hits" page.
  */
-function statistics_top_titles() {
-  $sql = "SELECT title, path, MAX(timestamp) AS last_hit, COUNT(title) AS hits FROM {accesslog} WHERE title <> '' GROUP BY title, path";
-  $sql_cnt = "SELECT COUNT(DISTINCT(title)) FROM {accesslog} WHERE title <> ''";
-  $describe = t('Top pages in the past %interval');
-
-  $page_title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
+function statistics_recent_hits($type = 'all', $id = 0) {
 
   $header = array(
-    array('data' => t('Page'), 'field' => 'title'),
-    array('data' => t('Path'), 'field' => 'path'),
-    array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
-    array('data' => t('Last hit'), 'field' => 'last_hit'),
+    array('data' => t('Timestamp'), 'field' => 'a.timestamp', 'sort' => 'desc'),
+    array('data' => t('Page'), 'field' => 'a.path'),
+    array('data' => t('User'), 'field' => 'u.name'),
     array('data' => t('Operations'))
   );
-  $sql .= tablesort_sql($header);
-  $result = pager_query($sql, 50, 0, $sql_cnt);
 
-  while ($title = db_fetch_object($result)) {
-    $rows[] = array(l(_statistics_column_width($title->title, '_title', 56), $title->path), _statistics_column_width($title->path, '_title', 56), $title->hits, format_date($title->last_hit, 'small'), ($title->title ? l(t('track title'), 'admin/logs/hits/page/'. urlencode($title->title)) : ''));
+  $sql = 'SELECT a.aid, a.path, a.title, a.uid, u.name, a.timestamp FROM {accesslog} a LEFT JOIN {users} u ON u.uid = a.uid' . tablesort_sql($header);
+
+  $result = pager_query($sql, 30);
+  while ($log = db_fetch_object($result)) {
+    $rows[] = array(
+      array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'),
+      $log->title .'<br />'. l($log->path, $log->path),
+      format_name($log),
+      l(t('details'), "admin/logs/access/$log->aid"));
   }
-  if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '5'));
+
+  if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+    $rows[] = array(array('data' => $pager, 'colspan' => '4'));
   }
 
-  $output = theme('table', $header, $rows);
-  print theme('page', $output, $page_title);
+  print theme('page', theme('table', $header, $rows), t('Recent hits'));
 }
 
 /**
- * Menu callback; presents the "Top users" page.
+ * Menu callback; presents the "Top pages" page.
  */
-function statistics_top_users() {
-  $sql = "SELECT uid, hostname, MAX(timestamp) AS last_hit, COUNT(uid) AS hits FROM {accesslog} GROUP BY uid, hostname";
-  $sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {accesslog}";
-  $describe = t('Top users in the past %interval');
-
-  $page_title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
+function statistics_top_pages() {
+  $sql = "SELECT COUNT(path) AS hits, path, title FROM {accesslog} GROUP BY path";
+  $sql_cnt = "SELECT COUNT(DISTINCT(path)) FROM {accesslog}";
 
   $header = array(
-    array('data' => t('User'), 'field' => 'user'),
-    array('data' => t('Hostname'), 'field' => 'hostname'),
     array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
-    array('data' => t('Last hit'), 'field' => 'last_hit'),
-    array('data' => t('Operations'), 'colspan' => '2')
+    array('data' => t('Page'), 'field' => 'path')
   );
   $sql .= tablesort_sql($header);
-  $result = pager_query($sql, 50, 0, $sql_cnt);
+  $result = pager_query($sql, 30, 0, $sql_cnt);
 
-  while ($u = db_fetch_object($result)) {
-    $user = user_load(array('uid' => $u->uid));
-    $rows[] = array(format_name($user), $u->hostname, $u->hits, format_date($u->last_hit, 'small'), ($u->uid ? l(t('track user'), "admin/logs/hits/user/$user->uid") : ''), ($u->hostname ? l(t('track host'), "admin/logs/hits/host/$u->hostname") : ''));
+  while ($page = db_fetch_object($result)) {
+    $rows[] = array($page->hits, $page->title .'<br />'. l($page->path, $page->path));
   }
-  if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '6'));
+  if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+    $rows[] = array(array('data' => $pager, 'colspan' => '2'));
   }
 
-  $output = theme('table', $header, $rows);
-  print theme('page', $output, $page_title);
+  print theme('page', theme('table', $header, $rows), t('Top pages in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
 }
 
 /**
- * Menu callback; presents the "Top hostnames" page.
+ * Menu callback; presents the "Top users" page.
  */
-function statistics_top_hostnames() {
-  $sql = "SELECT hostname, uid, MAX(timestamp) AS last_hit, COUNT(hostname) AS hits FROM {accesslog} GROUP BY hostname, uid";
-  $sql_cnt = "SELECT COUNT(DISTINCT(hostname)) FROM {accesslog}";
-  $describe = t('Top hostnames in the past %interval');
-
-  $page_title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
+function statistics_top_users() {
 
   $header = array(
-    array('data' => t('Hostname'), 'field' => 'hostname'),
-    array('data' => t('User'), 'field' => 'user'),
     array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
-    array('data' => t('Last hit'), 'field' => 'last_hit'),
-    array('data' => t('Operations'), 'colspan' => '2')
+    array('data' => t('User'), 'field' => 'u.name'),
   );
-  $sql .= tablesort_sql($header);
-  $result = pager_query($sql, 50, 0, $sql_cnt);
 
-  while ($hostname = db_fetch_object($result)) {
-    $user = user_load(array('uid' => $hostname->uid));
-    $rows[] = array($hostname->hostname, format_name($user), $hostname->hits, format_date($hostname->last_hit, 'small'), ($hostname->hostname ? l(t('track host'), "admin/logs/hits/host/$hostname->hostname") : ''), ($hostname->uid ? l(t('track user'), "admin/logs/hits/user/$hostname->uid") :''));
+  $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.uid". tablesort_sql($header);
+  $sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {accesslog}";
+  $result = pager_query($sql, 30, 0, $sql_cnt);
+
+  while ($account = db_fetch_object($result)) {
+    $rows[] = array($account->hits, format_name($account));
   }
-  if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '3'));
+
+  if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+    $rows[] = array(array('data' => $pager, 'colspan' => '2'));
   }
 
-  $output = theme('table', $header, $rows);
-  print theme('page', $output, $page_title);
+  print theme('page', theme('table', $header, $rows), t('Top users in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
 }
 
 /**
  * Menu callback; presents the "Top referrers" page.
- *
- * @param $view
- *   - "internal": Only display internal links.
- *   - "external": Only display links from off-site.
- *   - "all": Display all referrers.
  */
-function statistics_top_referrers($view = 'all') {
-  if ($view == 'all') {
-    $query = "SELECT url, MAX(timestamp) AS last_hit, COUNT(url) AS hits FROM {accesslog} WHERE url <> '' GROUP BY url";
-    $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> ''";
-    $describe = t('Top referrers in the past %interval');
-  }
-  elseif ($view == 'internal') {
-    $query = "SELECT url, MAX(timestamp) AS last_hit, COUNT(url) AS hits FROM {accesslog} WHERE url LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%' GROUP BY url";
-    $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%'";
-    $describe = t('Top internal referrers in the past %interval');
-  }
-  else {
-    /* default to external */
-    $query = "SELECT url, MAX(timestamp) AS last_hit, COUNT(url) AS hits FROM {accesslog} WHERE url NOT LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%' AND url <> '' GROUP BY url";
-    $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%'";
-    $describe = t('Top external referrers in the past %interval');
-  }
-
-  $title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
+function statistics_top_referrers() {
+  $query = "SELECT url, COUNT(url) AS hits FROM {accesslog} WHERE url NOT LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%' AND url <> '' GROUP BY url";
+  $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%". db_escape_string($_SERVER['HTTP_HOST']) ."%'";
+  $title = t('Top referrers in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
 
   $header = array(
-    array('data' => t('Url'), 'field' => 'url'),
     array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
-    array('data' => t('Last hit'), 'field' => 'last_hit')
+    array('data' => t('Url'), 'field' => 'url')
   );
-  $query .= tablesort_sql($header);
 
-  $result = pager_query($query, 50, 0, $query_cnt);
+  $query .= tablesort_sql($header);
+  $result = pager_query($query, 30, 0, $query_cnt);
 
   while ($referrer = db_fetch_object($result)) {
-    $rows[] = array('<a href="'. $referrer->url .'">'. _statistics_column_width($referrer->url, '_refer', 75) .'</a>', $referrer->hits, format_date($referrer->last_hit, 'small'));
+    $rows[] = array($referrer->hits, '<a href="'. $referrer->url .'">'. _statistics_column_width($referrer->url, '_refer', 75) .'</a>');
   }
-  if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '3'));
+  if ($pager = theme('pager', NULL, 30, 0, tablesort_pager())) {
+    $rows[] = array(array('data' => $pager, 'colspan' => '2'));
   }
 
-  $output .= theme('table', $header, $rows);
-
-  print theme('page', $output, $title);
-}
-
-/**
- * Menu callback; presents the "Most Popular Content" page.
- */
-function statistics_admin_content() {
-  $header = array(
-    array('data' => t('Post'), 'field' => 'n.title'),
-    array('data' => t('Today'), 'field' => 's.daycount', 'sort' => 'desc'),
-    array('data' => t('All time'), 'field' => 's.totalcount'),
-    array('data' => t('Last hit'), 'field' => 's.timestamp'),
-    array('data' => t('Operations'))
-  );
-  $sql = 'SELECT s.nid, s.daycount, s.totalcount, s.timestamp, n.title FROM {node_counter} s INNER JOIN {node} n ON s.nid = n.nid';
-  $sql .= tablesort_sql($header);
-  $result = pager_query($sql, 20); // WHERE s.%s <> '0'
-
-  while ($nid = db_fetch_object($result)) {
-    $rows[] = array(l($nid->title, 'node/'. $nid->nid, array('title' => t('View this posting.'))), $nid->daycount, $nid->totalcount, format_date($nid->timestamp, 'small'), l(t('track title'), 'admin/logs/hits/page/'. urlencode($nid->title)));
-  }
-  if ($pager = theme('pager', NULL, 20, 0, tablesort_pager())) {
-    $rows[] = array(array('data' => $pager, 'colspan' => '5'));
-  }
-
-  $output = theme('table', $header, $rows);
-  print theme('page', $output, t('Top posts'));
+  print theme('page', theme('table', $header, $rows), $title);
 }
 
 /**
@@ -445,17 +336,9 @@ function statistics_settings() {
 
   // count content views settings
   $group = form_radios(t('Count content views'), 'statistics_count_content_views', variable_get('statistics_count_content_views', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Increment a counter each time content is viewed.'));
-  $group .= form_radios(t('Display counter values'), 'statistics_display_counter', variable_get('statistics_display_counter', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Display how many times given content has been viewed.  User must have the "access statistics" permissions to be able to view these counts.'));
+  $group .= form_radios(t('Display counter values'), 'statistics_display_counter', variable_get('statistics_display_counter', 0), array('1' => t('Enabled'), '0' => t('Disabled')), t('Display how many times given content has been viewed.'));
   $output .= form_group(t('Content viewing counter settings'), $group);
 
-  // Popular content page settings
-  $numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25));
-  $group = form_textfield(t('Name for link to user page'), 'statistics_userpage_link', variable_get('statistics_userpage_link', ''), 20, 40, t("This node generates a user page listing your site's most popular content.  If you specify a name here, a link to the \"Popular content\" page will be added automatically."));
-  $group .= form_select(t("Number of day's top views to display"), 'statistics_userpage_day_cnt', variable_get('statistics_userpage_day_cnt', 0), $numbers, t('How many content items to display in the "day" list.  Requires enabled content viewing counters.'));
-  $group .= form_select(t('Number of all time top views to display'), 'statistics_userpage_all_cnt', variable_get('statistics_userpage_all_cnt', 0), $numbers, t('How many content items to display in the "all time" list.  Requires enabled content viewing counters.'));
-  $group .= form_select(t('Number of most recent views to display'), 'statistics_userpage_last_cnt', variable_get('statistics_userpage_last_cnt', 0), $numbers, t('How many posts to display in the "recently viewed" list.  Requires enabled content viewing counters.'));
-  $output .= form_group(t('"Popular content" page settings'), $group);
-
   return $output;
 }
 
@@ -578,42 +461,6 @@ function statistics_block($op = 'list', $delta = 0, $edit = array()) {
   }
 }
 
-/**
- * Menu callback; presents the "Top Nodes" summary page.
- */
-function statistics_page() {
-  $output = '';
-
-  // build day's most popular content list if enabled
-  if ($displaycount = variable_get('statistics_userpage_day_cnt', 0)) {
-    $table = '<table border="0" cellpadding="4" cellspacing="4" style="width: 100%;">';
-    $table .= statistics_summary('daycount', $displaycount);
-    $table .= '</table>';
-
-    $output .= theme('box', t("Day's most popular content:"), $table, 'main');
-  }
-
-  // build all time most popular content list if enabled
-  if ($displaycount = variable_get('statistics_userpage_all_cnt', 0)) {
-    $table = '<table border="0" cellpadding="4" cellspacing="4" style="width: 100%;">';
-    $table .= statistics_summary('totalcount', $displaycount);
-    $table .= '</table>';
-
-    $output .= theme('box', t('All time most popular content:'), $table, 'main');
-  }
-
-  // build last viewed content list if enabled
-  if ($displaycount = variable_get('statistics_userpage_last_cnt', 0)) {
-    $table = '<table border="0" cellpadding="4" cellspacing="4" style="width: 100%;">';
-    $table .= statistics_summary('timestamp', $displaycount);
-    $table .= '</table>';
-
-    $output .= theme('box', t('Last viewed content:'), $table, 'main');
-  }
-
-  print theme('page', $output);
-}
-
 function statistics_summary($dbfield, $dbrows) {
   /* valid dbfields: totalcount, daycount, timestamp */
 
@@ -656,8 +503,8 @@ function _statistics_column_width($column, $type = "", $default = 26) {
 function statistics_nodeapi(&$node, $op, $arg = 0) {
   switch ($op) {
     case 'delete':
-    // clean up statistics table when node is deleted
-    db_query('DELETE FROM {node_counter} WHERE nid = %d', $node->nid);
+      // clean up statistics table when node is deleted
+      db_query('DELETE FROM {node_counter} WHERE nid = %d', $node->nid);
   }
 }
 
diff --git a/modules/watchdog.module b/modules/watchdog.module
index 15f2afef74805cc634475493c35308ac3b8f0387..42b401e906ff13d5f0a62682950991d63ca7f6e6 100644
--- a/modules/watchdog.module
+++ b/modules/watchdog.module
@@ -21,20 +21,6 @@ function watchdog_help($section = 'admin/help#watchdog') {
       return t('<p>The watchdog module monitors your web site, capturing system events in a log to be reviewed by an authorized individual at a later time.  The watchdog log is simply a list of recorded events containing usage data, performance data, errors, warnings and operational information.  It is vital to <a href="%watchdog">check the watchdog report</a> on a regular basis as it is often the only way to tell what is going on.</p>', array('%watchdog' => url('admin/logs')));
     case 'admin/logs':
       return t('<p>The watchdog module monitors your web site, capturing system events in a log to be reviewed by an authorized individual at a later time.  The watchdog log is simply a list of recorded events containing usage data, performance data, errors, warnings and operational information.  It is vital to check the watchdog report on a regular basis as it is often the only way to tell what is going on.</p>');
-    case 'admin/logs/error':
-      return t('<p>Watchdog events about PHP and database errors.</p>');
-    case 'admin/logs/httpd':
-      return t('<p>Watchdog events that are from the web server, like 404s, etc.</p>');
-    case 'admin/logs/regular':
-      return t('<p>Watchdog events that are "normal" and have no other classification.</p>');
-    case 'admin/logs/search':
-      return t('<p>Watchdog events showing what users have searched for.</p>');
-    case 'admin/logs/special':
-      return t('<p>Watchdog events about adding, changing, and moderating nodes and comments.</p>');
-    case 'admin/logs/user':
-      return t('<p>Watchdog events that have to do with users and their accounts.</p>');
-    case 'admin/logs/warning':
-      return t('<p>Watchdog events that don\'t stop normal operation, but are things you should know.</p>');
     case 'admin/modules#description':
       return t('Logs and records system events.');
   }
@@ -49,14 +35,9 @@ function watchdog_menu($may_cache) {
   if ($may_cache) {
     $items[] = array('path' => 'admin/logs', 'title' => t('logs'),
       'callback' => 'watchdog_overview', 'access' => user_access('administer watchdog'));
-
-    $items[] = array('path' => 'admin/logs/view', 'title' => t('view details'),
-      'callback' => 'watchdog_view', 'access' => user_access('administer watchdog'),
+    $items[] = array('path' => 'admin/logs/event', 'title' => t('details'),
+      'callback' => 'watchdog_event', 'access' => user_access('administer watchdog'),
       'type' => MENU_CALLBACK);
-
-    foreach (_watchdog_get_message_types() as $type) {
-      $items[] = array('path' => 'admin/logs/'. $type, 'title' => t($type), 'type' => MENU_DYNAMIC_ITEM);
-    }
   }
   return $items;
 }
@@ -81,29 +62,46 @@ function watchdog_cron() {
 /**
  * Menu callback; displays a listing of log messages.
  */
-function watchdog_overview($type = '') {
-  foreach (_watchdog_get_message_types() as $key) {
-    $query[$key] = "WHERE type = '". db_escape_string($key) ."'";
+function watchdog_overview() {
+  $names['all'] = t('all messages');
+  $queries['all'] = '';
+  foreach (_watchdog_get_message_types() as $type) {
+    $names[$type] = t('%type messages', array('%type' => $type));
+    $queries[$type] = "WHERE type = '". db_escape_string($type) ."'";
+  }
+
+  if (empty($_SESSION['watchdog_overview_filter'])) {
+    $_SESSION['watchdog_overview_filter'] = 'all';
+  }
+
+  $op = $_POST['op'];
+  if ($op == t('Filter') && isset($_POST['edit']['filter'])) {
+    $_SESSION['watchdog_overview_filter'] = $_POST['edit']['filter'];
   }
 
+  $form  = form_select(t('Filter by type'), 'filter', $_SESSION['watchdog_overview_filter'], $names);
+  $form .= form_submit(t('Filter'));
+
   $header = array(
+    array('data' => t('Type'), 'field' => 'w.type'),
     array('data' => t('Date'), 'field' => 'w.timestamp', 'sort' => 'desc'),
     array('data' => t('Message'), 'field' => 'w.message'),
     array('data' => t('User'), 'field' => 'u.name'),
     array('data' => t('Operations'), 'colspan' => '2')
   );
-  $sql = 'SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid '. ($type ? $query[$type] : '') . tablesort_sql($header);
+  $sql = 'SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid '. $queries[$_SESSION['watchdog_overview_filter']] . tablesort_sql($header);
   $result = pager_query($sql, 50);
 
   while ($watchdog = db_fetch_object($result)) {
     $rows[] = array('data' =>
       array(
         // Cells
+        $watchdog->type,
         format_date($watchdog->timestamp, 'small'),
         truncate_utf8(strip_tags($watchdog->message), 64),
         format_name($watchdog),
         $watchdog->link,
-        l(t('details'), "admin/logs/view/$watchdog->wid")
+        l(t('details'), "admin/logs/event/$watchdog->wid")
       ),
       // Attributes for tr
       'class' => "watchdog-$watchdog->type"
@@ -118,13 +116,17 @@ function watchdog_overview($type = '') {
   if (!empty($pager)) {
     $rows[] = array(array('data' => $pager, 'colspan' => '5'));
   }
-  print theme('page', theme('table', $header, $rows));
+
+  $output  = '<div class="container-inline">'. form($form) .'</div>';
+  $output .= theme('table', $header, $rows);
+
+  print theme('page', $output);
 }
 
 /**
  * Menu callback; displays details about a log message.
  */
-function watchdog_view($id) {
+function watchdog_event($id) {
   $output = '';
   $result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d', $id);
   if ($watchdog = db_fetch_object($result)) {
@@ -132,7 +134,7 @@ function watchdog_view($id) {
     $output .= ' <tr><th>'. t('Type') ."</th><td>$watchdog->type</td></tr>";
     $output .= ' <tr><th>'. t('Date') .'</th><td>'. format_date($watchdog->timestamp, 'large') .'</td></tr>';
     $output .= ' <tr><th>'. t('User') .'</th><td>'. format_name($watchdog) .'</td></tr>';
-    $output .= ' <tr><th>'. t('Location') ."</th><td>$watchdog->location</td></tr>";
+    $output .= ' <tr><th>'. t('Location') ."</th><td>". l($watchdog->location, $watchdog->location) ."</td></tr>";
     $output .= ' <tr><th>'. t('Message') ."</th><td>$watchdog->message</td></tr>";
     $output .= ' <tr><th>'. t('Hostname') ."</th><td>$watchdog->hostname</td></tr>";
     $output .= '</table>';
diff --git a/modules/watchdog/watchdog.module b/modules/watchdog/watchdog.module
index 15f2afef74805cc634475493c35308ac3b8f0387..42b401e906ff13d5f0a62682950991d63ca7f6e6 100644
--- a/modules/watchdog/watchdog.module
+++ b/modules/watchdog/watchdog.module
@@ -21,20 +21,6 @@ function watchdog_help($section = 'admin/help#watchdog') {
       return t('<p>The watchdog module monitors your web site, capturing system events in a log to be reviewed by an authorized individual at a later time.  The watchdog log is simply a list of recorded events containing usage data, performance data, errors, warnings and operational information.  It is vital to <a href="%watchdog">check the watchdog report</a> on a regular basis as it is often the only way to tell what is going on.</p>', array('%watchdog' => url('admin/logs')));
     case 'admin/logs':
       return t('<p>The watchdog module monitors your web site, capturing system events in a log to be reviewed by an authorized individual at a later time.  The watchdog log is simply a list of recorded events containing usage data, performance data, errors, warnings and operational information.  It is vital to check the watchdog report on a regular basis as it is often the only way to tell what is going on.</p>');
-    case 'admin/logs/error':
-      return t('<p>Watchdog events about PHP and database errors.</p>');
-    case 'admin/logs/httpd':
-      return t('<p>Watchdog events that are from the web server, like 404s, etc.</p>');
-    case 'admin/logs/regular':
-      return t('<p>Watchdog events that are "normal" and have no other classification.</p>');
-    case 'admin/logs/search':
-      return t('<p>Watchdog events showing what users have searched for.</p>');
-    case 'admin/logs/special':
-      return t('<p>Watchdog events about adding, changing, and moderating nodes and comments.</p>');
-    case 'admin/logs/user':
-      return t('<p>Watchdog events that have to do with users and their accounts.</p>');
-    case 'admin/logs/warning':
-      return t('<p>Watchdog events that don\'t stop normal operation, but are things you should know.</p>');
     case 'admin/modules#description':
       return t('Logs and records system events.');
   }
@@ -49,14 +35,9 @@ function watchdog_menu($may_cache) {
   if ($may_cache) {
     $items[] = array('path' => 'admin/logs', 'title' => t('logs'),
       'callback' => 'watchdog_overview', 'access' => user_access('administer watchdog'));
-
-    $items[] = array('path' => 'admin/logs/view', 'title' => t('view details'),
-      'callback' => 'watchdog_view', 'access' => user_access('administer watchdog'),
+    $items[] = array('path' => 'admin/logs/event', 'title' => t('details'),
+      'callback' => 'watchdog_event', 'access' => user_access('administer watchdog'),
       'type' => MENU_CALLBACK);
-
-    foreach (_watchdog_get_message_types() as $type) {
-      $items[] = array('path' => 'admin/logs/'. $type, 'title' => t($type), 'type' => MENU_DYNAMIC_ITEM);
-    }
   }
   return $items;
 }
@@ -81,29 +62,46 @@ function watchdog_cron() {
 /**
  * Menu callback; displays a listing of log messages.
  */
-function watchdog_overview($type = '') {
-  foreach (_watchdog_get_message_types() as $key) {
-    $query[$key] = "WHERE type = '". db_escape_string($key) ."'";
+function watchdog_overview() {
+  $names['all'] = t('all messages');
+  $queries['all'] = '';
+  foreach (_watchdog_get_message_types() as $type) {
+    $names[$type] = t('%type messages', array('%type' => $type));
+    $queries[$type] = "WHERE type = '". db_escape_string($type) ."'";
+  }
+
+  if (empty($_SESSION['watchdog_overview_filter'])) {
+    $_SESSION['watchdog_overview_filter'] = 'all';
+  }
+
+  $op = $_POST['op'];
+  if ($op == t('Filter') && isset($_POST['edit']['filter'])) {
+    $_SESSION['watchdog_overview_filter'] = $_POST['edit']['filter'];
   }
 
+  $form  = form_select(t('Filter by type'), 'filter', $_SESSION['watchdog_overview_filter'], $names);
+  $form .= form_submit(t('Filter'));
+
   $header = array(
+    array('data' => t('Type'), 'field' => 'w.type'),
     array('data' => t('Date'), 'field' => 'w.timestamp', 'sort' => 'desc'),
     array('data' => t('Message'), 'field' => 'w.message'),
     array('data' => t('User'), 'field' => 'u.name'),
     array('data' => t('Operations'), 'colspan' => '2')
   );
-  $sql = 'SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid '. ($type ? $query[$type] : '') . tablesort_sql($header);
+  $sql = 'SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid '. $queries[$_SESSION['watchdog_overview_filter']] . tablesort_sql($header);
   $result = pager_query($sql, 50);
 
   while ($watchdog = db_fetch_object($result)) {
     $rows[] = array('data' =>
       array(
         // Cells
+        $watchdog->type,
         format_date($watchdog->timestamp, 'small'),
         truncate_utf8(strip_tags($watchdog->message), 64),
         format_name($watchdog),
         $watchdog->link,
-        l(t('details'), "admin/logs/view/$watchdog->wid")
+        l(t('details'), "admin/logs/event/$watchdog->wid")
       ),
       // Attributes for tr
       'class' => "watchdog-$watchdog->type"
@@ -118,13 +116,17 @@ function watchdog_overview($type = '') {
   if (!empty($pager)) {
     $rows[] = array(array('data' => $pager, 'colspan' => '5'));
   }
-  print theme('page', theme('table', $header, $rows));
+
+  $output  = '<div class="container-inline">'. form($form) .'</div>';
+  $output .= theme('table', $header, $rows);
+
+  print theme('page', $output);
 }
 
 /**
  * Menu callback; displays details about a log message.
  */
-function watchdog_view($id) {
+function watchdog_event($id) {
   $output = '';
   $result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d', $id);
   if ($watchdog = db_fetch_object($result)) {
@@ -132,7 +134,7 @@ function watchdog_view($id) {
     $output .= ' <tr><th>'. t('Type') ."</th><td>$watchdog->type</td></tr>";
     $output .= ' <tr><th>'. t('Date') .'</th><td>'. format_date($watchdog->timestamp, 'large') .'</td></tr>';
     $output .= ' <tr><th>'. t('User') .'</th><td>'. format_name($watchdog) .'</td></tr>';
-    $output .= ' <tr><th>'. t('Location') ."</th><td>$watchdog->location</td></tr>";
+    $output .= ' <tr><th>'. t('Location') ."</th><td>". l($watchdog->location, $watchdog->location) ."</td></tr>";
     $output .= ' <tr><th>'. t('Message') ."</th><td>$watchdog->message</td></tr>";
     $output .= ' <tr><th>'. t('Hostname') ."</th><td>$watchdog->hostname</td></tr>";
     $output .= '</table>';