From 65d57902ca9f05b7958ea0a47b3fa3c651da89f5 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 18:17:36 -0400 Subject: add sorting page --- doc/ikiwiki/pagespec/sorting.mdwn | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 doc/ikiwiki/pagespec/sorting.mdwn (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn new file mode 100644 index 000000000..1e0366029 --- /dev/null +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -0,0 +1,11 @@ +Some [[directives|ikiwiki/directive]] that use +[[PageSpecs|ikiwiki/pagespec]], such as [[ikiwiki/directive/inline]], allow +specifying the order that matching pages are shown in. The following sort +orders can be specified. + +* `age` - List pages from the most recently created to the oldest. +* `mtime` - List pages with the most recently modified first. +* `title` - Order by title. +* `title_natural` - Only available if [[!cpan Sort::Naturally]] is + installed. Orders by title, but numbers in the title are treated + as such, ("1 2 9 10 20" instead of "1 10 2 20 9") -- cgit v1.2.3 From fb3fd6b60fb584d8c1c0f76253d53633127afb18 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 00:06:08 -0400 Subject: don't link to inline, not available when directives underlay is not enabled --- doc/ikiwiki/pagespec/sorting.mdwn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index 1e0366029..41aa58151 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -1,5 +1,5 @@ Some [[directives|ikiwiki/directive]] that use -[[PageSpecs|ikiwiki/pagespec]], such as [[ikiwiki/directive/inline]], allow +[[PageSpecs|ikiwiki/pagespec]] allow specifying the order that matching pages are shown in. The following sort orders can be specified. -- cgit v1.2.3 From 5704255b8f65ebbf9d0d20926744f039816e7ca5 Mon Sep 17 00:00:00 2001 From: JeremyReed Date: Thu, 12 Nov 2009 10:16:44 -0500 Subject: ask question --- doc/ikiwiki/pagespec/attachment/discussion.mdwn | 2 ++ 1 file changed, 2 insertions(+) (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/pagespec/attachment/discussion.mdwn b/doc/ikiwiki/pagespec/attachment/discussion.mdwn index 373242b3f..abfb62edc 100644 --- a/doc/ikiwiki/pagespec/attachment/discussion.mdwn +++ b/doc/ikiwiki/pagespec/attachment/discussion.mdwn @@ -13,3 +13,5 @@ I am interested for [[todo/mbox]] --[[DavidBremner]] >> them. --[[DavidBremner]] >>> Done, [[plugins/filecheck]] --[[Joey]] + +Anyway to make it so an edit page doesn't offer the attachment capability unless it matches a specific user, is an admin, and/or is an allowed page? (For now, I have it on all pages, and then it prohibits after I submit based on the allowed_attachments.) -- cgit v1.2.3 From b9f264d066bd71e5a995f339fcf25181539c9b8f Mon Sep 17 00:00:00 2001 From: JeremyReed Date: Thu, 12 Nov 2009 10:23:58 -0500 Subject: fix typo --- doc/ikiwiki/pagespec/attachment/discussion.mdwn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/pagespec/attachment/discussion.mdwn b/doc/ikiwiki/pagespec/attachment/discussion.mdwn index abfb62edc..34f21f84a 100644 --- a/doc/ikiwiki/pagespec/attachment/discussion.mdwn +++ b/doc/ikiwiki/pagespec/attachment/discussion.mdwn @@ -14,4 +14,5 @@ I am interested for [[todo/mbox]] --[[DavidBremner]] >>> Done, [[plugins/filecheck]] --[[Joey]] -Anyway to make it so an edit page doesn't offer the attachment capability unless it matches a specific user, is an admin, and/or is an allowed page? (For now, I have it on all pages, and then it prohibits after I submit based on the allowed_attachments.) + +Any way to make it so an edit page doesn't offer the attachment capability unless it matches a specific user, is an admin, and/or is an allowed page? (For now, I have it on all pages, and then it prohibits after I submit based on the allowed_attachments.) -- cgit v1.2.3 From 2bd6ebb42ce3e7a91866f6731563926b09e7806f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 13 Nov 2009 15:31:34 -0500 Subject: move to todo item, some thoughtS --- doc/ikiwiki/pagespec/attachment/discussion.mdwn | 3 --- ...avoid_attachement_ui_if_upload_not_allowed.mdwn | 25 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 doc/todo/avoid_attachement_ui_if_upload_not_allowed.mdwn (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/pagespec/attachment/discussion.mdwn b/doc/ikiwiki/pagespec/attachment/discussion.mdwn index 34f21f84a..373242b3f 100644 --- a/doc/ikiwiki/pagespec/attachment/discussion.mdwn +++ b/doc/ikiwiki/pagespec/attachment/discussion.mdwn @@ -13,6 +13,3 @@ I am interested for [[todo/mbox]] --[[DavidBremner]] >> them. --[[DavidBremner]] >>> Done, [[plugins/filecheck]] --[[Joey]] - - -Any way to make it so an edit page doesn't offer the attachment capability unless it matches a specific user, is an admin, and/or is an allowed page? (For now, I have it on all pages, and then it prohibits after I submit based on the allowed_attachments.) diff --git a/doc/todo/avoid_attachement_ui_if_upload_not_allowed.mdwn b/doc/todo/avoid_attachement_ui_if_upload_not_allowed.mdwn new file mode 100644 index 000000000..487915850 --- /dev/null +++ b/doc/todo/avoid_attachement_ui_if_upload_not_allowed.mdwn @@ -0,0 +1,25 @@ +Any way to make it so an edit page doesn't offer the attachment capability +unless it matches a specific user, is an admin, and/or is an allowed page? +(For now, I have it on all pages, and then it prohibits after I submit +based on the allowed_attachments.) + +> To do that, ikiwiki would have to try to match the `allowed_attachments` +> pagespec against a sort of dummy upload to the current page. Then if it +> failed, assume all real uploads would fail. Now consider a pagespec like +> "user(joey) and mimetype(audio/mpeg)" -- it'd be hard to make a dummy +> upload to test this pagespec against. +> +> So, there would need to be some sort of test mode, where terms like +> `mimetype()` always succeed. But then consider a pagespec like +> "user(joey) and !mimetype(video/mpeg)" -- if mimetype succeeds, this +> fails. +> +> So, maybe we can instead just filter out all the pagespec terms aside +> from `user()`, `ip()`, and `admin()`. Transforming that into just +> "user(joey)", which would succeed in the test. +> +> That'd work, I guess. Pulling a pagespec apart, filtering out terms, and +> putting it back together is nontrivial, but doable. +> +> Other approach would be to have a separate pagespec that explicitly +> controlls what pages to show the attachment UI on. --[[Joey]] -- cgit v1.2.3 From 03810ebf4003a5c1cb8c8a247f0e2b429923a675 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 6 Feb 2010 16:29:04 -0500 Subject: add noindex robots directives --- doc/ikiwiki/directive/date.mdwn | 2 ++ doc/ikiwiki/pagespec/po.mdwn | 2 ++ doc/ikiwiki/pagespec/sorting.mdwn | 2 ++ 3 files changed, 6 insertions(+) (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/directive/date.mdwn b/doc/ikiwiki/directive/date.mdwn index df45fa840..b89241e4c 100644 --- a/doc/ikiwiki/directive/date.mdwn +++ b/doc/ikiwiki/directive/date.mdwn @@ -12,3 +12,5 @@ For example, an update to a page with an embedded date stamp could look like: Updated \[[!date "Wed, 25 Nov 2009 01:11:55 -0500"]]: mumble mumble + +[[!meta robots="noindex, follow"]] diff --git a/doc/ikiwiki/pagespec/po.mdwn b/doc/ikiwiki/pagespec/po.mdwn index e0264dd50..40ed9efb6 100644 --- a/doc/ikiwiki/pagespec/po.mdwn +++ b/doc/ikiwiki/pagespec/po.mdwn @@ -14,3 +14,5 @@ wiki: Note that every non-po page is considered to be written in `po_master_language`, as specified in `ikiwiki.setup`. + +[[!meta robots="noindex, follow"]] diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index 41aa58151..697818a2a 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -9,3 +9,5 @@ orders can be specified. * `title_natural` - Only available if [[!cpan Sort::Naturally]] is installed. Orders by title, but numbers in the title are treated as such, ("1 2 9 10 20" instead of "1 10 2 20 9") + +[[!meta robots="noindex, follow"]] -- cgit v1.2.3 From e67a9382f67e745af3be7d367fe7a0d36c1777e6 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 24 Mar 2010 00:29:10 +0000 Subject: Allow hooks to add sorting functions to pagespec_match_list --- IkiWiki.pm | 6 +++++- doc/ikiwiki/pagespec/sorting.mdwn | 2 ++ doc/plugins/write.mdwn | 15 +++++++++++++++ t/pagespec_match_list.t | 6 +++++- 4 files changed, 27 insertions(+), 2 deletions(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/IkiWiki.pm b/IkiWiki.pm index 022bfe3bd..1a4dc47dd 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -2035,7 +2035,11 @@ sub pagespec_match_list ($$;@) { if (defined $params{sort}) { my $f; - if ($params{sort} eq 'title') { + + if (exists $hooks{sort}{$params{sort}}{call}) { + $f = sub { $hooks{sort}{$params{sort}}{call}($a, $b) }; + } + elsif ($params{sort} eq 'title') { $f=sub { pagetitle(basename($a)) cmp pagetitle(basename($b)) }; } elsif ($params{sort} eq 'title_natural') { diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index 697818a2a..9007c23bf 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -10,4 +10,6 @@ orders can be specified. installed. Orders by title, but numbers in the title are treated as such, ("1 2 9 10 20" instead of "1 10 2 20 9") +Plugins can add additional sort orders. + [[!meta robots="noindex, follow"]] diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 96a2aa16d..bfa6617bd 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -588,6 +588,21 @@ describes the plugin as a whole. For example: This hook is used to inject C code (which it returns) into the `main` function of the ikiwiki wrapper when it is being generated. +### sort + + hook(type => "sort", id => "foo", call => \&sort_by_foo); + +This hook adds an additional [[ikiwiki/pagespec/sorting]] order or overrides +an existing one. The callback is given two page names as arguments, and +returns negative, zero or positive if the first page should come before, +close to (i.e. undefined order), or after the second page. + +For instance, the built-in `title` sort order could be reimplemented as + + sub sort_by_title { + pagetitle(basename($_[0])) cmp pagetitle(basename($_[1])); + } + ## Exported variables Several variables are exported to your plugin when you `use IkiWiki;` diff --git a/t/pagespec_match_list.t b/t/pagespec_match_list.t index dd5dcc5b0..b34ee769f 100755 --- a/t/pagespec_match_list.t +++ b/t/pagespec_match_list.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 88; +use Test::More tests => 89; BEGIN { use_ok("IkiWiki"); } @@ -9,6 +9,8 @@ BEGIN { use_ok("IkiWiki"); } $config{srcdir}=$config{destdir}="/dev/null"; IkiWiki::checkconfig(); +hook(type => "sort", id => "path", call => sub { $_[0] cmp $_[1] }); + %pagesources=( foo => "foo.mdwn", foo2 => "foo2.mdwn", @@ -34,6 +36,8 @@ is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 50)], is_deeply([pagespec_match_list("foo", "post/*", sort => "title", filter => sub { $_[0] =~ /3/}) ], ["post/1", "post/2"]); +is_deeply([pagespec_match_list("foo", "*", sort => "path", num => 2)], + ["bar", "foo"]); my $r=eval { pagespec_match_list("foo", "beep") }; ok(eval { pagespec_match_list("foo", "beep") } == 0); ok(! $@, "does not fail with error when unable to match anything"); -- cgit v1.2.3 From 0618f099dab8bd4f7f47e2695db01eabe49e3316 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 24 Mar 2010 00:59:01 +0000 Subject: Have the meta plugin add a meta_title sort order --- IkiWiki/Plugin/meta.pm | 15 +++++++++++++++ doc/ikiwiki/pagespec/sorting.mdwn | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 5f046cb2a..bf8159814 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -13,6 +13,7 @@ sub import { hook(type => "needsbuild", id => "meta", call => \&needsbuild); hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1); hook(type => "pagetemplate", id => "meta", call => \&pagetemplate); + hook(type => "sort", id => "meta_title", call => \&sort_meta_title); } sub getsetup () { @@ -282,6 +283,20 @@ sub pagetemplate (@) { } } +sub title { + my $title = $pagestate{$_[0]}{meta}{title}; + + if (defined $title) { + return $title; + } + + return pagetitle(IkiWiki::basename($_[0])); +} + +sub sort_meta_title { + return title($_[0]) cmp title($_[1]); +} + sub match { my $field=shift; my $page=shift; diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index 9007c23bf..3a9fef9b6 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -9,7 +9,12 @@ orders can be specified. * `title_natural` - Only available if [[!cpan Sort::Naturally]] is installed. Orders by title, but numbers in the title are treated as such, ("1 2 9 10 20" instead of "1 10 2 20 9") +[[!if test="enabled(meta)" then=""" +* `meta_title` - Order by the full title set by the `\[[!meta title="foo"]]` + [[ikiwiki/directive]]. +"""]] -Plugins can add additional sort orders. +Plugins can add additional sort orders, so more might be available on this +wiki. [[!meta robots="noindex, follow"]] -- cgit v1.2.3 From b0ae19872d443860aeaab7069255e3a68a520887 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 24 Mar 2010 03:18:24 +0000 Subject: Add an optional "sort" argument to meta titles, defaulting to the title This allows correct sorting of titles, names, etc., with: [[!meta title="David Bowie" sort="Bowie, David"]] [[!meta title="The Beatles" sort="Beatles, The"]] --- IkiWiki/Plugin/meta.pm | 16 +++++++++++----- doc/ikiwiki/directive/meta.mdwn | 7 +++++++ doc/ikiwiki/pagespec/sorting.mdwn | 7 ++++--- 3 files changed, 22 insertions(+), 8 deletions(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index bf8159814..a470041c9 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -90,6 +90,12 @@ sub preprocess (@) { # Metadata collection that needs to happen during the scan pass. if ($key eq 'title') { $pagestate{$page}{meta}{title}=HTML::Entities::encode_numeric($value); + if (exists $params{sort}) { + $pagestate{$page}{meta}{titlesort}=$params{sort}; + } + else { + $pagestate{$page}{meta}{titlesort}=$value; + } return ""; } elsif ($key eq 'description') { @@ -283,18 +289,18 @@ sub pagetemplate (@) { } } -sub title { - my $title = $pagestate{$_[0]}{meta}{title}; +sub titlesort { + my $key = $pagestate{$_[0]}{meta}{titlesort}; - if (defined $title) { - return $title; + if (defined $key) { + return $key; } return pagetitle(IkiWiki::basename($_[0])); } sub sort_meta_title { - return title($_[0]) cmp title($_[1]); + return titlesort($_[0]) cmp titlesort($_[1]); } sub match { diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn index 557441c0b..8d2a5b1ad 100644 --- a/doc/ikiwiki/directive/meta.mdwn +++ b/doc/ikiwiki/directive/meta.mdwn @@ -23,6 +23,13 @@ Supported fields: be set to a true value in the template; this can be used to format things differently in this case. + An optional `sort` parameter will be used preferentially when + [[ikiwiki/pagespec/sorting]] by `meta_title`: + + \[[!meta title="The Beatles" sort="Beatles, The"]] + + \[[!meta title="David Bowie" sort="Bowie, David"]] + * license Specifies a license for the page, for example, "GPL". Can contain diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index 3a9fef9b6..61516bec5 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -5,13 +5,14 @@ orders can be specified. * `age` - List pages from the most recently created to the oldest. * `mtime` - List pages with the most recently modified first. -* `title` - Order by title. +* `title` - Order by title (page name). * `title_natural` - Only available if [[!cpan Sort::Naturally]] is installed. Orders by title, but numbers in the title are treated as such, ("1 2 9 10 20" instead of "1 10 2 20 9") [[!if test="enabled(meta)" then=""" -* `meta_title` - Order by the full title set by the `\[[!meta title="foo"]]` - [[ikiwiki/directive]]. +* `meta_title` - Order according to the `\[[!meta title="foo" sort="bar"]]` + or `\[[!meta title="foo"]]` [[ikiwiki/directive]], or the page name if no + full title was set. """]] Plugins can add additional sort orders, so more might be available on this -- cgit v1.2.3 From 60edd2dc3157f756f4f7a213ee15836fe7bbb769 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 24 Mar 2010 23:51:48 +0000 Subject: Allow sorting to be combined and/or reversed --- IkiWiki.pm | 84 ++++++++++++++++++++++++++++----------- doc/ikiwiki/pagespec/sorting.mdwn | 4 ++ doc/plugins/write.mdwn | 17 +++++++- t/pagespec_match_list.t | 12 +++++- 4 files changed, 91 insertions(+), 26 deletions(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/IkiWiki.pm b/IkiWiki.pm index 1a4dc47dd..ce8fdd454 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -2005,6 +2005,64 @@ sub pagespec_match ($$;@) { return $sub->($page, @params); } +sub get_sort_function { + my $method = $_[0]; + + if ($method =~ m/\s/) { + my @methods = map { get_sort_function($_) } split(' ', $method); + + return sub { + foreach my $method (@methods) { + my $answer = $method->($_[0], $_[1]); + return $answer if $answer; + } + + return 0; + }; + } + + my $sense = 1; + + if ($method =~ s/^-//) { + $sense = -1; + } + + my $token = $method; + my $parameter = undef; + + if ($method =~ m/^(\w+)\((.*)\)$/) { + $token = $1; + $parameter = $2; + } + + if (exists $hooks{sort}{$token}{call}) { + my $callback = $hooks{sort}{$token}{call}; + return sub { $sense * $callback->($_[0], $_[1], $parameter) }; + } + + if ($method eq 'title') { + return sub { $sense * (pagetitle(basename($_[0])) cmp pagetitle(basename($_[1]))) }; + } + + if ($method eq 'title_natural') { + eval q{use Sort::Naturally}; + if ($@) { + error(gettext("Sort::Naturally needed for title_natural sort")); + } + return sub { $sense * Sort::Naturally::ncmp(pagetitle(basename($_[0])), pagetitle(basename($_[1]))) }; + } + + if ($method eq 'mtime') { + return sub { $sense * ($pagemtime{$_[1]} <=> $pagemtime{$_[0]}) }; + } + + if ($method eq 'age') { + return sub { $sense * ($pagectime{$_[1]} <=> $pagectime{$_[0]}) }; + } + + error sprintf(gettext("unknown sort type %s"), $method); +} + sub pagespec_match_list ($$;@) { my $page=shift; my $pagespec=shift; @@ -2034,31 +2092,9 @@ sub pagespec_match_list ($$;@) { } if (defined $params{sort}) { - my $f; + my $f = get_sort_function($params{sort}); - if (exists $hooks{sort}{$params{sort}}{call}) { - $f = sub { $hooks{sort}{$params{sort}}{call}($a, $b) }; - } - elsif ($params{sort} eq 'title') { - $f=sub { pagetitle(basename($a)) cmp pagetitle(basename($b)) }; - } - elsif ($params{sort} eq 'title_natural') { - eval q{use Sort::Naturally}; - if ($@) { - error(gettext("Sort::Naturally needed for title_natural sort")); - } - $f=sub { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) }; - } - elsif ($params{sort} eq 'mtime') { - $f=sub { $pagemtime{$b} <=> $pagemtime{$a} }; - } - elsif ($params{sort} eq 'age') { - $f=sub { $pagectime{$b} <=> $pagectime{$a} }; - } - else { - error sprintf(gettext("unknown sort type %s"), $params{sort}); - } - @candidates = sort { &$f } @candidates; + @candidates = sort { $f->($a, $b) } @candidates; } @candidates=reverse(@candidates) if $params{reverse}; diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index 61516bec5..f27972d4e 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -15,6 +15,10 @@ orders can be specified. full title was set. """]] +In addition, you can combine several sort orders and/or reverse the order of +sorting, with a string like `age -title` (which would sort by age, then by +title in reverse order if two pages have the same age). + Plugins can add additional sort orders, so more might be available on this wiki. diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index bfa6617bd..1010e76e4 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -593,7 +593,9 @@ function of the ikiwiki wrapper when it is being generated. hook(type => "sort", id => "foo", call => \&sort_by_foo); This hook adds an additional [[ikiwiki/pagespec/sorting]] order or overrides -an existing one. The callback is given two page names as arguments, and +an existing one. + +The callback is given two page names followed by the parameter as arguments, and returns negative, zero or positive if the first page should come before, close to (i.e. undefined order), or after the second page. @@ -603,6 +605,19 @@ For instance, the built-in `title` sort order could be reimplemented as pagetitle(basename($_[0])) cmp pagetitle(basename($_[1])); } +and to sort by an arbitrary `meta` value, you could use: + + # usage: sort="meta(description)" + sub sort_by_meta { + my $param = $_[2]; + error "sort=meta requires a parameter" unless defined $param; + my $left = $pagestate{$_[0]}{meta}{$param}; + $left = "" unless defined $left; + my $right = $pagestate{$_[1]}{meta}{$param}; + $right = "" unless defined $right; + return $left cmp $right; + } + ## Exported variables Several variables are exported to your plugin when you `use IkiWiki;` diff --git a/t/pagespec_match_list.t b/t/pagespec_match_list.t index b34ee769f..309961f1c 100755 --- a/t/pagespec_match_list.t +++ b/t/pagespec_match_list.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 89; +use Test::More tests => 90; BEGIN { use_ok("IkiWiki"); } @@ -20,6 +20,13 @@ hook(type => "sort", id => "path", call => sub { $_[0] cmp $_[1] }); "post/2" => "post/2.mdwn", "post/3" => "post/3.mdwn", ); +$IkiWiki::pagectime{foo} = 2; +$IkiWiki::pagectime{foo2} = 2; +$IkiWiki::pagectime{foo3} = 1; +$IkiWiki::pagectime{bar} = 3; +$IkiWiki::pagectime{"post/1"} = 6; +$IkiWiki::pagectime{"post/2"} = 6; +$IkiWiki::pagectime{"post/3"} = 6; $links{foo}=[qw{post/1 post/2}]; $links{foo2}=[qw{bar}]; $links{foo3}=[qw{bar}]; @@ -38,6 +45,9 @@ is_deeply([pagespec_match_list("foo", "post/*", sort => "title", ["post/1", "post/2"]); is_deeply([pagespec_match_list("foo", "*", sort => "path", num => 2)], ["bar", "foo"]); +is_deeply([pagespec_match_list("foo", "foo* or bar*", + sort => "-age title")], # oldest first, break ties by title + ["foo3", "foo", "foo2", "bar"]); my $r=eval { pagespec_match_list("foo", "beep") }; ok(eval { pagespec_match_list("foo", "beep") } == 0); ok(! $@, "does not fail with error when unable to match anything"); -- cgit v1.2.3 From a875ee8be702bd4575e009dc652015c1157c7c2e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 3 Apr 2010 13:48:30 +0100 Subject: Split out sortnaturally into a plugin --- IkiWiki.pm | 11 ----------- IkiWiki/Plugin/sortnaturally.pm | 32 ++++++++++++++++++++++++++++++++ debian/NEWS | 8 ++++++++ doc/ikiwiki/pagespec/sorting.mdwn | 5 +++-- doc/plugins/sortnaturally.mdwn | 5 +++++ 5 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 IkiWiki/Plugin/sortnaturally.pm create mode 100644 doc/plugins/sortnaturally.mdwn (limited to 'doc/ikiwiki/pagespec') diff --git a/IkiWiki.pm b/IkiWiki.pm index a89c14058..8f36f5818 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -2423,15 +2423,4 @@ sub cmp_title { sub cmp_mtime { $IkiWiki::pagemtime{$_[1]} <=> $IkiWiki::pagemtime{$_[0]} } sub cmp_age { $IkiWiki::pagectime{$_[1]} <=> $IkiWiki::pagectime{$_[0]} } -sub check_cmp_title_natural { - eval q{use Sort::Naturally}; - if ($@) { - error(gettext("Sort::Naturally needed for title_natural sort")); - } -} -sub cmp_title_natural { - Sort::Naturally::ncmp(IkiWiki::pagetitle(IkiWiki::basename($_[0])), - IkiWiki::pagetitle(IkiWiki::basename($_[1]))) -} - 1 diff --git a/IkiWiki/Plugin/sortnaturally.pm b/IkiWiki/Plugin/sortnaturally.pm new file mode 100644 index 000000000..0023f31f9 --- /dev/null +++ b/IkiWiki/Plugin/sortnaturally.pm @@ -0,0 +1,32 @@ +#!/usr/bin/perl +# Sort::Naturally-powered title_natural sort order for IkiWiki +package IkiWiki::Plugin::sortnaturally; + +use IkiWiki 3.00; +no warnings; + +sub import { + hook(type => "getsetup", id => "sortnaturally", call => \&getsetup); +} + +sub getsetup { + return + plugin => { + safe => 1, + rebuild => 1, + }, +} + +sub checkconfig () { + eval q{use Sort::Naturally}; + error $@ if $@; +} + +package IkiWiki::PageSpec; + +sub cmp_title_natural { + Sort::Naturally::ncmp(IkiWiki::pagetitle(IkiWiki::basename($_[0])), + IkiWiki::pagetitle(IkiWiki::basename($_[1]))) +} + +1; diff --git a/debian/NEWS b/debian/NEWS index 50332670f..614eb11f8 100644 --- a/debian/NEWS +++ b/debian/NEWS @@ -1,3 +1,11 @@ +ikiwiki (3.20100320) UNRELEASED; urgency=low + + The sort="title_natural" option on [[!inline]] etc. now requires the + new sortnaturally plugin. This is not enabled by default, because it requires + the Sort::Naturally module. + + -- Simon McVittie Sat, 03 Apr 2010 13:46:08 +0100 + ikiwiki (3.20091017) unstable; urgency=low To take advantage of significant performance improvements, all diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index f27972d4e..ba995a521 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -6,9 +6,10 @@ orders can be specified. * `age` - List pages from the most recently created to the oldest. * `mtime` - List pages with the most recently modified first. * `title` - Order by title (page name). -* `title_natural` - Only available if [[!cpan Sort::Naturally]] is - installed. Orders by title, but numbers in the title are treated +[[!if test="enabled(sortnaturally)" then=""" +* `title_natural` - Orders by title, but numbers in the title are treated as such, ("1 2 9 10 20" instead of "1 10 2 20 9") +"""]] [[!if test="enabled(meta)" then=""" * `meta_title` - Order according to the `\[[!meta title="foo" sort="bar"]]` or `\[[!meta title="foo"]]` [[ikiwiki/directive]], or the page name if no diff --git a/doc/plugins/sortnaturally.mdwn b/doc/plugins/sortnaturally.mdwn new file mode 100644 index 000000000..91f373f6b --- /dev/null +++ b/doc/plugins/sortnaturally.mdwn @@ -0,0 +1,5 @@ +[[!template id=plugin name=sortnaturally core=1 author="[[chrysn]], [[smcv]]"]] +[[!tag type/meta]] + +This plugin provides the `title_natural` [[ikiwiki/pagespec/sorting]] order, +which uses Sort::Naturally to sort numbered pages in a more natural order. -- cgit v1.2.3 From 618bbaee3815daffe329fc1e2d77f04fcd8392b8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 3 Apr 2010 14:17:48 +0100 Subject: meta: generalize meta_title into meta(title); support author, updated, date I've left meta_title in, undocumented, as a possible replacement for sort=title in IkiWiki 4.0 or something. --- IkiWiki/Plugin/meta.pm | 58 +++++++++++++++++++++++++++++++++------ doc/ikiwiki/directive/meta.mdwn | 7 ++++- doc/ikiwiki/pagespec/sorting.mdwn | 5 ++-- 3 files changed, 58 insertions(+), 12 deletions(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index cd7d0d127..c9fdbc934 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -122,6 +122,12 @@ sub preprocess (@) { } elsif ($key eq 'author') { $pagestate{$page}{meta}{author}=$value; + if (exists $params{sort}) { + $pagestate{$page}{meta}{authorsort}=$params{sort}; + } + else { + $pagestate{$page}{meta}{authorsort}=$value; + } # fallthorough } elsif ($key eq 'authorurl') { @@ -288,14 +294,31 @@ sub pagetemplate (@) { } } -sub titlesort { - my $key = $pagestate{$_[0]}{meta}{titlesort}; +sub get_sort_key { + my $page = $_[0]; + my $meta = $_[1]; - if (defined $key) { - return $key; - } + # e.g. titlesort (also makes sense for author) + my $key = $pagestate{$page}{meta}{$meta . "sort"}; + return $key if defined $key; + + # e.g. title + $key = $pagestate{$page}{meta}{$meta}; + return $key if defined $key; - return pagetitle(IkiWiki::basename($_[0])); + # fall back to closer-to-core things + if ($meta eq 'title') { + return pagetitle(IkiWiki::basename($page)); + } + elsif ($meta eq 'date') { + return $IkiWiki::pagectime{$page}; + } + elsif ($meta eq 'updated') { + return $IkiWiki::pagemtime{$page}; + } + else { + return ''; + } } sub match { @@ -350,10 +373,27 @@ sub match_copyright ($$;@) { package IkiWiki::SortSpec; +sub cmp_meta { + my $left = $_[0]; + my $right = $_[1]; + my $meta = $_[2]; + error(gettext("sort=meta requires a parameter")) unless defined $meta; + + if ($meta eq 'updated' || $meta eq 'date') { + return IkiWiki::Plugin::meta::get_sort_key($left, $meta) + <=> + IkiWiki::Plugin::meta::get_sort_key($right, $meta); + } + + return IkiWiki::Plugin::meta::get_sort_key($left, $meta) + cmp + IkiWiki::Plugin::meta::get_sort_key($right, $meta); +} + +# A prototype of how sort=title could behave in 4.0 or something sub cmp_meta_title { - IkiWiki::Plugin::meta::titlesort($_[0]) - cmp - IkiWiki::Plugin::meta::titlesort($_[1]) + $_[2] = 'title'; + return cmp_meta(@_); } 1 diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn index 8d2a5b1ad..c5f74fac5 100644 --- a/doc/ikiwiki/directive/meta.mdwn +++ b/doc/ikiwiki/directive/meta.mdwn @@ -24,7 +24,7 @@ Supported fields: differently in this case. An optional `sort` parameter will be used preferentially when - [[ikiwiki/pagespec/sorting]] by `meta_title`: + [[ikiwiki/pagespec/sorting]] by `meta(title)`: \[[!meta title="The Beatles" sort="Beatles, The"]] @@ -44,6 +44,11 @@ Supported fields: Specifies the author of a page. + An optional `sort` parameter will be used preferentially when + [[ikiwiki/pagespec/sorting]] by `meta(author)`: + + \[[!meta author="Joey Hess" sort="Hess, Joey"]] + * authorurl Specifies an url for the author of a page. diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index ba995a521..fbf598340 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -11,9 +11,10 @@ orders can be specified. as such, ("1 2 9 10 20" instead of "1 10 2 20 9") """]] [[!if test="enabled(meta)" then=""" -* `meta_title` - Order according to the `\[[!meta title="foo" sort="bar"]]` +* `meta(title)` - Order according to the `\[[!meta title="foo" sort="bar"]]` or `\[[!meta title="foo"]]` [[ikiwiki/directive]], or the page name if no - full title was set. + full title was set. `meta(author)`, `meta(date)`, `meta(updated)`, etc. + also work. """]] In addition, you can combine several sort orders and/or reverse the order of -- cgit v1.2.3 From 490f95616a8a49f2120655d07c282eefd067e640 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sat, 3 Apr 2010 14:19:18 +0100 Subject: Rename sort parameter to meta title/author to sortas=bar Joey pointed out that sort=x usually takes a sort order. --- IkiWiki/Plugin/meta.pm | 8 ++++---- doc/ikiwiki/directive/meta.mdwn | 10 +++++----- doc/ikiwiki/pagespec/sorting.mdwn | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index c9fdbc934..4992617d0 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -89,8 +89,8 @@ sub preprocess (@) { # Metadata collection that needs to happen during the scan pass. if ($key eq 'title') { $pagestate{$page}{meta}{title}=HTML::Entities::encode_numeric($value); - if (exists $params{sort}) { - $pagestate{$page}{meta}{titlesort}=$params{sort}; + if (exists $params{sortas}) { + $pagestate{$page}{meta}{titlesort}=$params{sortas}; } else { $pagestate{$page}{meta}{titlesort}=$value; @@ -122,8 +122,8 @@ sub preprocess (@) { } elsif ($key eq 'author') { $pagestate{$page}{meta}{author}=$value; - if (exists $params{sort}) { - $pagestate{$page}{meta}{authorsort}=$params{sort}; + if (exists $params{sortas}) { + $pagestate{$page}{meta}{authorsort}=$params{sortas}; } else { $pagestate{$page}{meta}{authorsort}=$value; diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn index c5f74fac5..5a3919dea 100644 --- a/doc/ikiwiki/directive/meta.mdwn +++ b/doc/ikiwiki/directive/meta.mdwn @@ -23,12 +23,12 @@ Supported fields: be set to a true value in the template; this can be used to format things differently in this case. - An optional `sort` parameter will be used preferentially when + An optional `sortas` parameter will be used preferentially when [[ikiwiki/pagespec/sorting]] by `meta(title)`: - \[[!meta title="The Beatles" sort="Beatles, The"]] + \[[!meta title="The Beatles" sortas="Beatles, The"]] - \[[!meta title="David Bowie" sort="Bowie, David"]] + \[[!meta title="David Bowie" sortas="Bowie, David"]] * license @@ -44,10 +44,10 @@ Supported fields: Specifies the author of a page. - An optional `sort` parameter will be used preferentially when + An optional `sortas` parameter will be used preferentially when [[ikiwiki/pagespec/sorting]] by `meta(author)`: - \[[!meta author="Joey Hess" sort="Hess, Joey"]] + \[[!meta author="Joey Hess" sortas="Hess, Joey"]] * authorurl diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index fbf598340..5c6cfcc2b 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -11,7 +11,7 @@ orders can be specified. as such, ("1 2 9 10 20" instead of "1 10 2 20 9") """]] [[!if test="enabled(meta)" then=""" -* `meta(title)` - Order according to the `\[[!meta title="foo" sort="bar"]]` +* `meta(title)` - Order according to the `\[[!meta title="foo" sortas="bar"]]` or `\[[!meta title="foo"]]` [[ikiwiki/directive]], or the page name if no full title was set. `meta(author)`, `meta(date)`, `meta(updated)`, etc. also work. -- cgit v1.2.3 From 04a9d8e867f1eef46e9c79dee055756bdbb6a039 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 6 Apr 2010 23:26:59 -0400 Subject: remove note about more sort types possibly being available Good plugins should document them :) --- doc/ikiwiki/pagespec/sorting.mdwn | 3 --- 1 file changed, 3 deletions(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index 5c6cfcc2b..37995f1e8 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -21,7 +21,4 @@ In addition, you can combine several sort orders and/or reverse the order of sorting, with a string like `age -title` (which would sort by age, then by title in reverse order if two pages have the same age). -Plugins can add additional sort orders, so more might be available on this -wiki. - [[!meta robots="noindex, follow"]] -- cgit v1.2.3 From 9060cb0cf8f73fca276719dd92dfae9b48d64d38 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 11 Apr 2010 14:32:18 +0100 Subject: Space sorting orders consistently Markdown interprets the empty lines resulting from [[!if]] as a request that each
  • contain a

    . For consistent spacing in the HTML, either the unconditional items should have blank lines between (resulting in each

  • having a

    ), or the conditional items should not (resulting in messy source code, and no

  • having a

    ). I think the former looks nicer. --- doc/ikiwiki/pagespec/sorting.mdwn | 2 ++ 1 file changed, 2 insertions(+) (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index 37995f1e8..ccd7f7eaa 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -4,7 +4,9 @@ specifying the order that matching pages are shown in. The following sort orders can be specified. * `age` - List pages from the most recently created to the oldest. + * `mtime` - List pages with the most recently modified first. + * `title` - Order by title (page name). [[!if test="enabled(sortnaturally)" then=""" * `title_natural` - Orders by title, but numbers in the title are treated -- cgit v1.2.3 From 33b0a69e90f4c2e22fe0e0c812836a2eb661c6d2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 23 Apr 2010 17:36:07 -0400 Subject: improve attachment example --- doc/ikiwiki/pagespec/attachment.mdwn | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/pagespec/attachment.mdwn b/doc/ikiwiki/pagespec/attachment.mdwn index 419f00ee4..fa2bc5867 100644 --- a/doc/ikiwiki/pagespec/attachment.mdwn +++ b/doc/ikiwiki/pagespec/attachment.mdwn @@ -7,11 +7,12 @@ If attachments are enabled, the wiki admin can control what types of attachments will be accepted, via the `allowed_attachments` configuration setting. -For example, to limit arbitrary files to 50 kilobytes, but allow -larger mp3 files to be uploaded by joey into a specific directory, and -check all attachments for viruses, something like this could be used: +For example, to limit most users to uploading small images, and nothing else, +while allowing larger mp3 files to be uploaded by joey into a specific +directory, and check all attachments for viruses, something like this could be +used: - virusfree() and ((user(joey) and podcast/*.mp3 and mimetype(audio/mpeg) and maxsize(15mb)) or (!ispage() and maxsize(50kb))) + virusfree() and ((user(joey) and podcast/*.mp3 and mimetype(audio/mpeg) and maxsize(15mb)) or (mimetype(image/*) and maxsize(50kb))) The regular [[ikiwiki/PageSpec]] syntax is expanded with the following additional tests: -- cgit v1.2.3 From 14e1cccf1222232bd890c9eff1ea2c7fb0804b4f Mon Sep 17 00:00:00 2001 From: PaulePanter Date: Sat, 19 Jun 2010 10:35:32 +0000 Subject: Match start page `/index` does not work. --- doc/ikiwiki/pagespec/discussion.mdwn | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/pagespec/discussion.mdwn b/doc/ikiwiki/pagespec/discussion.mdwn index 4eed3722c..1aac47fa4 100644 --- a/doc/ikiwiki/pagespec/discussion.mdwn +++ b/doc/ikiwiki/pagespec/discussion.mdwn @@ -92,3 +92,11 @@ does not seem suitable for this, as > \[[!map pages="./*"]] also lists the current page and all its siblings. + +--- + +I am a little lost. I want to match the start page `/index.mdwn`. So I use + + \[[!inline pages="/index"]] + +which does not work though. I also tried it in this Wiki. Just take a look at the end of the [[SandBox|sandbox]]. --[[PaulePanter]] -- cgit v1.2.3 From 4048988576c4ad23293379751b438af0bdb4b310 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 23 Jun 2010 13:04:56 -0400 Subject: response --- doc/ikiwiki/pagespec/discussion.mdwn | 3 +++ 1 file changed, 3 insertions(+) (limited to 'doc/ikiwiki/pagespec') diff --git a/doc/ikiwiki/pagespec/discussion.mdwn b/doc/ikiwiki/pagespec/discussion.mdwn index 1aac47fa4..4c553925a 100644 --- a/doc/ikiwiki/pagespec/discussion.mdwn +++ b/doc/ikiwiki/pagespec/discussion.mdwn @@ -100,3 +100,6 @@ I am a little lost. I want to match the start page `/index.mdwn`. So I use \[[!inline pages="/index"]] which does not work though. I also tried it in this Wiki. Just take a look at the end of the [[SandBox|sandbox]]. --[[PaulePanter]] + +> Unlike wikilinks, pagespecs match relative to the top of the wiki by +> default. So lose the "/" and it will work. --[[Joey]] -- cgit v1.2.3 From be49679fe9235f0fe9a28dabf3d91c9ee173106f Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 29 Jun 2010 15:45:34 +0200 Subject: po: added a needstranslation() pagespec (cherry picked from commit b225fdc44d4b3d2853db622d59aed7b59788aeec) --- IkiWiki/Plugin/po.pm | 15 +++++++++++++++ doc/ikiwiki/pagespec/po.mdwn | 2 ++ 2 files changed, 17 insertions(+) (limited to 'doc/ikiwiki/pagespec') diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 86d5087f4..f12c69d5f 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -1220,4 +1220,19 @@ sub match_currentlang ($$;@) { } } +sub match_needstranslation ($$;@) { + my $page=shift; + + my $percenttranslated=IkiWiki::Plugin::po::percenttranslated($page); + if ($percenttranslated eq 'N/A') { + return IkiWiki::FailReason->new("file is not a translation page"); + } + elsif ($percenttranslated < 100) { + return IkiWiki::SuccessReason->new("file has $percenttranslated translated"); + } + else { + return IkiWiki::FailReason->new("file is fully translated"); + } +} + 1 diff --git a/doc/ikiwiki/pagespec/po.mdwn b/doc/ikiwiki/pagespec/po.mdwn index 40ed9efb6..f8b398575 100644 --- a/doc/ikiwiki/pagespec/po.mdwn +++ b/doc/ikiwiki/pagespec/po.mdwn @@ -11,6 +11,8 @@ wiki: specified as a ISO639-1 (two-letter) language code. * "`currentlang()`" - tests whether a page is written in the same language as the current page. +* "`needstranslation()`" - tests whether a page needs translation + work. Only slave pages match this PageSpec. Note that every non-po page is considered to be written in `po_master_language`, as specified in `ikiwiki.setup`. -- cgit v1.2.3 From 718d9413fb39db52cff4975dac1c09afc0ca8f79 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sun, 11 Jul 2010 11:58:09 +0200 Subject: po: added an optional target percentage to needstranslation (cherry picked from commit 98cc9460ac67fee606437712882cfa1e5d259729) --- IkiWiki/Plugin/po.pm | 17 +++++++++++++++-- doc/ikiwiki/pagespec/po.mdwn | 5 ++++- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'doc/ikiwiki/pagespec') diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 4e6eff94f..903a9500f 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -1249,16 +1249,29 @@ sub match_currentlang ($$;@) { sub match_needstranslation ($$;@) { my $page=shift; + my $wanted=shift; + + if (defined $wanted && $wanted ne "") { + if ($wanted !~ /^\d+$/) { + return IkiWiki::FailReason->new("parameter is not an integer"); + } + elsif ($wanted > 100) { + return IkiWiki::FailReason->new("parameter is greater than 100"); + } + } + else { + $wanted=100; + } my $percenttranslated=IkiWiki::Plugin::po::percenttranslated($page); if ($percenttranslated eq 'N/A') { return IkiWiki::FailReason->new("file is not a translatable page"); } - elsif ($percenttranslated < 100) { + elsif ($percenttranslated < $wanted) { return IkiWiki::SuccessReason->new("file has $percenttranslated translated"); } else { - return IkiWiki::FailReason->new("file is fully translated"); + return IkiWiki::FailReason->new("file is translated enough"); } } diff --git a/doc/ikiwiki/pagespec/po.mdwn b/doc/ikiwiki/pagespec/po.mdwn index f8b398575..f9956404c 100644 --- a/doc/ikiwiki/pagespec/po.mdwn +++ b/doc/ikiwiki/pagespec/po.mdwn @@ -12,7 +12,10 @@ wiki: * "`currentlang()`" - tests whether a page is written in the same language as the current page. * "`needstranslation()`" - tests whether a page needs translation - work. Only slave pages match this PageSpec. + work. Only slave pages match this PageSpec. A minimum target + translation percentage can optionally be passed as an integer + parameter: "`needstranslation(50)`" matches only pages less than 50% + translated. Note that every non-po page is considered to be written in `po_master_language`, as specified in `ikiwiki.setup`. -- cgit v1.2.3