UseModWiki | WikiPatches | RecentChanges | Preferences

Option to eliminate prefix slash before subpages

add a new variable to the config list:

use vars qw(@RcDays @HtmlPairs @HtmlSingle ... $SubSlashText ... );

add a new variable to the config:

$SubSlashText= 0; # 1 = allow \Sub 0 = only display Sub

and add an extra line to GetPageLinkText:

  sub GetPageLinkText {
    my ($id, $name) = @_;

    $id =~ s|^/|$MainPage/|;
    if ($FreeLinks) {
      $id = &FreeToNormal($id);
      $name =~ s/_/ /g;
    $name =~ s?^/??g if (!$SubSlashText);
    return &ScriptLink($id, $name);

I prefer a different delimiter (s? ??g instead of s/ //g) and have changed your code accordingly. It looks a lot tidier when there is a / inside the expression. It's easy to forget that Perl allows a huge choice of delimiters

Would this patch render /BatMan (a subpage of the current page) the same as BatMan (an independent page) ?


The way I read this is that the page-link would still be correct, pointing to the sub-page, but a sub-page of /BatMan will look the same as BatMan. It's just a personal taste thing really, and for my self, I prefer to leave the slash in-place. But if the slash is not to your taste, then you can either use the above code, or change the regex to something like:

    $name =~ s|^/|-> |g if (!$SubSlashText);

which would render "BatMan" as "-> BatMan"


The wiki I manage has a structure involving several major subpages; we almost always found ourselves writing [[Page/Subpage|Subpage]] for narrative flow. I modified this patch slightly to make that the default:

  sub GetPageLinkText {
    my ($id, $name) = @_;
    my $SubSlashText = $SubSlashText;

    if ($name eq "|") {
      $name = $id;
      $SubSlashText = 1;

    $id =~ s|^/|$MainPage/|;<nowiki>
    if <nowiki>($FreeLinks) {
      $id = &FreeToNormal($id);
      $name =~ s/_/ /g;
    $name =~ s?^.*/??g if (!$SubSlashText);
    return &ScriptLinkClass($id, $name, 'wikipagelink');

"[[Page/Subpage]]" is now rendered as "Subpage". And [[Page/Subpage||]] is rendered as "Page/Subpage?".

This made the recent changes hard to read; thus:

  sub DoRc {
    $SubSlashText = 1;   # we always want to have the whole path in recents

    my (<nowik>i$rcType</nowiki>) = @_;   # 0 = RSS, 1 = HTML
    my ($fileData, $rcline, $i, $daysago, $lastTs, $ts, $idOnly);

...will retain the full Page/Subpage link in the recent changes page.

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited August 23, 2005 12:18 am by 65-103-201-204.phnx.qwest.net (diff)