our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
bestlink htmllink readfile writefile pagetype srcfile pagename
displaytime will_render gettext urlto targetpage
- add_underlay pagetitle titlepage linkpage
+ add_underlay pagetitle titlepage linkpage newpagefile
%config %links %pagestate %wikistate %renderedfiles
%pagesources %destsources);
our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
safe => 0, # changing requires manual transition
rebuild => 1,
},
+ indexpages => {
+ type => "boolean",
+ default => 0,
+ description => "use page/index.mdwn source files",
+ safe => 1,
+ rebuild => 1,
+ },
discussion => {
type => "boolean",
default => 1,
my $type=pagetype($file);
my $page=$file;
$page=~s/\Q.$type\E*$// if defined $type && !$hooks{htmlize}{$type}{keepextension};
+ if ($config{indexpages} && $page=~/(.*)\/index$/) {
+ $page=$1;
+ }
return $page;
} #}}}
+sub newpagefile ($$) { #{{{
+ my $page=shift;
+ my $type=shift;
+
+ if (! $config{indexpages} || $page eq 'index') {
+ return $page.".".$type;
+ }
+ else {
+ return $page."/index.".$type;
+ }
+} #}}}
+
sub targetpage ($$) { #{{{
my $page=shift;
my $ext=shift;
-
- if (! $config{usedirs} || $page =~ /^index$/ ) {
+
+ my $targetpage='';
+ run_hooks(targetpage => sub {
+ $targetpage=shift->(
+ page => $page,
+ ext => $ext,
+ );
+ });
+
+ if (defined $targetpage && (length($targetpage) > 0)) {
+ return $targetpage;
+ }
+ elsif (! $config{usedirs} || $page eq 'index') {
return $page.".".$ext;
- } else {
+ }
+ else {
return $page."/index.".$ext;
}
} #}}}
sub add_underlay ($) { #{{{
my $dir=shift;
- if ($dir=~/^\//) {
- unshift @{$config{underlaydirs}}, $dir;
+ if ($dir !~ /^\//) {
+ $dir="$config{underlaydir}/../$dir";
}
- else {
- unshift @{$config{underlaydirs}}, "$config{underlaydir}/../$dir";
+
+ if (! grep { $_ eq $dir } @{$config{underlaydirs}}) {
+ unshift @{$config{underlaydirs}}, $dir;
}
return 1;
# Important security check.
if (-e "$config{destdir}/$dest" && ! $config{rebuild} &&
- ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}})) {
+ ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}}, @{$wikistate{editpage}{previews}})) {
error("$config{destdir}/$dest independently created, not overwriting with version from $page");
}
sub bestlink ($$) { #{{{
my $page=shift;
my $link=shift;
+ my $res=undef;
my $cwd=$page;
if ($link=~s/^\/+//) {
$l.=$link;
if (exists $links{$l}) {
- return $l;
+ $res=$l;
}
elsif (exists $pagecase{lc $l}) {
- return $pagecase{lc $l};
+ $res=$pagecase{lc $l};
}
- } while $cwd=~s{/?[^/]+$}{};
+ } while ($cwd=~s{/?[^/]+$}{} && ! defined $res);
- if (length $config{userdir}) {
+ if (! defined $res && length $config{userdir}) {
my $l = "$config{userdir}/".lc($link);
if (exists $links{$l}) {
- return $l;
+ $res=$l;
}
elsif (exists $pagecase{lc $l}) {
- return $pagecase{lc $l};
+ $res=$pagecase{lc $l};
}
}
- #print STDERR "warning: page $page, broken link: $link\n";
- return "";
+ if (defined $res) {
+ run_hooks(tweakbestlink => sub {
+ $res=shift->(
+ page => $page,
+ link => $res);
+ });
+ return $res;
+ }
+ else {
+ #print STDERR "warning: page $page, broken link: $link\n";
+ return "";
+ }
} #}}}
sub isinlinableimage ($) { #{{{
$url =~ s!/index.$config{htmlext}$!/!;
}
+ run_hooks(tweakurlpath => sub {
+ $url=shift->(url => $url);
+ });
+
# Ensure url is not an empty link, and
# if it's relative, make that explicit to avoid colon confusion.
if ($url !~ /^\//) {
}
} #}}}
+sub match_user ($$;@) { #{{{
+ shift;
+ my $user=shift;
+ my %params=@_;
+
+ if (! exists $params{user}) {
+ return IkiWiki::FailReason->new("no user specified");
+ }
+
+ if (defined $params{user} && lc $params{user} eq lc $user) {
+ return IkiWiki::SuccessReason->new("user is $user");
+ }
+ elsif (! defined $params{user}) {
+ return IkiWiki::FailReason->new("not logged in");
+ }
+ else {
+ return IkiWiki::FailReason->new("user is $params{user}, not $user");
+ }
+} #}}}
+
+sub match_admin ($$;@) { #{{{
+ shift;
+ shift;
+ my %params=@_;
+
+ if (! exists $params{user}) {
+ return IkiWiki::FailReason->new("no user specified");
+ }
+
+ if (defined $params{user} && IkiWiki::is_admin($params{user})) {
+ return IkiWiki::SuccessReason->new("user is an admin");
+ }
+ elsif (! defined $params{user}) {
+ return IkiWiki::FailReason->new("not logged in");
+ }
+ else {
+ return IkiWiki::FailReason->new("user is not an admin");
+ }
+} #}}}
+
+sub match_ip ($$;@) { #{{{
+ shift;
+ my $ip=shift;
+ my %params=@_;
+
+ if (! exists $params{ip}) {
+ return IkiWiki::FailReason->new("no IP specified");
+ }
+
+ if (defined $params{ip} && lc $params{ip} eq lc $ip) {
+ return IkiWiki::SuccessReason->new("IP is $ip");
+ }
+ else {
+ return IkiWiki::FailReason->new("IP is $params{ip}, not $ip");
+ }
+} #}}}
+
1