[Home]WikiPatches/DefaultSearch

UseModWiki | WikiPatches | RecentChanges | Preferences

This patch was intended to go along with the /BackLinks patch, but it is more or less independent, so I made it a separate patch. The disclaimers on the /BackLinks page apply here too.

This patch automatically puts the page's title in the search text box at the bottom of each page. Thus, if you have the /BackLinks patch active and want to do a traditional full-search, you just click in the text box and hit enter.

The patch also includes a configuration variable to turn it on or off.

-- Wiki:RobHarwood


Going from top to bottom...

We need a new configuration variable. Instead of adding to the huge list, I just added a new line right after the list.

 # Configuration/constant variables:
 use vars qw(@RcDays? @HtmlPairs @HtmlSingle?
   $TempDir? $LockDir? $DataDir $HtmlDir? $UserDir $KeepDir? $PageDir
   ...
   $UserGotoBar);
 # PATCH: Default Search
 use vars qw($DefaultSearch?);
 # /PATCH: Default Search

Add the default value to the configuration section:
 $FreeUpper   = 1;       # 1 = force upper case,   0 = do not force case
 $FastGlob?    = 1;       # 1 = new faster code,    0 = old compatible code
 # PATCH: Default Search
 $DefaultSearch? = 1;     # 1 = search for title,   0 = blank search box
 # /PATCH: Default Search

In sub GetFooterText, add a new local variable:
 sub GetFooterText {
   my ($id, $rev) = @_;
   my $result = '';
Becomes:
 sub GetFooterText {
   my ($id, $rev) = @_;
   my $result = '';
   # PATCH: Default search
   my ($search);
   # /PATCH: Default search

A little lower in GetFooterText, we add a parameter to GetSearchForm.
  if ($UseDiff) {
    $result .= ' ' . &ScriptLinkDiff?(4, $id, T('(diff)'), $rev);
  }
  $result .= '
' . &GetSearchForm();
Becomes:
  if ($UseDiff) {
    $result .= ' ' . &ScriptLinkDiff?(4, $id, T('(diff)'), $rev);
  }
  # PATCH: Default search
  if ($DefaultSearch?) {
    $search = $id;
    $search =~ s|.*/|/|;
    $search =~ s|_| |g;
  }
  $result .= '
' . &GetSearchForm(
$search'''); # /PATCH: Default search

Finally, GetSearchForm gets a face-lift and a new optional parameter.
 sub GetSearchForm {
   my ($result);

   $result = T('Search:') . ' ' . $q->textfield(-name=>'search', -size=>20)
             . &GetHiddenValue("dosearch", 1);
   return $result;
 }
Becomes:
 # PATCH: Default search
 sub GetSearchForm {
   my ($search) = @_;
   my ($result, $text);

   if (defined($search)) {
     $text = $q->textfield(-name=>'search', -value=>$search, -size=>20);
   }else{
     $text = $q->textfield(-name=>'search', -size=>20);
   }
   $result = T('Search:') . ' ' . $text
             . &GetHiddenValue("dosearch", 1);
   return $result;
 }
 # /PATCH: Default search

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited November 21, 2007 12:15 pm by MarkusLude (diff)
Search: