From: Simon McVittie <smcv@debian.org>
Date: Sun, 14 Sep 2014 14:15:27 +0000 (+0100)
Subject: Rename show parameter of [[!inline]] and [[!pagestats]] to limit
X-Git-Tag: 3.20160121~48^2
X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/ab768a62c66335a96a5791c444e54b8ae3b078b1?ds=inline

Rename show parameter of [[!inline]] and [[!pagestats]] to limit

The old name still works, if its value is numeric.

This name allows a non-numeric "show" to mean the same thing
it does for [[!map]] (show title, show description, etc.).
---

diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index f578526cc..b122bd0f2 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -180,11 +180,22 @@ sub preprocess_inline (@) {
 	my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick && ! $raw;
 	my $emptyfeeds=exists $params{emptyfeeds} ? yesno($params{emptyfeeds}) : 1;
 	my $feedonly=yesno($params{feedonly});
-	if (! exists $params{show} && ! $archive) {
-		$params{show}=10;
+
+	# Backwards compatibility
+	if (defined $params{show} && $params{show} =~ m/^\d+$/) {
+		$params{limit} = $params{show};
+		delete $params{show};
+	}
+	if (defined $params{feedshow} && $params{feedshow} =~ m/^\d+$/) {
+		$params{feedlimit} = $params{feedshow};
+		delete $params{feedshow};
+	}
+
+	if (! exists $params{limit} && ! $archive) {
+		$params{limit}=10;
 	}
-	if (! exists $params{feedshow} && exists $params{show}) {
-		$params{feedshow}=$params{show};
+	if (! exists $params{feedlimit} && exists $params{limit}) {
+		$params{feedlimit}=$params{limit};
 	}
 	my $title;
 	if (exists $params{title}) {
@@ -232,11 +243,11 @@ sub preprocess_inline (@) {
 	}
 	else {
 		my $num=0;
-		if ($params{show}) {
-			$num=$params{show};
+		if ($params{limit}) {
+			$num=$params{limit};
 		}
-		if ($params{feedshow} && $num < $params{feedshow} && $num > 0) {
-			$num=$params{feedshow};
+		if ($params{feedlimit} && $num < $params{feedlimit} && $num > 0) {
+			$num=$params{feedlimit};
 		}
 		if ($params{skip} && $num) {
 			$num+=$params{skip};
@@ -257,17 +268,17 @@ sub preprocess_inline (@) {
 	
 	my @feedlist;
 	if ($feeds) {
-		if (exists $params{feedshow} &&
-		    $params{feedshow} && @list > $params{feedshow}) {
-			@feedlist=@list[0..$params{feedshow} - 1];
+		if (exists $params{feedlimit} &&
+		    $params{feedlimit} && @list > $params{feedlimit}) {
+			@feedlist=@list[0..$params{feedlimit} - 1];
 		}
 		else {
 			@feedlist=@list;
 		}
 	}
 	
-	if ($params{show} && @list > $params{show}) {
-		@list=@list[0..$params{show} - 1];
+	if ($params{limit} && @list > $params{limit}) {
+		@list=@list[0..$params{limit} - 1];
 	}
 
 	if ($feeds && exists $params{feedpages}) {
diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm
index 17b26f7ba..460a5969a 100644
--- a/IkiWiki/Plugin/pagestats.pm
+++ b/IkiWiki/Plugin/pagestats.pm
@@ -35,7 +35,13 @@ sub preprocess (@) {
 	my %params=@_;
 	$params{pages}="*" unless defined $params{pages};
 	my $style = ($params{style} or 'cloud');
-	
+
+	# Backwards compatibility
+	if (defined $params{show} && $params{show} =~ m/^\d+$/) {
+		$params{limit} = $params{show};
+		delete $params{show};
+	}
+
 	my %counts;
 	my $max = 0;
 	foreach my $page (pagespec_match_list($params{page}, $params{pages},
@@ -64,11 +70,11 @@ sub preprocess (@) {
 		$max = $counts{$page} if $counts{$page} > $max;
 	}
 
-	if (exists $params{show}) {
+	if (exists $params{limit}) {
 		my $i=0;
 		my %show;
 		foreach my $key (sort { $counts{$b} <=> $counts{$a} } keys %counts) {
-			last if ++$i > $params{show};
+			last if ++$i > $params{limit};
 			$show{$key}=$counts{$key};
 		}
 		%counts=%show;
diff --git a/doc/ikiwiki/directive/inline.mdwn b/doc/ikiwiki/directive/inline.mdwn
index a4632a5b4..dfe3e171f 100644
--- a/doc/ikiwiki/directive/inline.mdwn
+++ b/doc/ikiwiki/directive/inline.mdwn
@@ -5,7 +5,7 @@ The most common use of inlining is generating blogs and RSS or Atom feeds.
 
 Example:
 
-	\[[!inline pages="blog/* and !*/Discussion" show="10" rootpage="blog"]]
+	\[[!inline pages="blog/* and !*/Discussion" limit="10" rootpage="blog"]]
 
 Any pages that match the specified [[PageSpec]] (in the example, any
 [[SubPage]] of "blog") will be part of the blog, and the newest 10
@@ -46,9 +46,11 @@ There are many parameters you can use with the `inline`
 directive. These are the commonly used ones:
 
 * `pages` - A [[PageSpec]] of the pages to inline.
-* `show` - Specify the maximum number of matching pages to inline.
+* `limit` - Specify the maximum number of matching pages to inline.
   Default is 10, unless archiving, when the default is to show all.
   Set to 0 to show all matching pages.
+  In older versions of IkiWiki this parameter was called `show`, which
+  also still works.
 * `archive` - If set to "yes", only list page titles and some metadata, not
   full contents.
 * `title` - Sets the title of the rss feed if one is generated.
@@ -96,8 +98,10 @@ Here are some less often needed parameters:
 * `sort` - Controls how inlined pages are [[sorted|pagespec/sorting]].
   The default is to sort the newest created pages first.
 * `reverse` - If set to "yes", causes the sort order to be reversed.
-* `feedshow` - Specify the maximum number of matching pages to include in
-  the rss/atom feeds. The default is the same as the `show` value above.
+* `feedlimit` - Specify the maximum number of matching pages to include in
+  the rss/atom feeds. The default is the same as the `limit` value above.
+  In older versions of IkiWiki this parameter was called `feedshow`, which
+  also still works.
 * `feedonly` - Only generate the feed, do not display the pages inline on
   the page.
 * `quick` - Build archives in quick mode, without reading page contents for
@@ -124,7 +128,7 @@ Here are some less often needed parameters:
 * `trail` - If set to "yes" and the [[!iki plugins/trail desc=trail]] plugin
   is enabled, turn the inlined pages into a trail with next/previous links,
   by passing the same options to [[ikiwiki/directive/trailitems]]. The `skip`
-  and `show` options are ignored by the trail, so the next/previous links
+  and `limit` options are ignored by the trail, so the next/previous links
   traverse through all matching pages.
 
 [[!meta robots="noindex, follow"]]
diff --git a/doc/ikiwiki/directive/pagestats.mdwn b/doc/ikiwiki/directive/pagestats.mdwn
index 8d904f5a3..8d2be0946 100644
--- a/doc/ikiwiki/directive/pagestats.mdwn
+++ b/doc/ikiwiki/directive/pagestats.mdwn
@@ -28,11 +28,14 @@ Or to display a cloud of tags related to Linux, you could use:
 
 	\[[!pagestats pages="tags/* and !tags/linux" among="tagged(linux)"]]
 
-The optional `show` parameter limits display to the specified number of
+The optional `limit` parameter limits display to the specified number of
 pages. For instance, to show a table of the top ten pages with the most
 links:
 
-	\[[!pagestats style="table" show="10"]]
+	\[[!pagestats style="table" limit="10"]]
+
+In older versions of IkiWiki this parameter was called `show`;
+that name still works, if its value is numeric.
 
 The optional `class` parameter can be used to control the class
 of the generated tag cloud `div` or page stats `table`.
diff --git a/t/inline.t b/t/inline.t
index 726227b8f..d1ec9a6d6 100755
--- a/t/inline.t
+++ b/t/inline.t
@@ -20,9 +20,10 @@ sub write_old_file {
 write_old_file("protagonists.mdwn",
 	'[[!inline pages="protagonists/*" rootpage="protagonists/new"]]');
 write_old_file("friends.mdwn",
-	'[[!inline pages="friends/*" postform=yes sort=title show=2]]');
+	'[[!inline pages="friends/*" postform=yes sort=title limit=2]]');
 write_old_file("antagonists.mdwn",
 	'[[!inline pages="antagonists/*"]]');
+# using old spelling of "limit" ("show") to verify backwards compat
 write_old_file("enemies.mdwn",
 	'[[!inline pages="enemies/*" postform=no rootpage=enemies sort=title reverse=yes show=2]]');
 foreach my $page (qw(protagonists/shepard protagonists/link
@@ -53,7 +54,7 @@ like($blob, qr{<input type="hidden" name="from" value="friends"},
 like($blob, qr[this page is {friends/garrus}.*this page is {friends/liara}]s,
 	'first two pages in desired sort order are present');
 unlike($blob, qr{friends/(?:midna|telma)},
-	'pages excluded by show should not be present');
+	'pages excluded by limit should not be present');
 
 $blob = readfile("t/tmp/out/antagonists.html");
 unlike($blob, qr{Add a new post}, 'default is no postform');