* pagespec_match() has changed to take named parameters, to better allow

for extended pagespecs. The old calling convention will still work for
  back-compat for now.
* The calling convention for functions in the IkiWiki::PageSpec namespace
  has changed so they are passed named parameters.
* Plugin interface version increased to 2.00 since I don't anticipate any
  more interface changes before 2.0.
master
joey 2007-04-27 02:55:52 +00:00
parent 80aa0336e6
commit ee1ad53c4c
60 changed files with 189 additions and 166 deletions

View File

@ -18,7 +18,7 @@ our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
bestlink htmllink readfile writefile pagetype srcfile pagename bestlink htmllink readfile writefile pagetype srcfile pagename
displaytime will_render gettext urlto targetpage displaytime will_render gettext urlto targetpage
%config %links %renderedfiles %pagesources %destsources); %config %links %renderedfiles %pagesources %destsources);
our $VERSION = 1.02; # plugin interface version, next is ikiwiki version our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
@ -974,38 +974,42 @@ sub pagespec_translate ($) { #{{{
} }
elsif ($word =~ /^(\w+)\((.*)\)$/) { elsif ($word =~ /^(\w+)\((.*)\)$/) {
if (exists $IkiWiki::PageSpec::{"match_$1"}) { if (exists $IkiWiki::PageSpec::{"match_$1"}) {
$code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \$from)"; $code.="IkiWiki::PageSpec::match_$1(\$page, ".safequote($2).", \@params)";
} }
else { else {
$code.=" 0"; $code.=" 0";
} }
} }
else { else {
$code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \$from)"; $code.=" IkiWiki::PageSpec::match_glob(\$page, ".safequote($word).", \@params)";
} }
} }
return $code; return $code;
} #}}} } #}}}
sub pagespec_match ($$;$) { #{{{ sub pagespec_match ($$;@) { #{{{
my $page=shift; my $page=shift;
my $spec=shift; my $spec=shift;
my $from=shift; my @params=@_;
# Backwards compatability with old calling convention.
if (@params == 1) {
unshift @params, "location";
}
return eval pagespec_translate($spec); return eval pagespec_translate($spec);
} #}}} } #}}}
package IkiWiki::PageSpec; package IkiWiki::PageSpec;
sub match_glob ($$$) { #{{{ sub match_glob ($$;@) { #{{{
my $page=shift; my $page=shift;
my $glob=shift; my $glob=shift;
my $from=shift; my %params=@_;
if (! defined $from){
$from = ""; my $from=exists $params{location} ? $params{location} : "";
}
# relative matching # relative matching
if ($glob =~ m!^\./!) { if ($glob =~ m!^\./!) {
$from=~s!/?[^/]+$!!; $from=~s!/?[^/]+$!!;
@ -1021,13 +1025,12 @@ sub match_glob ($$$) { #{{{
return $page=~/^$glob$/i; return $page=~/^$glob$/i;
} #}}} } #}}}
sub match_link ($$$) { #{{{ sub match_link ($$;@) { #{{{
my $page=shift; my $page=shift;
my $link=lc(shift); my $link=lc(shift);
my $from=shift; my %params=@_;
if (! defined $from){
$from = ""; my $from=exists $params{location} ? $params{location} : "";
}
# relative matching # relative matching
if ($link =~ m!^\.! && defined $from) { if ($link =~ m!^\.! && defined $from) {
@ -1046,11 +1049,11 @@ sub match_link ($$$) { #{{{
return 0; return 0;
} #}}} } #}}}
sub match_backlink ($$$) { #{{{ sub match_backlink ($$;@) { #{{{
match_link($_[1], $_[0], $_[3]); match_link($_[1], $_[0], @_);
} #}}} } #}}}
sub match_created_before ($$$) { #{{{ sub match_created_before ($$;@) { #{{{
my $page=shift; my $page=shift;
my $testpage=shift; my $testpage=shift;
@ -1062,7 +1065,7 @@ sub match_created_before ($$$) { #{{{
} }
} #}}} } #}}}
sub match_created_after ($$$) { #{{{ sub match_created_after ($$;@) { #{{{
my $page=shift; my $page=shift;
my $testpage=shift; my $testpage=shift;
@ -1074,16 +1077,25 @@ sub match_created_after ($$$) { #{{{
} }
} #}}} } #}}}
sub match_creation_day ($$$) { #{{{ sub match_creation_day ($$;@) { #{{{
return ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift); return ((gmtime($IkiWiki::pagectime{shift()}))[3] == shift);
} #}}} } #}}}
sub match_creation_month ($$$) { #{{{ sub match_creation_month ($$;@) { #{{{
return ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift); return ((gmtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift);
} #}}} } #}}}
sub match_creation_year ($$$) { #{{{ sub match_creation_year ($$;@) { #{{{
return ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift); return ((gmtime($IkiWiki::pagectime{shift()}))[5] + 1900 == shift);
} #}}} } #}}}
sub match_user ($$;@) { #{{{
shift;
my $user=shift;
my %params=@_;
return unless exists $params{user};
return $user eq $params{user};
} #}}}
1 1

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::aggregate;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
use HTML::Entities; use HTML::Entities;
use HTML::Parser; use HTML::Parser;
use HTML::Tagset; use HTML::Tagset;

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::anonok;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "canedit", id => "anonok", call => \&canedit,); hook(type => "canedit", id => "anonok", call => \&canedit,);

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::brokenlinks;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "preprocess", id => "brokenlinks", call => \&preprocess); hook(type => "preprocess", id => "brokenlinks", call => \&preprocess);
@ -20,7 +20,7 @@ sub preprocess (@) { #{{{
my @broken; my @broken;
foreach my $page (keys %links) { foreach my $page (keys %links) {
if (pagespec_match($page, $params{pages}, $params{page})) { if (pagespec_match($page, $params{pages}, location => $params{page})) {
my $discussion=gettext("discussion"); my $discussion=gettext("discussion");
foreach my $link (@{$links{$page}}) { foreach my $link (@{$links{$page}}) {
next if $link =~ /.*\/\Q$discussion\E/i && $config{discussion}; next if $link =~ /.*\/\Q$discussion\E/i && $config{discussion};

View File

@ -2,9 +2,9 @@
# CamelCase links # CamelCase links
package IkiWiki::Plugin::camelcase; package IkiWiki::Plugin::camelcase;
use IkiWiki;
use warnings; use warnings;
use strict; use strict;
use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "filter", id => "camelcase", call => \&filter); hook(type => "filter", id => "camelcase", call => \&filter);

View File

@ -3,12 +3,9 @@ package IkiWiki::Plugin::conditional;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
use UNIVERSAL; use UNIVERSAL;
# Globals used to pass information into the PageSpec functions.
our ($sourcepage, $destpage);
sub import { #{{{ sub import { #{{{
hook(type => "preprocess", id => "if", call => \&preprocess_if); hook(type => "preprocess", id => "if", call => \&preprocess_if);
} # }}} } # }}}
@ -21,27 +18,28 @@ sub preprocess_if (@) { #{{{
} }
my $result=0; my $result=0;
$sourcepage=$params{page};
$destpage=$params{destpage};
# An optimisation to avoid needless looping over every page # An optimisation to avoid needless looping over every page
# and adding of dependencies for simple uses of some of the # and adding of dependencies for simple uses of some of the
# tests. # tests.
if ($params{test} =~ /^(enabled|sourcepage|destpage)\((.*)\)$/) { if ($params{test} =~ /^(enabled|sourcepage|destpage)\((.*)\)$/) {
$result=eval "IkiWiki::PageSpec::match_$1(undef, ". $result=pagespec_match($params{page}, $params{test},
IkiWiki::safequote($2).", \$params{page})"; location => $params{page},
sourcepage => $params{page},
destpage => $params{destpage});
} }
else { else {
add_depends($params{page}, $params{test}); add_depends($params{page}, $params{test});
foreach my $page (keys %pagesources) { foreach my $page (keys %pagesources) {
if (pagespec_match($page, $params{test}, $params{page})) { if (pagespec_match($page, $params{test},
location => $params{page},
sourcepage => $params{page},
destpage => $params{destpage})) {
$result=1; $result=1;
last; last;
} }
} }
} }
$sourcepage="";
$destpage="";
my $ret; my $ret;
if ($result) { if ($result) {
@ -59,7 +57,7 @@ sub preprocess_if (@) { #{{{
package IkiWiki::PageSpec; package IkiWiki::PageSpec;
sub match_enabled ($$$) { #{{{ sub match_enabled ($$;@) { #{{{
shift; shift;
my $plugin=shift; my $plugin=shift;
@ -67,24 +65,31 @@ sub match_enabled ($$$) { #{{{
return UNIVERSAL::can("IkiWiki::Plugin::".$plugin, "import"); return UNIVERSAL::can("IkiWiki::Plugin::".$plugin, "import");
} #}}} } #}}}
sub match_sourcepage ($$$) { #{{{ sub match_sourcepage ($$;@) { #{{{
shift; shift;
my $glob=shift; my $glob=shift;
my %params=@_;
return match_glob($IkiWiki::Plugin::conditional::sourcepage, $glob,
$IkiWiki::Plugin::conditional::sourcepage); return unless exists $params{sourcepage};
return match_glob($params{sourcepage}, $glob, @_);
} #}}} } #}}}
sub match_destpage ($$$) { #{{{ sub match_destpage ($$;@) { #{{{
shift; shift;
my $glob=shift; my $glob=shift;
my %params=@_;
return match_glob($IkiWiki::Plugin::conditional::destpage, $glob, return unless exists $params{destpage};
$IkiWiki::Plugin::conditional::sourcepage); return match_glob($params{destpage}, $glob, @_);
} #}}} } #}}}
sub match_included ($$$) { #{{{ sub match_included ($$;$) { #{{{
return $IkiWiki::Plugin::conditional::sourcepage ne $IkiWiki::Plugin::conditional::destpage; shift;
shift;
my %params=@_;
return unless exists $params{sourcepage} && exists $params{destpage};
return $params{sourcepage} ne $params{destpage};
} #}}} } #}}}
1 1

View File

@ -1,7 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
# Discordian date support fnord ikiwiki. # Discordian date support fnord ikiwiki.
package IkiWiki::Plugin::ddate; package IkiWiki::Plugin::ddate;
use IkiWiki;
use IkiWiki 2.00;
no warnings; no warnings;
sub import { #{{{ sub import { #{{{

View File

@ -5,7 +5,7 @@ package IkiWiki::Plugin::favicon;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "pagetemplate", id => "favicon", call => \&pagetemplate); hook(type => "pagetemplate", id => "favicon", call => \&pagetemplate);

View File

@ -2,9 +2,9 @@
# Include a fortune in a page # Include a fortune in a page
package IkiWiki::Plugin::fortune; package IkiWiki::Plugin::fortune;
use IkiWiki;
use warnings; use warnings;
use strict; use strict;
use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "preprocess", id => "fortune", call => \&preprocess); hook(type => "preprocess", id => "fortune", call => \&preprocess);

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::goodstuff;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
my @bundle=qw{ my @bundle=qw{
brokenlinks brokenlinks

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::googlecalendar;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "preprocess", id => "googlecalendar", hook(type => "preprocess", id => "googlecalendar",

View File

@ -5,7 +5,7 @@ package IkiWiki::Plugin::graphviz;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
use IPC::Open2; use IPC::Open2;
sub import { #{{{ sub import { #{{{

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::haiku;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "preprocess", id => "haiku", call => \&preprocess); hook(type => "preprocess", id => "haiku", call => \&preprocess);

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::html;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "htmlize", id => "html", call => \&htmlize); hook(type => "htmlize", id => "html", call => \&htmlize);

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::htmlscrubber;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "sanitize", id => "htmlscrubber", call => \&sanitize); hook(type => "sanitize", id => "htmlscrubber", call => \&sanitize);

View File

@ -9,7 +9,7 @@ package IkiWiki::Plugin::htmltidy;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
use IPC::Open2; use IPC::Open2;
sub import { #{{{ sub import { #{{{

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::httpauth;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "auth", id => "httpauth", call => \&auth); hook(type => "auth", id => "httpauth", call => \&auth);

View File

@ -5,7 +5,7 @@ package IkiWiki::Plugin::img;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
my %imgdefaults; my %imgdefaults;

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::inline;
use warnings; use warnings;
use strict; use strict;
use IkiWiki 1.00; use IkiWiki 2.00;
use URI; use URI;
sub import { #{{{ sub import { #{{{
@ -88,7 +88,7 @@ sub preprocess_inline (@) { #{{{
my @list; my @list;
foreach my $page (keys %pagesources) { foreach my $page (keys %pagesources) {
next if $page eq $params{page}; next if $page eq $params{page};
if (pagespec_match($page, $params{pages}, $params{page})) { if (pagespec_match($page, $params{pages}, location => $params{page})) {
push @list, $page; push @list, $page;
} }
} }
@ -223,7 +223,7 @@ sub preprocess_inline (@) { #{{{
@list=@list[0..$params{feedshow} - 1]; @list=@list[0..$params{feedshow} - 1];
} }
if (exists $params{feedpages}) { if (exists $params{feedpages}) {
@list=grep { pagespec_match($_, $params{feedpages}, $params{page}) } @list; @list=grep { pagespec_match($_, $params{feedpages}, location => $params{page}) } @list;
} }
if ($rss) { if ($rss) {

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::linkmap;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
use IPC::Open2; use IPC::Open2;
sub import { #{{{ sub import { #{{{
@ -48,7 +48,7 @@ sub genmap ($) { #{{{
# Get all the items to map. # Get all the items to map.
my %mapitems = (); my %mapitems = ();
foreach my $item (keys %links) { foreach my $item (keys %links) {
if (pagespec_match($item, $params{pages}, $params{page})) { if (pagespec_match($item, $params{pages}, location => $params{page})) {
$mapitems{$item}=urlto($item, $params{destpage}); $mapitems{$item}=urlto($item, $params{destpage});
} }
} }

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::lockedit;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "canedit", id => "lockedit", call => \&canedit); hook(type => "canedit", id => "lockedit", call => \&canedit);
@ -20,7 +20,7 @@ sub canedit ($$) { #{{{
return undef if defined $user && IkiWiki::is_admin($user); return undef if defined $user && IkiWiki::is_admin($user);
foreach my $admin (@{$config{adminuser}}) { foreach my $admin (@{$config{adminuser}}) {
if (pagespec_match($page, IkiWiki::userinfo_get($admin, "locked_pages"), "")) { if (pagespec_match($page, IkiWiki::userinfo_get($admin, "locked_pages"))) {
return sprintf(gettext("%s is locked by %s and cannot be edited"), return sprintf(gettext("%s is locked by %s and cannot be edited"),
htmllink("", "", $page, noimageinline => 1), htmllink("", "", $page, noimageinline => 1),
IkiWiki::userlink($admin)); IkiWiki::userlink($admin));

View File

@ -9,7 +9,7 @@ package IkiWiki::Plugin::map;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "preprocess", id => "map", call => \&preprocess); hook(type => "preprocess", id => "map", call => \&preprocess);
@ -26,7 +26,7 @@ sub preprocess (@) { #{{{
# Get all the items to map. # Get all the items to map.
my @mapitems = (); my @mapitems = ();
foreach my $page (keys %links) { foreach my $page (keys %links) {
if (pagespec_match($page, $params{pages}, $params{page})) { if (pagespec_match($page, $params{pages}, location => $params{page})) {
push @mapitems, $page; push @mapitems, $page;
} }
} }

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::mdwn;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "htmlize", id => "mdwn", call => \&htmlize); hook(type => "htmlize", id => "mdwn", call => \&htmlize);

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::meta;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
my %meta; my %meta;
my %title; my %title;

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::mirrorlist;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "pagetemplate", id => "mirrorlist", call => \&pagetemplate); hook(type => "pagetemplate", id => "mirrorlist", call => \&pagetemplate);

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::more;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
my $linktext = gettext("more"); my $linktext = gettext("more");

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::opendiscussion;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "canedit", id => "opendiscussion", call => \&canedit); hook(type => "canedit", id => "opendiscussion", call => \&canedit);

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::openid;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "getopt", id => "openid", call => \&getopt); hook(type => "getopt", id => "openid", call => \&getopt);

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::orphans;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "preprocess", id => "orphans", call => \&preprocess); hook(type => "preprocess", id => "orphans", call => \&preprocess);
@ -28,7 +28,7 @@ sub preprocess (@) { #{{{
my $discussion=gettext("discussion"); my $discussion=gettext("discussion");
foreach my $page (keys %pagesources) { foreach my $page (keys %pagesources) {
next if $linkedto{$page}; next if $linkedto{$page};
next unless pagespec_match($page, $params{pages}, $params{page}); next unless pagespec_match($page, $params{pages}, location => $params{page});
# If the page has a link to some other page, it's # If the page has a link to some other page, it's
# indirectly linked to a page via that page's backlinks. # indirectly linked to a page via that page's backlinks.
next if grep { next if grep {

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::otl;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "filter", id => "otl", call => \&filter); hook(type => "filter", id => "otl", call => \&filter);

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::pagecount;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "preprocess", id => "pagecount", call => \&preprocess); hook(type => "preprocess", id => "pagecount", call => \&preprocess);
@ -21,7 +21,7 @@ sub preprocess (@) { #{{{
return $#pages+1 if $params{pages} eq "*"; # optimisation return $#pages+1 if $params{pages} eq "*"; # optimisation
my $count=0; my $count=0;
foreach my $page (@pages) { foreach my $page (@pages) {
$count++ if pagespec_match($page, $params{pages}, $params{page}); $count++ if pagespec_match($page, $params{pages}, location => $params{page});
} }
return $count; return $count;
} # }}} } # }}}

View File

@ -12,7 +12,7 @@ package IkiWiki::Plugin::pagestats;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
# Names of the HTML classes to use for the tag cloud # Names of the HTML classes to use for the tag cloud
our @classes = ('smallestPC', 'smallPC', 'normalPC', 'bigPC', 'biggestPC' ); our @classes = ('smallestPC', 'smallPC', 'normalPC', 'bigPC', 'biggestPC' );
@ -33,7 +33,7 @@ sub preprocess (@) { #{{{
my %counts; my %counts;
my $max = 0; my $max = 0;
foreach my $page (keys %links) { foreach my $page (keys %links) {
if (pagespec_match($page, $params{pages}, $params{page})) { if (pagespec_match($page, $params{pages}, location => $params{page})) {
use IkiWiki::Render; use IkiWiki::Render;
my @bl = IkiWiki::backlinks($page); my @bl = IkiWiki::backlinks($page);
$counts{$page} = scalar(@bl); $counts{$page} = scalar(@bl);

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::passwordauth;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "formbuilder_setup", id => "passwordauth", hook(type => "formbuilder_setup", id => "passwordauth",

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::poll;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "preprocess", id => "poll", call => \&preprocess); hook(type => "preprocess", id => "poll", call => \&preprocess);

View File

@ -7,7 +7,7 @@ package IkiWiki::Plugin::polygen;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
use File::Find; use File::Find;
sub import { #{{{ sub import { #{{{

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::postsparkline;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
IkiWiki::loadplugin('sparkline'); IkiWiki::loadplugin('sparkline');
@ -37,7 +37,7 @@ sub preprocess (@) { #{{{
my @list; my @list;
foreach my $page (keys %pagesources) { foreach my $page (keys %pagesources) {
next if $page eq $params{page}; next if $page eq $params{page};
if (pagespec_match($page, $params{pages}, $params{page})) { if (pagespec_match($page, $params{pages}, location => $params{page})) {
push @list, $page; push @list, $page;
} }
} }

View File

@ -1,6 +1,6 @@
#!/usr/bin/perl #!/usr/bin/perl
package IkiWiki::Plugin::prettydate; package IkiWiki::Plugin::prettydate;
use IkiWiki; use IkiWiki 2.00;
use warnings; use warnings;
no warnings 'redefine'; no warnings 'redefine';
use strict; use strict;

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::rawhtml;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
$config{wiki_file_prune_regexps} = [ grep { !m/\\\.x\?html\?\$/ } @{$config{wiki_file_prune_regexps}} ]; $config{wiki_file_prune_regexps} = [ grep { !m/\\\.x\?html\?\$/ } @{$config{wiki_file_prune_regexps}} ];

View File

@ -18,7 +18,7 @@ package IkiWiki::Plugin::rst;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
use IPC::Open2; use IPC::Open2;
# Simple python script, maybe it should be implemented using an external script. # Simple python script, maybe it should be implemented using an external script.

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::search;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "getopt", id => "hyperestraier", hook(type => "getopt", id => "hyperestraier",

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::shortcut;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "checkconfig", id => "shortcut", call => \&checkconfig); hook(type => "checkconfig", id => "shortcut", call => \&checkconfig);

View File

@ -6,7 +6,7 @@ package IkiWiki::Plugin::sidebar;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate); hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate);

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::signinedit;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "canedit", id => "signinedit", call => \&canedit, hook(type => "canedit", id => "signinedit", call => \&canedit,

View File

@ -6,7 +6,7 @@ package IkiWiki::Plugin::skeleton;
use warnings; use warnings;
use strict; use strict;
use IkiWiki '1.02'; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "getopt", id => "skeleton", call => \&getopt); hook(type => "getopt", id => "skeleton", call => \&getopt);

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::smiley;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
my %smileys; my %smileys;
my $smiley_regexp; my $smiley_regexp;

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::sparkline;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
use IPC::Open2; use IPC::Open2;
my $match_num=qr/[-+]?[0-9]+(?:\.[0-9]+)?/; my $match_num=qr/[-+]?[0-9]+(?:\.[0-9]+)?/;

View File

@ -3,8 +3,7 @@ package IkiWiki::Plugin::table;
use warnings; use warnings;
use strict; use strict;
use IkiWiki 2.00;
use IkiWiki;
sub import { #{{{ sub import { #{{{
hook(type => "preprocess", id => "table", call => \&preprocess); hook(type => "preprocess", id => "table", call => \&preprocess);

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::tag;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
my %tags; my %tags;

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::template;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
use HTML::Template; use HTML::Template;
use Encode; use Encode;

View File

@ -6,7 +6,7 @@ package IkiWiki::Plugin::textile;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "htmlize", id => "txtl", call => \&htmlize); hook(type => "htmlize", id => "txtl", call => \&htmlize);

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::toc;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
use HTML::Parser; use HTML::Parser;
sub import { #{{{ sub import { #{{{

View File

@ -3,7 +3,7 @@ package IkiWiki::Plugin::toggle;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
# Here's the javascript that makes this possible. A key feature is the use # Here's the javascript that makes this possible. A key feature is the use
# of css to hide toggleables, to avoid any flashing on page load. The css # of css to hide toggleables, to avoid any flashing on page load. The css

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::typography;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
IkiWiki::hook(type => "sanitize", id => "typography", call => \&sanitize); IkiWiki::hook(type => "sanitize", id => "typography", call => \&sanitize);

View File

@ -4,7 +4,7 @@ package IkiWiki::Plugin::wikitext;
use warnings; use warnings;
use strict; use strict;
use IkiWiki; use IkiWiki 2.00;
sub import { #{{{ sub import { #{{{
hook(type => "htmlize", id => "wiki", call => \&htmlize); hook(type => "htmlize", id => "wiki", call => \&htmlize);

View File

@ -365,7 +365,7 @@ sub refresh () { #{{{
foreach my $file (keys %rendered, @del) { foreach my $file (keys %rendered, @del) {
next if $f eq $file; next if $f eq $file;
my $page=pagename($file); my $page=pagename($file);
if (pagespec_match($page, $depends{$p}, $p)) { if (pagespec_match($page, $depends{$p}, location => $p)) {
debug(sprintf(gettext("rendering %s, which depends on %s"), $f, $page)); debug(sprintf(gettext("rendering %s, which depends on %s"), $f, $page));
render($f); render($f);
$rendered{$f}=1; $rendered{$f}=1;

View File

@ -92,11 +92,8 @@ sub set_banned_users (@) { #{{{
return userinfo_store($userinfo); return userinfo_store($userinfo);
} #}}} } #}}}
# Global used to pass information into the PageSpec function.
our $committer;
sub commit_notify_list ($@) { #{{{ sub commit_notify_list ($@) { #{{{
$committer=shift; my $committer=shift;
my @pages = map pagename($_), @_; my @pages = map pagename($_), @_;
my @ret; my @ret;
@ -107,7 +104,9 @@ sub commit_notify_list ($@) { #{{{
length $userinfo->{$user}->{subscriptions} && length $userinfo->{$user}->{subscriptions} &&
exists $userinfo->{$user}->{email} && exists $userinfo->{$user}->{email} &&
length $userinfo->{$user}->{email} && length $userinfo->{$user}->{email} &&
grep { pagespec_match($_, $userinfo->{$user}->{subscriptions}, "") } grep { pagespec_match($_,
$userinfo->{$user}->{subscriptions},
user => $committer) }
map pagename($_), @_) { map pagename($_), @_) {
push @ret, $userinfo->{$user}->{email}; push @ret, $userinfo->{$user}->{email};
} }
@ -180,13 +179,4 @@ sub send_commit_mails ($$$@) { #{{{
} }
} #}}} } #}}}
package IkiWiki::PageSpec;
sub match_user ($$$) { #{{{
shift;
my $user=shift;
return $user eq $committer;
} #}}}
1 1

9
debian/changelog vendored
View File

@ -22,8 +22,15 @@ ikiwiki (1.51) UNRELEASED; urgency=low
* Avoid .svn directories when installing from svn checkout. * Avoid .svn directories when installing from svn checkout.
* Fix sending of commit mails when new pages are added via the web. * Fix sending of commit mails when new pages are added via the web.
* Add user(name) to the PageSpec for commit subscriptions. * Add user(name) to the PageSpec for commit subscriptions.
* pagespec_match() has changed to take named parameters, to better allow
for extended pagespecs. The old calling convention will still work for
back-compat for now.
* The calling convention for functions in the IkiWiki::PageSpec namespace
has changed so they are passed named parameters.
* Plugin interface version increased to 2.00 since I don't anticipate any
more interface changes before 2.0.
-- Joey Hess <joeyh@debian.org> Thu, 26 Apr 2007 20:25:53 -0400 -- Joey Hess <joeyh@debian.org> Thu, 26 Apr 2007 22:18:47 -0400
ikiwiki (1.50) unstable; urgency=low ikiwiki (1.50) unstable; urgency=low

View File

@ -20,6 +20,8 @@ being edited.
## Registering plugins ## Registering plugins
All plugins should `use IkiWiki` to import the ikiwiki plugin interface. All plugins should `use IkiWiki` to import the ikiwiki plugin interface.
It's a good idea to include the version number of the plugin interface that
your plugin expects: `use IkiWiki 2.00`
Plugins should, when imported, call `hook()` to hook into ikiwiki's Plugins should, when imported, call `hook()` to hook into ikiwiki's
processing. The function uses named parameters, and use varies depending on processing. The function uses named parameters, and use varies depending on
@ -316,12 +318,15 @@ page created from it. (Ie, it appends ".html".)
Makes the specified page depend on the specified [[PageSpec]]. Makes the specified page depend on the specified [[PageSpec]].
#### `pagespec_match($$;$)` #### `pagespec_match($$;@)`
Passed a page name, a [[PageSpec]], and the location the [[PageSpec]] should Passed a page name, and [[PageSpec]], returns true if the [[PageSpec]]
be matched against, returns true if the [[PageSpec]] matches the page. (If matches the page.
the third parameter is not passed, relative PageSpecs will match relative to
the top of the wiki.) Additional named parameters can be passed, to further limit the match.
The most often used is "location", which specifies the location the
PageSpec should match against. If not passed, relative PageSpecs will match
relative to the top of the wiki.
#### `bestlink($$)` #### `bestlink($$)`
@ -441,6 +446,6 @@ It's also possible to write plugins that add new functions to
[[PageSpecs|PageSpec]]. Such a plugin should add a function to the [[PageSpecs|PageSpec]]. Such a plugin should add a function to the
IkiWiki::PageSpec package, that is named `match_foo`, where "foo()" is IkiWiki::PageSpec package, that is named `match_foo`, where "foo()" is
how it will be accessed in a [[PageSpec]]. The function will be passed how it will be accessed in a [[PageSpec]]. The function will be passed
three parameters: The name of the page being matched, the thing to match two parameters: The name of the page being matched, and the thing to match
against, and the page that the matching is occuring on. It should return against. It may also be passed additional, named parameters. It should return
true if the page matches. true if the page matches.

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-04-26 20:28-0400\n" "POT-Creation-Date: 2007-04-26 22:52-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -119,7 +119,7 @@ msgstr ""
msgid "There are no broken links!" msgid "There are no broken links!"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/conditional.pm:20 #: ../IkiWiki/Plugin/conditional.pm:17
msgid "\"test\" and \"then\" parameters are required" msgid "\"test\" and \"then\" parameters are required"
msgstr "" msgstr ""
@ -397,23 +397,23 @@ msgstr ""
msgid "failed to run php" msgid "failed to run php"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/table.pm:22 #: ../IkiWiki/Plugin/table.pm:21
msgid "cannot find file" msgid "cannot find file"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/table.pm:45 #: ../IkiWiki/Plugin/table.pm:44
msgid "unknown data format" msgid "unknown data format"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/table.pm:53 #: ../IkiWiki/Plugin/table.pm:52
msgid "empty data" msgid "empty data"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/table.pm:73 #: ../IkiWiki/Plugin/table.pm:72
msgid "Direct data download" msgid "Direct data download"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/table.pm:106 #: ../IkiWiki/Plugin/table.pm:105
#, perl-format #, perl-format
msgid "parse fail at line %d: %s" msgid "parse fail at line %d: %s"
msgstr "" msgstr ""
@ -513,7 +513,7 @@ msgstr ""
#. translators: A list of one or more pages that were changed, #. translators: A list of one or more pages that were changed,
#. translators: And the name of the user making the change. #. translators: And the name of the user making the change.
#. translators: This is used as the subject of a commit email. #. translators: This is used as the subject of a commit email.
#: ../IkiWiki/UserInfo.pm:146 #: ../IkiWiki/UserInfo.pm:145
#, perl-format #, perl-format
msgid "update of %s's %s by %s" msgid "update of %s's %s by %s"
msgstr "" msgstr ""

View File

@ -1,29 +1,30 @@
#!/usr/bin/perl #!/usr/bin/perl
use warnings; use warnings;
use strict; use strict;
use Test::More tests => 46; use Test::More tests => 49;
BEGIN { use_ok("IkiWiki"); } BEGIN { use_ok("IkiWiki"); }
ok(pagespec_match("foo", "*", "")); ok(pagespec_match("foo", "*"));
ok(pagespec_match("page", "?ag?", "")); ok(pagespec_match("page", "?ag?"));
ok(! pagespec_match("page", "?a?g?", "")); ok(! pagespec_match("page", "?a?g?"));
ok(pagespec_match("foo.png", "*.*", "")); ok(pagespec_match("foo.png", "*.*"));
ok(! pagespec_match("foo", "*.*", "")); ok(! pagespec_match("foo", "*.*"));
ok(pagespec_match("foo", "foo or bar", ""), "simple list"); ok(pagespec_match("foo", "foo or bar"), "simple list");
ok(pagespec_match("bar", "foo or bar", ""), "simple list 2"); ok(pagespec_match("bar", "foo or bar"), "simple list 2");
ok(pagespec_match("foo", "f?? and !foz", "")); ok(pagespec_match("foo", "f?? and !foz"));
ok(! pagespec_match("foo", "f?? and !foo", "")); ok(! pagespec_match("foo", "f?? and !foo"));
ok(! pagespec_match("foo", "* and !foo", "")); ok(! pagespec_match("foo", "* and !foo"));
ok(! pagespec_match("foo", "foo and !foo", "")); ok(! pagespec_match("foo", "foo and !foo"));
ok(! pagespec_match("foo.png", "* and !*.*", "")); ok(! pagespec_match("foo.png", "* and !*.*"));
ok(pagespec_match("foo", "(bar or ((meep and foo) or (baz or foo) or beep))", "")); ok(pagespec_match("foo", "(bar or ((meep and foo) or (baz or foo) or beep))"));
ok(! pagespec_match("a/foo", "foo", "a/b"), "nonrelative fail"); ok(! pagespec_match("a/foo", "foo", location => "a/b"), "nonrelative fail");
ok(! pagespec_match("foo", "./*", "a/b"), "relative fail"); ok(! pagespec_match("foo", "./*", location => "a/b"), "relative fail");
ok(pagespec_match("a/foo", "./*", "a/b"), "relative"); ok(pagespec_match("a/foo", "./*", location => "a/b"), "relative");
ok(pagespec_match("a/b/foo", "./*", "a/b"), "relative 2"); ok(pagespec_match("a/b/foo", "./*", location => "a/b"), "relative 2");
ok(pagespec_match("foo", "./*", "a"), "relative toplevel"); ok(pagespec_match("a/foo", "./*", "a/b"), "relative oldstyle call");
ok(pagespec_match("foo/bar", "*", "baz"), "absolute"); ok(pagespec_match("foo", "./*", location => "a"), "relative toplevel");
ok(pagespec_match("foo/bar", "*", location => "baz"), "absolute");
# The link and backlink stuff needs this. # The link and backlink stuff needs this.
$config{userdir}=""; $config{userdir}="";
@ -37,16 +38,16 @@ $links{"done"}=[];
$links{"examples/softwaresite/bugs/fails_to_frobnicate"}=[qw{done}]; $links{"examples/softwaresite/bugs/fails_to_frobnicate"}=[qw{done}];
$links{"examples/softwaresite/bugs/done"}=[]; $links{"examples/softwaresite/bugs/done"}=[];
ok(pagespec_match("foo", "link(bar)", ""), "link"); ok(pagespec_match("foo", "link(bar)"), "link");
ok(! pagespec_match("foo", "link(quux)", ""), "failed link"); ok(! pagespec_match("foo", "link(quux)"), "failed link");
ok(pagespec_match("bugs/foo", "link(done)", "bugs/done"), "link match to bestlink"); ok(pagespec_match("bugs/foo", "link(done)", location => "bugs/done"), "link match to bestlink");
ok(! pagespec_match("examples/softwaresite/bugs/done", "link(done)", ok(! pagespec_match("examples/softwaresite/bugs/done", "link(done)",
"bugs/done"), "link match to bestlink"); location => "bugs/done"), "link match to bestlink");
ok(pagespec_match("examples/softwaresite/bugs/fails_to_frobnicate", ok(pagespec_match("examples/softwaresite/bugs/fails_to_frobnicate",
"link(./done)", "examples/softwaresite/bugs/done"), "link relative"); "link(./done)", location => "examples/softwaresite/bugs/done"), "link relative");
ok(! pagespec_match("foo", "link(./bar)", "foo/bar"), "link relative fail"); ok(! pagespec_match("foo", "link(./bar)", location => "foo/bar"), "link relative fail");
ok(pagespec_match("bar", "backlink(foo)", ""), "backlink"); ok(pagespec_match("bar", "backlink(foo)"), "backlink");
ok(! pagespec_match("quux", "backlink(foo)", ""), "failed backlink"); ok(! pagespec_match("quux", "backlink(foo)"), "failed backlink");
$IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006 $IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006
$IkiWiki::pagectime{bar}=1154532695; # after $IkiWiki::pagectime{bar}=1154532695; # after
@ -63,6 +64,9 @@ ok(! pagespec_match("foo", "creation_day(3)"), "other day");
ok(! pagespec_match("foo", "no_such_function(foo)"), "foo"); ok(! pagespec_match("foo", "no_such_function(foo)"), "foo");
ok(pagespec_match("foo", "foo and user(bar)", user => "bar"), "user");
ok(! pagespec_match("foo", "foo and user(bar)", user => "baz"), "user fail");
# old style globlists # old style globlists
ok(pagespec_match("foo", "foo bar"), "simple list"); ok(pagespec_match("foo", "foo bar"), "simple list");
ok(pagespec_match("bar", "foo bar"), "simple list 2"); ok(pagespec_match("bar", "foo bar"), "simple list 2");