[Home]WikiPatches/EmbeddedSubpageList

UseModWiki | WikiPatches | RecentChanges | Preferences

Embedded Subpage List

Description

Similar to /EmbeddedBacklinks, this patch adds a new tag to the wiki markup. The new tag, <subpage> lists all the subpages belonging to the current page. It can also be used as <subpage OtherPage> to list the subpages of a specific other page.

The Patch

--- wiki.pl     2003-09-11 14:21:02.000000000 +0200
+++ SubpageList.pl      2006-03-01 07:47:21.831646640 +0100
@@ -1572,6 +1572,8 @@
   }
   $pageText = &QuoteHtml($pageText);
   $pageText =~ s/\\ *\r?\n/ /g;          # Join lines with backslash at end
+  $pageText =~ s/&lt;subpages&gt;/&StoreRaw("<h2>" . Ts('Subpages of: %s', $MainPage) . "<\/h2>\n" . &GetPageList(&GetSubpages($MainPage)))/ige;
+  $pageText =~ s/&lt;subpages\s+(.*?)&gt;/&StoreRaw("<h2>" . Ts('Subpages of: %s', &QuoteHtml($1)) . "<\/h2>\n" . &GetPageList(&GetSubpages($1)))/ige;
   if ($ParseParas) {
     # Note: The following 3 rules may span paragraphs, so they are
     #       copied from CommonMarkup
@@ -3736,6 +3738,23 @@
   print &GetCommonFooter();
 }

+sub GetSubpages {
+  my ($parentPage) = @_;
+  my ($dir, @subpageFiles, @pages, $subId);
+
+  return '' unless $parentPage;
+  $dir = GetPageDirectory($parentPage);
+  opendir(PAGELIST, "$PageDir/$dir/$parentPage") or return '';
+  @subpageFiles = readdir(PAGELIST);
+  closedir(PAGELIST);
+  foreach $subId (@subpageFiles) {
+    if (substr($subId, -3) eq '.db') {
+      push(@pages, "$parentPage/" . substr($subId, 0, -3));
+    }
+  }
+  return @pages;
+}
+
 sub PrintPageList {
   my $pagename;


Notes


-- UngarPeter

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited March 1, 2006 7:40 am by UngarPeter (diff)
Search: