[Home]WikiPatches/CollectPages

UseModWiki | WikiPatches | RecentChanges | Preferences

With this patch you can search into titles of pages, some strings; with optional "sensitive case" and "want word" (no wrap).Search action, can use the particles "or", "and", too.

If there's matches, it returns pages and its contents, all in one.

 sub DoOtherRequest {
 ...
 +     } elsif ($action eq 'pick') {
 +       &DoPick();
 ...
 }

 + sub DoPick {
 + my ($collect, $titles, $text);
 +
 +  $collect = &GetParam('collect','');
 +  print &GetHeader('', &QuoteHtml(Ts('PickFor: %s', $collect)), '');
 +  print &GetFormStart();
 +  print &GetHiddenValue('action', 'pick');
 +  print $q->textfield(-name=>'collect',-size=>60, -maxlength=>200);
 +  print $q->submit(-name=>'pick');
 +  print '<br>';
 +  print $q->checkbox(-name=>'wordsearch', -default => 'checked',
 +                            -label => ' '. T('word'));
 +  print ' ';
 +  print $q->checkbox(-name=>'casesearch', -default => 'checked',
 +                           -label => ' ' . T('case'));
 +  print $q->endform;
 +  if (!$collect) {
 +    print GetCommonFooter();
 +    return;
 +  }
 +  $titles = &SearchName($collect);
 +  if ($titles) {
 +    print T('Titles');
 +    &PrintPageList(&SearchName($collect, $casesearch));
 +    for (&SearchName($collect, $casesearch)) {
 +      print &GetPageLink($_);
 +      &OpenPage($_);
 +      &OpenDefaultText();
 +      $text = $Text{'text'};
 +      print &WikiToHTML($text);
 +      if ($Toc) {
 +        $Toc = '';
 +        $SectionNumber = 0;
 +      }
 +    }
 + } else {
 +    print T('Invalid URL or file does not exist --nothing done');
 +  }
 +  print GetCommonFooter();
 +  return;
 +} 

 + sub SearchName {
 + my $string = shift;
 + my ($wordsearch, $casesearch);
 + my ($name, $freeName, $found, @found);
 +
 + my $and = T('and');
 + my $or = T('or');
 + my @temp;
 + my @strings = split(/ +$and +/, $string);
 +
 + $wordsearch = &GetParam("wordsearch", "");
 + $casesearch = &GetParam("casesearch", "");
 + foreach $name (&AllPagesList()) {
 +   # assume found
 +   $found = 1;
 +   foreach my $str (@strings) {
 +     @temp = split(/ +$or +/, $str);
 +     $str = join('|', @temp);
 +     $str = $wordsearch ? "\\b$str\\b" : $str;
 +     if (!$casesearch) {
 +       if (not $name =~ /$str/i) {
 +         $found = 0;
 +         last;
 +       }
 +     }
 +     if ($casesearch) {
 +       if (not $name =~ /$str/) {
 +         $found = 0;
 +         last;
 +       }
 +     }
 +   }
 +   if (!$casesearch) {
 +     if ($found || $name =~ /@strings/i) {
 +       push(@found, $name);
 +     }
 +   }
 +   if ($casesearch) {
 +     if ($found || $name =~ /@strings/) {
 +       push(@found, $name);
 +     }
 +   }
 +   if ($string =~ m/_/) {
 +     $freeName = $string;
 +     $freeName =~ s/_/ /g;
 +     if (!$casesearch) {
 +       if ($name =~ /$freeName/i) {
 +         push(@found, $name);
 +       }
 +     }
 +     if ($casesearch) {
 +       if ($name =~ /$freeName/) {
 +         push(@found, $name);
 +       }
 +     }
 +   }
 + }
 + return @found;
 +}
--JuanmaMP

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited May 31, 2012 10:19 am by JuanmaMP (diff)
Search: