UseModWiki | WikiPatches | RecentChanges | Preferences

A Patch For Version 0.92

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));


  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";


    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

    # 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;

I am attempting to build a set of interlinked wikis on the subject of Hinduism. Each of the core books would be a wiki i.e. The Vedas, Upanisads, Vedanta-Sutras, Ramayana, Mahabharata etc. I've put some intial thoughts at eBook Wiki, I think this Dynamic Link approach would be great (Thanks to Alex Schroeder for pointing out MeatBall:GaGa and this). --ajiva_rts

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited May 1, 2009 11:10 pm by Juanmamp (diff)