[Home]WikiPatches/BacklinksImproved

UseModWiki | WikiPatches | RecentChanges | Preferences

This patch improves backlink search. It --StefanTrcek

Patch for UseModWiki 1.0: added lines are bold:


 sub DoBackLinks {
  my ($string) = @_;

  print &GetHeader(, &QuoteHtml?(Ts('Backlinks for: %s', $string)), );
  print '<br>'; 
  # At this time the backlinks are mostly a renamed search. 
  # An initial attempt to match links only failed on subpages and free links.
  # Escape some possibly problematic characters:
  $string =~ s/([-'().,])/\\$1/g; 
  $string = "(?-i)$string";
  $string = "\\b$string\\b" if ($string !~ m,/,);
  &PrintPageList?(&SearchTitleAndBody($string));
  print &GetCommonFooter();
 }

One problem with the above patch is when pages are created with link names like "Abc whatcase". The page itself gets created with the name "Abc Whatcase", and the backlink search fails to match "whatcase" with "Whatcase".

I seem to have resolved this by only adding the second of the the two suggested lines.

-- cjbj


That's true - the first line misses too many pages. However there is a second problem when people are creative about mixing blanks and underscores in WikiWiki names. I fixed it by searching for both.

Additionally the word boundaries can be narrowed, so my current code is:

 $string =~ s/([_ ])/( |_)/g; 
 $string = ($string !~ m,/,) ? "\\b$string\\b" : "$string\\b";

-- StefanTrcek


This patch works great! I made one minor improvement: The output always lists the page itself you are getting backlinks for. A simple grep removed it. Just add this line near the top of the function DoBackLinks:

 my $title = $string; # keep an unmangled version
And replace the appropriate line with this:
 &PrintPageList?(grep($_ ne $title, &SearchTitleAndBody($string)));

While I was at it, I added a "what links here" link to the GotoBar... real simple, just add $BackGotoBar? into the "use vars" section, add this to the config vars:

 $BackGotoBar? = 1;               # 1 = backlink link in goto bar, 0 = none

And add this to GetGotoBar (wherever it pleases you, I added it after RecentChanges):

 $bartext .= " | " . &GetBackLinksSearchLink?($id, "What links here")
     if $BackGotoBar? and $id;

-- Trent


Small correction for Trent""s grep filter in order to filter out subpages showing up themselves in the backlinks list:

&PrintPageList( grep($_ !~ $title, &SearchTitleAndBody($string)));

-- Robert Kurcina --


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited October 1, 2007 11:04 am by MarkusLude (diff)
Search: