From 673ef07f9aef1593d2b57e80918542603bca7eaf Mon Sep 17 00:00:00 2001
From: dairiki
Date: Wed, 7 Nov 2001 21:42:34 +0000
Subject: [PATCH] Fix SF bug #445108: Empty search string results in phpwiki
error.
git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/branches/release-1_2-branch@611 96ab9672-09ca-45d6-a79d-3d69d39ca109
---
lib/fullsearch.php | 49 +++++++++++++++++++++++++---------------------
lib/search.php | 17 ++++++++++------
2 files changed, 38 insertions(+), 28 deletions(-)
diff --git a/lib/fullsearch.php b/lib/fullsearch.php
index 342120ac9..1be5086c2 100644
--- a/lib/fullsearch.php
+++ b/lib/fullsearch.php
@@ -1,6 +1,6 @@
\n\n";
-
- // search matching pages
- $query = InitFullSearch($dbi, $full);
-
- // quote regexp chars (space are treated as "or" operator)
- $full = preg_replace("/\s+/", "|", preg_quote($full));
-
$found = 0;
$count = 0;
- while ($pagehash = FullSearchNextMatch($dbi, $query)) {
- $html .= "- " . LinkExistingWikiWord($pagehash["pagename"]) . "\n";
- $count++;
- // print out all matching lines, highlighting the match
- for ($j = 0; $j < (count($pagehash["content"])); $j++) {
+ if (strlen($full)) {
+ // search matching pages
+ $query = InitFullSearch($dbi, $full);
+
+ // quote regexp chars (space are treated as "or" operator)
+ $full = preg_replace("/\s+/", "|", preg_quote($full));
+
+ while ($pagehash = FullSearchNextMatch($dbi, $query)) {
+ $html .= "
- " . LinkExistingWikiWord($pagehash["pagename"]) . "\n";
+ $count++;
+
+ // print out all matching lines, highlighting the match
+ for ($j = 0; $j < (count($pagehash["content"])); $j++) {
if ($hits = preg_match_all(":$full:i", $pagehash["content"][$j], $dummy)) {
- $matched = preg_replace(":$full:i",
- "${FieldSeparator}OT\\0${FieldSeparator}CT",
- $pagehash["content"][$j]);
- $matched = htmlspecialchars($matched);
- $matched = str_replace("${FieldSeparator}OT", '', $matched);
- $matched = str_replace("${FieldSeparator}CT", '', $matched);
- $html .= "
- $matched
\n";
- $found += $hits;
+ $matched = preg_replace(":$full:i",
+ "${FieldSeparator}OT\\0${FieldSeparator}CT",
+ $pagehash["content"][$j]);
+ $matched = htmlspecialchars($matched);
+ $matched = str_replace("${FieldSeparator}OT", '', $matched);
+ $matched = str_replace("${FieldSeparator}CT", '', $matched);
+ $html .= "- $matched
\n";
+ $found += $hits;
}
- }
+ }
+ }
+ }
+ else {
+ $html .= "- " . gettext("(You entered an empty search string)") . "
\n";
}
$html .= "
\n
"
diff --git a/lib/search.php b/lib/search.php
index ad16914bd..13fa3e003 100644
--- a/lib/search.php
+++ b/lib/search.php
@@ -1,6 +1,6 @@
\n";
+ if (strlen($search)) {
+ $query = InitTitleSearch($dbi, $search);
+ while ($page = TitleSearchNextMatch($dbi, $query)) {
+ $found++;
+ $html .= LinkExistingWikiWord($page) . "
\n";
+ }
}
-
+ else {
+ $html .= gettext("(You entered an empty search string)") . "
\n";
+ }
+
$html .= "
\n"
. sprintf(gettext ("%d pages match your query."), $found)
. "\n";
--
2.45.0