-- jl
--- wiki.pl Sun Apr 22 02:44:10 2001
+++ wiki_patched_like.pl Fri Jan 10 19:13:07 2003
@@ -52,7 +52,8 @@
%KeptRevisions %UserCookie %SetCookie %UserData %IndexHash %Translate
%LinkIndex $InterSiteInit $SaveUrlIndex $SaveNumUrlIndex $MainPage
$OpenPageName @KeptList @IndexList $IndexInit
- $q $Now $UserID $TimeZoneOffset $ScriptName $BrowseCode $OtherCode);
+ $q $Now $UserID $TimeZoneOffset $ScriptName $BrowseCode $OtherCode
+ $EnableShowLike);
# == Configuration =====================================================
$DataDir = "/tmp/mywikidb"; # Main wiki directory
@@ -84,6 +85,7 @@
$NewText = ""; # New page text ("" for default message)
$HttpCharset = ""; # Charset for pages, like "iso-8859-2"
$UserGotoBar = ""; # HTML added to end of goto bar
+$EnableShowLike = 1; # Enable like link
# Major options:
$UseSubpage = 1; # 1 = use subpages, 0 = do not use subpages
@@ -877,6 +879,11 @@
return &ScriptLink("action=random", T('Random Page'));
}
+sub GetLikeLink {
+ my $id = shift;
+ return &ScriptLink("action=showlike;id=$id", T("Like $id"), 'showlike');
+}
+
sub ScriptLinkDiff {
my ($diff, $id, $text, $rev) = @_;
@@ -1095,6 +1102,9 @@
}
$bartext .= " | " . &GetPageLink($RCName);
$bartext .= " | " . &GetPrefsLink();
+ if ($EnableShowLike){
+ $bartext .= " | " . &GetLikeLink($id||$HomePage);
+ }
if (&GetParam("linkrandom", 0)) {
$bartext .= " | " . &GetRandomLink();
}
@@ -2475,6 +2485,8 @@
&DoEditPrefs(); # Also creates new ID
} elsif ($action eq "version") {
&DoShowVersion();
+ } elsif ($action eq "showlike" && $EnableShowLike){
+ &DoShowLike($id);
} else {
# Later improve error reporting
&ReportError(Ts('Invalid action parameter %s', $action));
@@ -2906,6 +2918,15 @@
# Later consider returning status?
}
+sub DoShowLike {
+ my $id = shift;
+
+ print &GetHeader('', T("Like $id"));
+ &PrintLikeLinks($id);
+ print &GetCommonFooter();
+}
+
+
sub DoIndex {
print &GetHeader('', T('Index of all pages'), '');
print '<br>';
@@ -3046,6 +3067,37 @@
print &GetPageLink($pagename), "<br>\n";
}
}
+
+
+sub PrintLikeLinks {
+ my $id = shift;
+ return "" unless $id =~ m/^([A-Z]+[^A-Z]+)(?:[A-Z]+[^A-Z]+)*([A-Z]+.*)$/;
+ my ($prefix, $suffix) = ($1,$2);
+ my (%prefixList, %suffixList);
+ my %allHits;
+
+ for(map { m:([^/]+)/(.+)$: ? ($1,$2) : $_ } &AllPagesList()){
+ next if $_ eq $id;
+ if (m/^([A-Z]+[^A-Z]+)(?:[A-Z]+[^A-Z]+)*([A-Z]+.*)$/) {
+ if($prefix eq $1){
+ $prefixList{$_} = 1;
+ } elsif($suffix eq $2){
+ $suffixList{$_} = 1;
+ }
+ }
+ }
+
+ print "<h2>Words starting with $prefix</h2>\n";
+ print "<ul>\n";
+ print " <li>" . &GetPageLink($_) . "</li>\n" for(keys %prefixList);
+ print "</ul>\n";
+ print "<h2>Words ending with $suffix</h2>\n";
+ print "<ul>\n";
+ print " <li>" . &GetPageLink($_) . "</li>\n" for(keys %suffixList);
+ print "</ul>\n";
+}
+
+
sub DoLinks {
print &GetHeader('', &QuoteHtml(T('Full Link List')), '');
The modification is done only in two regular expressions in the subroutine PrintLikeLinks?; you must search the two occurences of this regular expression:
m/^([A-Z]+[^A-Z]+)(?:[A-Z]+[^A-Z]+)*([A-Z]+.*)$/
and replace them with the following regular expression:
m/^([A-Z]+[^A-Z_]+)(?:[A-Z_]+[^A-Z]+)*_*([A-Z]+.*)$/
-- FerdinandPrantl
Find this line in the patch:
my ($prefix, $suffix) = ($1,$2);and insert the following lines after it:
$_ = $id;
s/_//g;
my @words = split /(?=[A-Z])/;
for (my $i = $#words; $i > 0; $i--) {
if ($words[$i] =~ /^[A-Z]+$/ && $words[$i - 1] =~ /^[A-Z]+$/) {
$words[$i - 1] .= $words[$i];
pop @words;
}
}
Replace this loop in the patch:
for(map { m:([^/]+)/(.+)$: ? ($1,$2) : $_ } &AllPagesList()){
next if $_ eq $id;
if (m/^([A-Z]+[^A-Z]+)(?:[A-Z]+[^A-Z]+)*([A-Z]+.*)$/) {
if($prefix eq $1){
$prefixList{$_} = 1;
} elsif($suffix eq $2){
$suffixList{$_} = 1;
}
}
}
with the following one (the underscore patch for regex from above is applied too):
for (map { /([^\/]+)\/(.+)$/ ? ($1,$2) : $_ } &AllPagesList()) {
next if $_ eq $id;
if (/^([A-Z]+[^A-Z_]+)([A-Z_]+[^A-Z]+)*_*([A-Z]+.*)$/) {
if ($prefix eq $1) {
$prefixList{$_} = 1;
} elsif ($suffix eq $3) {
$suffixList{$_} = 1;
}
}
if ($#words >= 0) {
my $original = $_;
s/_//g;
my $modified = $_;
$allHits{$original} = 1 if (grep { $modified =~ /$_/ } @words);
}
}
Replace the rest of the subroutine:
print "<ul>\n"; print " <li>" . &GetPageLink($_) . "</li>\n" for(keys %prefixList); print "</ul>\n"; print "<h2>Words ending with $suffix</h2>\n"; print "<ul>\n"; print " <li>" . &GetPageLink($_) . "</li>\n" for(keys %suffixList); print "</ul>\n";with the following code:
print "<h2>Words starting with $prefix</h2>\n"; print &GetPageLink($_), "<br>\n" for(keys %prefixList); print "<h2>Words ending with $suffix</h2>\n"; print &GetPageLink($_), "<br>\n" for(keys %suffixList); print "<h2>Words containing part of $id</h2>\n"; print &GetPageLink($_), "<br>\n" for(keys %allHits);
The latest change also prints the links found on a separated lines without bullets, just like the results of a search.
-- FerdinandPrantl
Cool! If you have a UnifiedDiff? to usemod-0.92 at hand, please substitute my patch with yours :) -- jl
Example, it found:
(Tester isn`t an item of CamelCase.)
if ($prefix eq $1) {
$prefixList{$_} = 1;
- } elsif ($suffix eq $3) {
+ }
+ if ($suffix eq $3) {
$suffixList{$_} = 1;
}
--JuanmaMP