wikiheaders.pl: Make sure all wiki API pages reference CategoryAPI.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index d00631c..2dc02f0 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -854,30 +854,57 @@ if ($copy_direction == 1) { # --copy-to-headers
}
my $wikisectionorderref = $wikisectionorder{$fn};
- my @ordered_sections = (@standard_wiki_sections, defined $wikisectionorderref ? @$wikisectionorderref : ()); # this copies the arrays into one.
+ # Make sure there's a footer in the wiki that puts this function in CategoryAPI...
+ if (not $$sectionsref{'[footer]'}) {
+ $$sectionsref{'[footer]'} = '';
+ push @$wikisectionorderref, '[footer]';
+ }
+
+ # !!! FIXME: This won't be CategoryAPI if we eventually handle things other than functions.
+ my $footer = $$sectionsref{'[footer]'};
+ if ($wikitype eq 'mediawiki') {
+ $footer =~ s/\[\[CategoryAPI\]\],?\s*//g;
+ $footer = '[[CategoryAPI]]' . (($footer eq '') ? "\n" : ", $footer");
+ } elsif ($wikitype eq 'md') {
+ $footer =~ s/\[CategoryAPI\]\(CategoryAPI\),?\s*//g;
+ $footer = '[CategoryAPI](CategoryAPI)' . (($footer eq '') ? '' : ', ') . $footer;
+ } else { die("Unexpected wikitype '$wikitype'\n"); }
+ $$sectionsref{'[footer]'} = $footer;
+
+ my $prevsectstr = '';
+ my @ordered_sections = (@standard_wiki_sections, defined $wikisectionorderref ? @$wikisectionorderref : ()); # this copies the arrays into one.
foreach (@ordered_sections) {
my $sect = $_;
next if $sect eq '[start]';
next if (not defined $sections{$sect} and not defined $$sectionsref{$sect});
my $section = defined $sections{$sect} ? $sections{$sect} : $$sectionsref{$sect};
if ($sect eq '[footer]') {
+ # Make sure previous section ends with two newlines.
+ if (substr($prevsectstr, -1) ne "\n") {
+ print FH "\n\n";
+ } elsif (substr($prevsectstr, -2) ne "\n\n") {
+ print FH "\n";
+ }
print FH "----\n"; # It's the same in Markdown and MediaWiki.
} elsif ($sect eq '[Brief]') {
if ($wikitype eq 'mediawiki') {
print FH "= $fn =\n\n";
} elsif ($wikitype eq 'md') {
print FH "# $fn\n\n";
- } else { die("Expected wikitype '$wikitype'\n"); }
+ } else { die("Unexpected wikitype '$wikitype'\n"); }
} else {
if ($wikitype eq 'mediawiki') {
print FH "\n== $sect ==\n\n";
} elsif ($wikitype eq 'md') {
print FH "\n## $sect\n\n";
- } else { die("Expected wikitype '$wikitype'\n"); }
+ } else { die("Unexpected wikitype '$wikitype'\n"); }
}
- print FH defined $sections{$sect} ? $sections{$sect} : $$sectionsref{$sect};
+ my $sectstr = defined $sections{$sect} ? $sections{$sect} : $$sectionsref{$sect};
+ print FH $sectstr;
+
+ $prevsectstr = $sectstr;
# make sure these don't show up twice.
delete($sections{$sect});