The following code tries to suggest simple possible wiki word links, based on the pages and subpages currently in the wiki, as the user is browsing. Comments, code improvements, improvement suggestions are highly solicited
- ManpreetSingh
Change 1 In sub BrowsePage, replace
$fullHtml .= &WikiToHTML($Text{'text'}); $fullHtml .= "<hr>\n" if (!&GetParam('embed', $EmbedWiki));
with
if (!$showDiff && $revision eq '' && $id ne $RCName && T($RCName) ne $id && T($id) ne $RCName ) { $fullHtml .= suggestLinks($Text{'text'}); } else { $fullHtml .= &WikiToHTML($Text{'text'}); } $fullHtml .= "<hr>\n" if (!&GetParam('embed', $EmbedWiki));
Change 2 In sub DoEdit, replace
print &WikiToHTML($oldText) . "<hr>\n";
with
print suggestLinks($oldText) . "<hr>\n";
Change 3 Add the following sub in the file
sub suggestLinks { my $str = shift; my $bodyHtml = &WikiToHTML($str); # prevent links within html tags $bodyHtml =~ s/(<a[^>]*?href.*?\/a>)/&StoreRaw($1)/gsie; $bodyHtml =~ s/(<[^>]*?>)/&StoreRaw($1)/gse; # Get a list of simple words from existing wiki pages and subpages my @wordlist = grep { /^([A-Z][a-z]{2,})$/ } # Only 3 characters or more WikiWords split (/([A-Z][a-z]+)/, join ('', map { $_ =~ s[/][]; $_ } # Use SubPages too &AllPagesList())); # Remove duplicates for speed and create a pattern my %wordlist = (); @wordlist{@wordlist} = @wordlist; my $wordlist = '(?:' . join('|', keys %wordlist) . ')'; ## Modify the page being browsed # Links from the words we found in the wiki $bodyHtml =~ s/\b($wordlist[_-\s]+(?:$wordlist[_-\s]*)+)\b/<font color="red">$1<\/font>/gsi; # Any wiki word like multiple word combination (this maybe too much?) $bodyHtml =~ s/\b([A-Z][a-z]{2,}[_-\s]+(?:[A-Z][a-z]{2,}[_-\s]*)+)\b/<font color="red">$1<\/font>/gs; # restore HTML tags $bodyHtml =~ s/$FS(\d+)$FS/$SaveUrl{$1}/gse; return $bodyHtml; }