From d6ce51e4ce39c143732f69de9a5590428d6e3c6c Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Sat, 10 Feb 2001 11:59:06 +0000
Subject: [PATCH] - added a "search framework" which allows for easy searching 
  (to be continued) - tidyied up some existing code

---
 includes/common.inc              |  3 +-
 includes/function.inc            |  5 +--
 modules/account.module           | 59 +++++++++++++++++++-------------
 modules/comment.module           | 18 ++++++++--
 modules/comment/comment.module   | 18 ++++++++--
 modules/diary.module             | 25 +++++++++++---
 modules/story.module             | 22 ++++++++----
 modules/story/story.module       | 22 ++++++++----
 modules/watchdog.module          |  4 +--
 modules/watchdog/watchdog.module |  4 +--
 10 files changed, 127 insertions(+), 53 deletions(-)

diff --git a/includes/common.inc b/includes/common.inc
index f5ebc09d6f58..3cda625af18c 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -15,8 +15,9 @@ function conf_load() {
 include_once "includes/database.inc";
 include_once "includes/watchdog.inc";
 include_once "includes/function.inc";
-include_once "includes/module.inc";
+include_once "includes/search.inc";
 include_once "includes/locale.inc";
+include_once "includes/module.inc";
 include_once "includes/theme.inc";
 include_once "includes/user.inc";
 
diff --git a/includes/function.inc b/includes/function.inc
index 98a9da53e9e1..c8b027934feb 100644
--- a/includes/function.inc
+++ b/includes/function.inc
@@ -76,8 +76,9 @@ function format_data($field, $replacement = "<I>na</I>") {
   return ($field) ? $field : $replacement;
 }
 
-function format_username($username, $admin = 0) {
-  if ($username) return ($admin) ? "<A HREF=\"admin.php?mod=account&op=view&name=$username\">$username</A>" : "<A HREF=\"account.php?op=view&name=$username\">$username</A>";
+function format_username($username) {
+  global $user;
+  if ($username) return (user_permission($user) ? "<A HREF=\"admin.php?mod=account&op=view&name=$username\">$username</A>" : "<A HREF=\"account.php?op=view&name=$username\">$username</A>");
   else { global $anonymous; return $anonymous; }
 }
 
diff --git a/modules/account.module b/modules/account.module
index 90ff8f038c81..ca5ddc6db993 100644
--- a/modules/account.module
+++ b/modules/account.module
@@ -6,23 +6,6 @@
                 "block" => "account_block",
                 "admin" => "account_admin");
 
-function account_help() {
- ?>
-  <P>The account-module is responsible for maintaining the user database. It automatically handles tasks like registration, authentication, access rights, password retrieval, user settings and much more.</P>
-  <P>The required administration can be accomplished through the "account" interface of the administration section.  From here administrators can get a quick overview of all registered users and view/edit specific accounts using the links provided.  Some useful operations include blocking specific accounts (e.g. a troublesome user) and giving/taking administration permissions.  Note that you should only give these permissions to people you trust!</P>
-  <P>Check the documentation page for detailed information about user management.</P>
-  <H3>User rating</H3>
-  <P>The account cron will periodically calculate an overall rating of each user's contributed value that is a time-weighted average of his or her comments ratings with an additional bonus for the stories he or she contributed.  The system can be best compared with <A HREF="http://slashcode.com/">SlashCode</A>'s karma and is - in fact - even more similar to <A HREF="http://scoop.kuro5hin.org/">Scoop</A>'s mojo implementation.</P>
-  <P>I won't elaborate on all the funny math involved and it suffices to say that the actual weighting is done in such a way:</P>
-  <OL>
-   <LI>that comments with a lot of votes count more then comments with only one or two votes.</LI>
-   <LI>that newer comments count for more then older comments.</LI>
-  </OL>
-  <P>The idea of (1) is that it favors comments that more people voted on, and thus whose rating is more likely to be accurate or justified.</P>
-  <P>The latter (2) makes the user rating that comes out of the calulations temporary, based on users' most recent activity and responsive to their current state.  This is accomplished by taking each user's last 30 comments, or however many he or she posted in the last 60 days - whatever comes first.</P>
-  <P>Additionally, users that posted one or more succesful stories in the last 60 days gain extra bonus points which will boost up their overall rating.</P>
- <?
-}
 
 function account_cron_ratings() {
   $period = 5184000;  // 60 days
@@ -56,15 +39,40 @@ function account_cron() {
   account_cron_ratings();
 }
 
+function account_help() {
+ ?>
+  <P>The account-module is responsible for maintaining the user database. It automatically handles tasks like registration, authentication, access rights, password retrieval, user settings and much more.</P>
+  <P>The required administration can be accomplished through the "account" interface of the administration section.  From here administrators can get a quick overview of all registered users and view/edit specific accounts using the links provided.  Some useful operations include blocking specific accounts (e.g. a troublesome user) and giving/taking administration permissions.  Note that you should only give these permissions to people you trust!</P>
+  <P>Check the documentation page for detailed information about user management.</P>
+  <H3>User rating</H3>
+  <P>The account cron will periodically calculate an overall rating of each user's contributed value that is a time-weighted average of his or her comments ratings with an additional bonus for the stories he or she contributed.  The system can be best compared with <A HREF="http://slashcode.com/">SlashCode</A>'s karma and is - in fact - even more similar to <A HREF="http://scoop.kuro5hin.org/">Scoop</A>'s mojo implementation.</P>
+  <P>I won't elaborate on all the funny math involved and it suffices to say that the actual weighting is done in such a way:</P>
+  <OL>
+   <LI>that comments with a lot of votes count more then comments with only one or two votes.</LI>
+   <LI>that newer comments count for more then older comments.</LI>
+  </OL>
+  <P>The idea of (1) is that it favors comments that more people voted on, and thus whose rating is more likely to be accurate or justified.</P>
+  <P>The latter (2) makes the user rating that comes out of the calulations temporary, based on users' most recent activity and responsive to their current state.  This is accomplished by taking each user's last 30 comments, or however many he or she posted in the last 60 days - whatever comes first.</P>
+  <P>Additionally, users that posted one or more succesful stories in the last 60 days gain extra bonus points which will boost up their overall rating.</P>
+ <?
+}
+
 function account_find($keys) {
+  global $user;
   $find = array();
   $result = db_query("SELECT * FROM users WHERE userid LIKE '%". check_input($keys) ."%' LIMIT 20");
   while ($account = db_fetch_object($result)) {
-    array_push($find, array("subject" => $account->userid, "link" => "account.php?op=view&name=$account->userid", "user" => $account->userid));
+    array_push($find, array("subject" => $account->userid, "link" => (user_permission($user) ? "admin.php?mod=account&op=view&name=$account->userid" : "account.php?op=view&name=$account->userid"), "user" => $account->userid));
   }
   return $find;
 }
 
+function account_search() {
+  global $keys, $mod;
+  search_form($keys);
+  search_data($keys, $mod);
+}
+
 function account_display($order = "username") {
   $sort = array("ID" => "id", "fake e-mail address" => "fake_email", "hostname" => "last_host DESC", "last access date" => "last_access DESC", "real e-mail address" => "real_email", "real name" => "name", "permissions" => "permissions", "rating" => "rating DESC", "status" => "status", "theme" => "theme", "timezone" => "timezone DESC", "username" => "userid");
   $show = array("ID" => "id", "username" => "userid", "$order" => "$sort[$order]", "homepage" => "url");
@@ -119,7 +127,7 @@ function account_display($order = "username") {
           $output .= "  <TD>". format_url($account[$value]) ."</TD>\n";
           break;
         case "userid":
-          $output .= "  <TD>". format_username($account[$value], 1) ."</TD>\n";
+          $output .= "  <TD>". format_username($account[$value]) ."</TD>\n";
           break;
         default:
           $output .= "  <TD>". format_data($account[$value]) ."</TD>\n";
@@ -185,7 +193,8 @@ function account_edit($name) {
     $output .= " <TR><TD ALIGN=\"right\"><B>Fake e-mail address:</B></TD><TD><INPUT NAME=\"edit[fake_email]\" SIZE=\"55\" VALUE=\"$account->fake_email\"></TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>URL of homepage:</B></TD><TD><INPUT NAME=\"edit[url]\" SIZE=\"55\" VALUE=\"$account->url\"></TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Permissions:</B></TD><TD>$perm</TD></TR>\n";
-    $output .= " <TR><TD ALIGN=\"right\"><B>Last access:</B></TD><TD>". format_date($account->last_access) ." from $account->last_host</TD></TR>\n";
+    $output .= " <TR><TD ALIGN=\"right\"><B>Last access:</B></TD><TD>". format_date($account->last_access) ." from ". format_data($account->last_host) ."</TD></TR>\n";
+    $output .= " <TR><TD ALIGN=\"right\"><B>User rating:</B></TD><TD>". format_data($account->rating) ."</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Bio information:</B></TD><TD><TEXTAREA NAME=\"edit[bio]\" COLS=\"35\" ROWS=\"5\" WRAP=\"virtual\">$account->bio</TEXTAREA></TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Signature:</B></TD><TD><TEXTAREA NAME=\"edit[signature]\" COLS=\"35\" ROWS=\"5\" WRAP=\"virtual\">$account->signature</TEXTAREA></TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Theme:</B></TD><TD>". format_data($account->theme) ."</TD></TR>\n";
@@ -208,7 +217,7 @@ function account_view($name) {
 
   if ($account = db_fetch_object($result)) {
     $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">\n";
-    $output .= " <TR><TD ALIGN=\"right\"><B>ID:</B></TD><TD>$account->id</TD></TR>\n";
+    $output .= " <TR><TD ALIGN=\"right\"><B>ID:</B></TD><TD><A HREF=\"admin.php?mod=account&op=edit&name=$account->userid\">$account->id</A></TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Status:</B></TD><TD>". $status[$account->status] ."</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Username:</B></TD><TD>$account->userid</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Real name:</B></TD><TD>". format_data($account->name) ."</TD></TR>\n";
@@ -216,7 +225,8 @@ function account_view($name) {
     $output .= " <TR><TD ALIGN=\"right\"><B>Fake e-mail address:</B></TD><TD>". format_data($account->fake_email) ."</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>URL of homepage:</B></TD><TD>". format_url($account->url) ."</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Permissions:</B></TD><TD>". $permissions[$account->permissions] ."</TD></TR>\n";
-    $output .= " <TR><TD ALIGN=\"right\"><B>Last access:</B></TD><TD>". format_date($account->last_access) ." from $account->last_host</TD></TR>\n";
+    $output .= " <TR><TD ALIGN=\"right\"><B>Last access:</B></TD><TD>". format_date($account->last_access) ." from ". format_data($account->last_host) ."</TD></TR>\n";
+    $output .= " <TR><TD ALIGN=\"right\"><B>User rating:</B></TD><TD>". format_data($account->rating) ."</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Bio information:</B></TD><TD>". format_data($account->bio) ."</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Signature:</B></TD><TD>". format_data($account->signature) ."</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Theme:</B></TD><TD>". format_data($account->theme) ."</TD></TR>\n";
@@ -248,7 +258,7 @@ function account_block() {
 function account_admin() {
   global $op, $edit, $order, $name;
 
-  print "<SMALL><A HREF=\"admin.php?mod=account\">overview</A> | <A HREF=\"admin.php?mod=account&op=help\">help</A></SMALL><HR>\n";
+  print "<SMALL><A HREF=\"admin.php?mod=account\">overview</A> | <A HREF=\"admin.php?mod=account&op=search\">search account</A> | <A HREF=\"admin.php?mod=account&op=help\">help</A></SMALL><HR>\n";
 
   switch ($op) {
     case "edit":
@@ -257,6 +267,9 @@ function account_admin() {
     case "help":
       account_help();
       break;
+    case "search":
+      account_search();
+      break;
     case "view":
       account_view($name);
       break;
diff --git a/modules/comment.module b/modules/comment.module
index bd6594dbc4a8..f97728e7a3fe 100644
--- a/modules/comment.module
+++ b/modules/comment.module
@@ -4,14 +4,21 @@
                 "admin" => "comment_admin");
 
 function comment_find($keys) {
+  global $user;
   $find = array();
   $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.subject LIKE '%". check_input($keys) ."%' OR c.comment LIKE '%". check_input($keys) ."%' ORDER BY c.timestamp DESC LIMIT 20");
   while ($comment = db_fetch_object($result)) {
-    array_push($find, array("subject" => check_output($comment->subject), "link" => "story.php?id=$comment->lid&cid=$comment->cid", "user" => $story->userid, "date" => $comment->timestamp));
+    array_push($find, array("subject" => check_output($comment->subject), "link" => (user_permission($user) ? "admin.php?mod=comment&op=edit&id=$comment->cid" : "story.php?id=$comment->lid&cid=$comment->cid"), "user" => $story->userid, "date" => $comment->timestamp));
   }
   return $find;
 }
 
+function comment_search() {
+  global $keys, $mod;
+  search_form($keys);
+  search_data($keys, $mod);
+}
+
 function comment_edit($id) {
   $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = $id");
 
@@ -21,7 +28,7 @@ function comment_edit($id) {
 
   $output .= "<P>\n";
   $output .= " <B>Author:</B><BR>\n";
-  $output .= " ". format_username($comment->userid, 1) ."\n";
+  $output .= " ". format_username($comment->userid) ."\n";
   $output .= "</P>\n";
 
   $output .= "<P>\n";
@@ -76,7 +83,7 @@ function comment_display($order = "date") {
   $output .= " </TR>\n";
 
   while ($comment = db_fetch_object($result)) {
-    $output .= " <TR><TD>". ($comment->link == "story" ? "<A HREF=\"story.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</A>" : check_output($comment->subject)) ."</TD><TD>". format_username($comment->userid, 1) ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=comment&op=edit&id=$comment->cid\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD>". ($comment->link == "story" ? "<A HREF=\"story.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</A>" : check_output($comment->subject)) ."</TD><TD>". format_username($comment->userid) ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=comment&op=edit&id=$comment->cid\">edit</A></TD></TR>\n";
   }
 
   $output .= "</TABLE>\n";
@@ -87,10 +94,15 @@ function comment_display($order = "date") {
 function comment_admin() {
   global $op, $id, $subject, $comment, $order;
 
+  print "<SMALL><A HREF=\"admin.php?mod=comment\">overview</A> | <A HREF=\"admin.php?mod=comment&op=search\">search comment</A></SMALL><HR>\n";
+
   switch ($op) {
     case "edit":
       comment_edit($id);
       break;
+    case "search":
+      comment_search();
+      break;
     case "Save comment":
       comment_save($id, $subject, $comment);
       comment_edit($id);
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index bd6594dbc4a8..f97728e7a3fe 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -4,14 +4,21 @@
                 "admin" => "comment_admin");
 
 function comment_find($keys) {
+  global $user;
   $find = array();
   $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.subject LIKE '%". check_input($keys) ."%' OR c.comment LIKE '%". check_input($keys) ."%' ORDER BY c.timestamp DESC LIMIT 20");
   while ($comment = db_fetch_object($result)) {
-    array_push($find, array("subject" => check_output($comment->subject), "link" => "story.php?id=$comment->lid&cid=$comment->cid", "user" => $story->userid, "date" => $comment->timestamp));
+    array_push($find, array("subject" => check_output($comment->subject), "link" => (user_permission($user) ? "admin.php?mod=comment&op=edit&id=$comment->cid" : "story.php?id=$comment->lid&cid=$comment->cid"), "user" => $story->userid, "date" => $comment->timestamp));
   }
   return $find;
 }
 
+function comment_search() {
+  global $keys, $mod;
+  search_form($keys);
+  search_data($keys, $mod);
+}
+
 function comment_edit($id) {
   $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = $id");
 
@@ -21,7 +28,7 @@ function comment_edit($id) {
 
   $output .= "<P>\n";
   $output .= " <B>Author:</B><BR>\n";
-  $output .= " ". format_username($comment->userid, 1) ."\n";
+  $output .= " ". format_username($comment->userid) ."\n";
   $output .= "</P>\n";
 
   $output .= "<P>\n";
@@ -76,7 +83,7 @@ function comment_display($order = "date") {
   $output .= " </TR>\n";
 
   while ($comment = db_fetch_object($result)) {
-    $output .= " <TR><TD>". ($comment->link == "story" ? "<A HREF=\"story.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</A>" : check_output($comment->subject)) ."</TD><TD>". format_username($comment->userid, 1) ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=comment&op=edit&id=$comment->cid\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD>". ($comment->link == "story" ? "<A HREF=\"story.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</A>" : check_output($comment->subject)) ."</TD><TD>". format_username($comment->userid) ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=comment&op=edit&id=$comment->cid\">edit</A></TD></TR>\n";
   }
 
   $output .= "</TABLE>\n";
@@ -87,10 +94,15 @@ function comment_display($order = "date") {
 function comment_admin() {
   global $op, $id, $subject, $comment, $order;
 
+  print "<SMALL><A HREF=\"admin.php?mod=comment\">overview</A> | <A HREF=\"admin.php?mod=comment&op=search\">search comment</A></SMALL><HR>\n";
+
   switch ($op) {
     case "edit":
       comment_edit($id);
       break;
+    case "search":
+      comment_search();
+      break;
     case "Save comment":
       comment_save($id, $subject, $comment);
       comment_edit($id);
diff --git a/modules/diary.module b/modules/diary.module
index 19b683df2d7c..15dac5dcdad9 100644
--- a/modules/diary.module
+++ b/modules/diary.module
@@ -12,21 +12,28 @@
 include_once "includes/common.inc";
 
 function diary_find($keys) {
+  global $user;
   $find = array();
   $result = db_query("SELECT d.*, u.userid FROM diaries d LEFT JOIN users u ON d.author = u.id WHERE d.text LIKE '%". check_input($keys) ."%' ORDER BY d.timestamp DESC LIMIT 20");
   while ($diary = db_fetch_object($result)) {
-    array_push($find, array("subject" => "$diary->userid's diary", "link" => "module.php?mod=diary&op=view&name=$diary->userid", "user" => $diary->userid, "date" => $diary->timestamp));
+    array_push($find, array("subject" => "$diary->userid's diary", "link" => (user_permission($user) ? "admin.php?mod=diary&op=edit&id=$diary->id" : "module.php?mod=diary&op=view&name=$diary->userid"), "user" => $diary->userid, "date" => $diary->timestamp));
   }
   return $find;
 
 }
 
+function diary_search() {
+  global $keys, $mod;
+  search_form($keys);
+  search_data($keys, $mod);
+}
+
 function diary_page_overview($num = 20) {
   global $theme, $user;
 
   $result = db_query("SELECT d.*, u.userid FROM diaries d LEFT JOIN users u ON d.author = u.id ORDER BY d.timestamp DESC LIMIT $num");
 
-  $output .= "<P>This part of the website is dedicated to providing easy-to-write and easy-to-read online diaries or journals filled with daily thoughts, poetry, boneless blabber, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on current facts, fresh insights, diverse dreams, chronicles and mumbling madness available for general human consumption.</P>";
+  $output .= "<P>This part of the website is dedicated to provide easy-to-write and easy-to-read online diaries or journals filled with daily thoughts, poetry, boneless blabber, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on current facts, fresh insights, diverse dreams, chronicles and mumbling madness available for public consumption.</P>";
 
   while ($diary = db_fetch_object($result)) {
     if ($time != date("F jS", $diary->timestamp)) {
@@ -210,7 +217,7 @@ function diary_page() {
 
 function diary_help() {
  ?>
-  <P>Drupal's diary module allows registered users to maintain an online diary.</P>
+  <P>Drupal's diary module allows registered users to maintain an online diary.  It provides easy-to-write and easy-to-read online diaries or journals that can be filled with daily thoughts, poetry, boneless blabber, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on current facts, fresh insights, diverse dreams, chronicles and mumbling madness available for public consumption.</P>
  <?
 }
 
@@ -262,7 +269,7 @@ function diary_admin_edit($id) {
 
   $output .= "<P>\n";
   $output .= " <B>Author:</B><BR>\n";
-  $output .= " ". format_username($diary->userid, 1) ."\n";
+  $output .= " ". format_username($diary->userid) ."\n";
   $output .= "</P>\n";
 
   $output .= "<P>\n";
@@ -312,7 +319,7 @@ function diary_admin_display($order = "date") {
   $output .= " </TR>\n";
 
   while ($diary = db_fetch_object($result)) {
-    $output .= " <TR><TD><A HREF=\"module.php?mod=diary&op=view&name=$diary->userid\">$diary->userid on ". format_date($diary->timestamp, "small") ."</A></TD><TD>". format_username($diary->userid, 1) ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=diary&op=edit&id=$diary->id\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD><A HREF=\"module.php?mod=diary&op=view&name=$diary->userid\">$diary->userid on ". format_date($diary->timestamp, "small") ."</A></TD><TD>". format_username($diary->userid) ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=diary&op=edit&id=$diary->id\">edit</A></TD></TR>\n";
   }
 
   $output .= "</TABLE>\n";
@@ -324,10 +331,18 @@ function diary_admin_display($order = "date") {
 function diary_admin() {
   global $op, $id, $text, $order;
 
+  print "<SMALL><A HREF=\"admin.php?mod=diary\">overview</A> | <A HREF=\"admin.php?mod=diary&op=search\">search diary</A> | <A HREF=\"admin.php?mod=diary&op=help\">help</A></SMALL><HR>\n";
+
   switch ($op) {
     case "edit":
       diary_admin_edit($id);
       break;
+    case "help":
+      diary_help();
+      break;
+    case "search":
+      diary_search();
+      break;
     case "Save diary entry":
       diary_admin_save($id, $text);
       diary_admin_edit($id);
diff --git a/modules/story.module b/modules/story.module
index e71f74bbaddc..4a199951b42c 100644
--- a/modules/story.module
+++ b/modules/story.module
@@ -16,14 +16,21 @@ function story_cron() {
 }
 
 function story_find($keys) {
+  global $user;
   $find = array();
   $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.status = 2 AND (s.subject LIKE '%". check_input($keys) ."%' OR s.abstract LIKE '%". check_input($keys) ."%' OR s.article LIKE '%". check_input($keys) ."%') ORDER BY s.timestamp DESC LIMIT 20");
   while ($story = db_fetch_object($result)) {
-    array_push($find, array("subject" => check_output($story->subject), "link" => "story.php?id=$story->id", "user" => $story->userid, "date" => $story->timestamp));
+    array_push($find, array("subject" => check_output($story->subject), "link" => (user_permission($user) ? "admin.php?mod=story&op=edit&id=$story->id" : "story.php?id=$story->id"), "user" => $story->userid, "date" => $story->timestamp));
   }
   return $find;
 }
 
+function story_search() {
+  global $keys, $mod;
+  search_form($keys);
+  search_data($keys, $mod);
+}
+
 function story_help() {
  ?>
   <P>Scheduled stories: stories that are scheduled to be automatically published at a given date and time.  Useful when you have to leave the site alone for a while or when you want to regulate the flow of new content.</P>
@@ -187,28 +194,28 @@ function story_display() {
   $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 1 ORDER BY timestamp DESC");
   $output .= " <TR><TH COLSPAN=\"4\">queued stories</TH></TR>\n";
   while ($story = db_fetch_object($result)) {
-    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid, 1) ."</TD><TD>votes: $story->votes, score: $story->score</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>votes: $story->votes, score: $story->score</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
   }
 
   // Scheduled stories:
   $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 3 ORDER BY timestamp");
   $output .= " <TR><TH COLSPAN=\"4\">scheduled stories</TH></TR>\n";
   while ($story = db_fetch_object($result)) {
-    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid, 1) ."</TD><TD>". date("D, m/d/Y H:i", $story->timestamp) ." - ". format_interval($story->timestamp - time()) ." left</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>". date("D, m/d/Y H:i", $story->timestamp) ." - ". format_interval($story->timestamp - time()) ." left</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
   }
 
   // Dumped stories:
   $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 0 ORDER BY timestamp DESC LIMIT 5");
   $output .= " <TR><TH COLSPAN=\"4\">dumped stories</TTH></TR>\n";
   while ($story = db_fetch_object($result)) {
-    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid, 1) ."</TD><TD>$story->section</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>$story->section</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
   }
 
   // Posted stories:
   $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 2 ORDER BY timestamp DESC LIMIT 15");
   $output .= " <TR><TH COLSPAN=\"4\">posted stories</TH></TR>\n";
   while ($story = db_fetch_object($result)) {
-    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid, 1) ."</TD><TD>$story->section</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>$story->section</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
   }
 
   $output .= "</TABLE>\n";
@@ -219,7 +226,7 @@ function story_display() {
 function story_admin() {
   global $op, $id, $edit;
 
-  print "<SMALL><A HREF=\"admin.php?mod=story&op=add\">add new story</A> | <A HREF=\"admin.php?mod=story\">overview</A> | <A HREF=\"admin.php?mod=story&op=help\">help</A></SMALL><HR>\n";
+  print "<SMALL><A HREF=\"admin.php?mod=story&op=add\">add new story</A> | <A HREF=\"admin.php?mod=story\">overview</A> | <A HREF=\"admin.php?mod=story&op=search\">search story</A> | <A HREF=\"admin.php?mod=story&op=help\">help</A></SMALL><HR>\n";
 
   switch ($op) {
     case "add":
@@ -231,6 +238,9 @@ function story_admin() {
     case "help":
       story_help();
       break;
+   case "search":
+      story_search();
+      break;
     case "Add story":
       story_add_save($edit);
       story_display();
diff --git a/modules/story/story.module b/modules/story/story.module
index e71f74bbaddc..4a199951b42c 100644
--- a/modules/story/story.module
+++ b/modules/story/story.module
@@ -16,14 +16,21 @@ function story_cron() {
 }
 
 function story_find($keys) {
+  global $user;
   $find = array();
   $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.status = 2 AND (s.subject LIKE '%". check_input($keys) ."%' OR s.abstract LIKE '%". check_input($keys) ."%' OR s.article LIKE '%". check_input($keys) ."%') ORDER BY s.timestamp DESC LIMIT 20");
   while ($story = db_fetch_object($result)) {
-    array_push($find, array("subject" => check_output($story->subject), "link" => "story.php?id=$story->id", "user" => $story->userid, "date" => $story->timestamp));
+    array_push($find, array("subject" => check_output($story->subject), "link" => (user_permission($user) ? "admin.php?mod=story&op=edit&id=$story->id" : "story.php?id=$story->id"), "user" => $story->userid, "date" => $story->timestamp));
   }
   return $find;
 }
 
+function story_search() {
+  global $keys, $mod;
+  search_form($keys);
+  search_data($keys, $mod);
+}
+
 function story_help() {
  ?>
   <P>Scheduled stories: stories that are scheduled to be automatically published at a given date and time.  Useful when you have to leave the site alone for a while or when you want to regulate the flow of new content.</P>
@@ -187,28 +194,28 @@ function story_display() {
   $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 1 ORDER BY timestamp DESC");
   $output .= " <TR><TH COLSPAN=\"4\">queued stories</TH></TR>\n";
   while ($story = db_fetch_object($result)) {
-    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid, 1) ."</TD><TD>votes: $story->votes, score: $story->score</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>votes: $story->votes, score: $story->score</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
   }
 
   // Scheduled stories:
   $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 3 ORDER BY timestamp");
   $output .= " <TR><TH COLSPAN=\"4\">scheduled stories</TH></TR>\n";
   while ($story = db_fetch_object($result)) {
-    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid, 1) ."</TD><TD>". date("D, m/d/Y H:i", $story->timestamp) ." - ". format_interval($story->timestamp - time()) ." left</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>". date("D, m/d/Y H:i", $story->timestamp) ." - ". format_interval($story->timestamp - time()) ." left</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
   }
 
   // Dumped stories:
   $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 0 ORDER BY timestamp DESC LIMIT 5");
   $output .= " <TR><TH COLSPAN=\"4\">dumped stories</TTH></TR>\n";
   while ($story = db_fetch_object($result)) {
-    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid, 1) ."</TD><TD>$story->section</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>$story->section</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
   }
 
   // Posted stories:
   $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 2 ORDER BY timestamp DESC LIMIT 15");
   $output .= " <TR><TH COLSPAN=\"4\">posted stories</TH></TR>\n";
   while ($story = db_fetch_object($result)) {
-    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid, 1) ."</TD><TD>$story->section</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
+    $output .= " <TR><TD><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>$story->section</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=edit&id=$story->id\">edit</A></TD></TR>\n";
   }
 
   $output .= "</TABLE>\n";
@@ -219,7 +226,7 @@ function story_display() {
 function story_admin() {
   global $op, $id, $edit;
 
-  print "<SMALL><A HREF=\"admin.php?mod=story&op=add\">add new story</A> | <A HREF=\"admin.php?mod=story\">overview</A> | <A HREF=\"admin.php?mod=story&op=help\">help</A></SMALL><HR>\n";
+  print "<SMALL><A HREF=\"admin.php?mod=story&op=add\">add new story</A> | <A HREF=\"admin.php?mod=story\">overview</A> | <A HREF=\"admin.php?mod=story&op=search\">search story</A> | <A HREF=\"admin.php?mod=story&op=help\">help</A></SMALL><HR>\n";
 
   switch ($op) {
     case "add":
@@ -231,6 +238,9 @@ function story_admin() {
     case "help":
       story_help();
       break;
+   case "search":
+      story_search();
+      break;
     case "Add story":
       story_add_save($edit);
       story_display();
diff --git a/modules/watchdog.module b/modules/watchdog.module
index 5762842725c5..81593d4c0a40 100644
--- a/modules/watchdog.module
+++ b/modules/watchdog.module
@@ -36,7 +36,7 @@ function watchdog_display($order = "date") {
   $output .= " </TR>\n";
 
   while ($watchdog = db_fetch_object($result)) {
-    $output .= " <TR BGCOLOR=\"". $colors[$watchdog->level] ."\"><TD>". format_date($watchdog->timestamp) ."</TD><TD>". substr(check_output($watchdog->message), 0, 44) ."</TD><TD ALIGN=\"center\">". format_username($watchdog->userid, 1) ."</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=watchdog&op=view&id=$watchdog->id\">details</A></TD></TR>\n";
+    $output .= " <TR BGCOLOR=\"". $colors[$watchdog->level] ."\"><TD>". format_date($watchdog->timestamp) ."</TD><TD>". substr(check_output($watchdog->message), 0, 44) ."</TD><TD ALIGN=\"center\">". format_username($watchdog->userid) ."</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=watchdog&op=view&id=$watchdog->id\">details</A></TD></TR>\n";
   }
 
   $output .= "</TABLE>\n";
@@ -51,7 +51,7 @@ function watchdog_view($id) {
     $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Level:</B></TD><TD>$watchdog->level</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Date:</B></TD><TD>". format_date($watchdog->timestamp, "extra large") ."</TD></TR>\n";
-    $output .= " <TR><TD ALIGN=\"right\"><B>User:</B></TD><TD>". format_username($watchdog->userid, 1) ."</TD></TR>\n";
+    $output .= " <TR><TD ALIGN=\"right\"><B>User:</B></TD><TD>". format_username($watchdog->userid) ."</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Location:</B></TD><TD>$watchdog->location</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Message:</B></TD><TD>$watchdog->message</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Hostname:</B></TD><TD>$watchdog->hostname</TD></TR>\n";
diff --git a/modules/watchdog/watchdog.module b/modules/watchdog/watchdog.module
index 5762842725c5..81593d4c0a40 100644
--- a/modules/watchdog/watchdog.module
+++ b/modules/watchdog/watchdog.module
@@ -36,7 +36,7 @@ function watchdog_display($order = "date") {
   $output .= " </TR>\n";
 
   while ($watchdog = db_fetch_object($result)) {
-    $output .= " <TR BGCOLOR=\"". $colors[$watchdog->level] ."\"><TD>". format_date($watchdog->timestamp) ."</TD><TD>". substr(check_output($watchdog->message), 0, 44) ."</TD><TD ALIGN=\"center\">". format_username($watchdog->userid, 1) ."</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=watchdog&op=view&id=$watchdog->id\">details</A></TD></TR>\n";
+    $output .= " <TR BGCOLOR=\"". $colors[$watchdog->level] ."\"><TD>". format_date($watchdog->timestamp) ."</TD><TD>". substr(check_output($watchdog->message), 0, 44) ."</TD><TD ALIGN=\"center\">". format_username($watchdog->userid) ."</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=watchdog&op=view&id=$watchdog->id\">details</A></TD></TR>\n";
   }
 
   $output .= "</TABLE>\n";
@@ -51,7 +51,7 @@ function watchdog_view($id) {
     $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Level:</B></TD><TD>$watchdog->level</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Date:</B></TD><TD>". format_date($watchdog->timestamp, "extra large") ."</TD></TR>\n";
-    $output .= " <TR><TD ALIGN=\"right\"><B>User:</B></TD><TD>". format_username($watchdog->userid, 1) ."</TD></TR>\n";
+    $output .= " <TR><TD ALIGN=\"right\"><B>User:</B></TD><TD>". format_username($watchdog->userid) ."</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Location:</B></TD><TD>$watchdog->location</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Message:</B></TD><TD>$watchdog->message</TD></TR>\n";
     $output .= " <TR><TD ALIGN=\"right\"><B>Hostname:</B></TD><TD>$watchdog->hostname</TD></TR>\n";
-- 
GitLab