summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2010-04-20 18:19:00 -0400
committerJoey Hess <joey@kitenet.net>2010-04-20 18:19:00 -0400
commit34e8c78c1c9bf65564c1a3086584158e5c3cc415 (patch)
treeba95100ac77e203def8c1529a9c128e85b8a7818 /IkiWiki/Plugin
parent59ceeb5621ae0ae2bcb7501c6ac0c7a06562a7cc (diff)
parent64946f91982d85bb301cc9241459939c657d0eb9 (diff)
Merge branch 'master' into autotag
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/attachment.pm2
-rw-r--r--IkiWiki/Plugin/autoindex.pm14
-rw-r--r--IkiWiki/Plugin/bzr.pm24
-rw-r--r--IkiWiki/Plugin/comments.pm24
-rw-r--r--IkiWiki/Plugin/darcs.pm2
-rw-r--r--IkiWiki/Plugin/editpage.pm7
-rw-r--r--IkiWiki/Plugin/passwordauth.pm12
-rw-r--r--IkiWiki/Plugin/rename.pm5
-rw-r--r--IkiWiki/Plugin/search.pm2
9 files changed, 50 insertions, 42 deletions
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm
index ad1dd9bca..8c3ff887a 100644
--- a/IkiWiki/Plugin/attachment.pm
+++ b/IkiWiki/Plugin/attachment.pm
@@ -137,7 +137,7 @@ sub formbuilder (@) {
$filename=linkpage(IkiWiki::possibly_foolish_untaint(
attachment_location($form->field('page')).
IkiWiki::basename($filename)));
- if (IkiWiki::file_pruned($filename, $config{srcdir})) {
+ if (IkiWiki::file_pruned($filename)) {
error(gettext("bad attachment filename"));
}
diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm
index c71d73349..0dd76259e 100644
--- a/IkiWiki/Plugin/autoindex.pm
+++ b/IkiWiki/Plugin/autoindex.pm
@@ -36,18 +36,22 @@ sub refresh () {
my (%pages, %dirs);
foreach my $dir ($config{srcdir}, @{$config{underlaydirs}}, $config{underlaydir}) {
+ require File::Spec;
+ $dir=File::Spec->canonpath($dir);
+
find({
no_chdir => 1,
wanted => sub {
- $_=decode_utf8($_);
- if (IkiWiki::file_pruned($_, $dir)) {
+ my $file=File::Spec->canonpath(decode_utf8($_));
+ return if $file eq $dir;
+ $file=~s/^\Q$dir\E\/?//;
+ return unless length $file;
+ if (IkiWiki::file_pruned($file)) {
$File::Find::prune=1;
}
elsif (! -l $_) {
- my ($f)=/$config{wiki_file_regexp}/; # untaint
+ my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
return unless defined $f;
- $f=~s/^\Q$dir\E\/?//;
- return unless length $f;
return if $f =~ /\._([^.]+)$/; # skip internal page
if (! -d _) {
$pages{pagename($f)}=1;
diff --git a/IkiWiki/Plugin/bzr.pm b/IkiWiki/Plugin/bzr.pm
index f79ca7c8f..e7c1b8d8e 100644
--- a/IkiWiki/Plugin/bzr.pm
+++ b/IkiWiki/Plugin/bzr.pm
@@ -286,14 +286,10 @@ sub rcs_diff ($) {
}
}
-sub rcs_getctime ($) {
- my ($file) = @_;
-
+sub extract_timestamp (@) {
# XXX filename passes through the shell here, should try to avoid
# that just in case
- my @cmdline = ("bzr", "log", "--limit", '1', "$config{srcdir}/$file");
- open (my $out, "@cmdline |");
-
+ open (my $out, "@_ |");
my @log = bzr_log($out);
if (length @log < 1) {
@@ -303,12 +299,22 @@ sub rcs_getctime ($) {
eval q{use Date::Parse};
error($@) if $@;
- my $ctime = str2time($log[0]->{"timestamp"});
- return $ctime;
+ my $time = str2time($log[0]->{"timestamp"});
+ return $time;
+}
+
+sub rcs_getctime ($) {
+ my ($file) = @_;
+
+ my @cmdline = ("bzr", "log", "--forward", "--limit", '1', "$config{srcdir}/$file");
+ return extract_timestamp(@cmdline);
}
sub rcs_getmtime ($) {
- error "rcs_getmtime is not implemented for bzr\n"; # TODO
+ my ($file) = @_;
+
+ my @cmdline = ("bzr", "log", "--limit", '1', "$config{srcdir}/$file");
+ return extract_timestamp(@cmdline);
}
1
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 0aa043215..58bd4b851 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -338,7 +338,7 @@ sub editcomment ($$) {
my $page = $form->field('page');
$page = IkiWiki::possibly_foolish_untaint($page);
if (! defined $page || ! length $page ||
- IkiWiki::file_pruned($page, $config{srcdir})) {
+ IkiWiki::file_pruned($page)) {
error(gettext("bad page name"));
}
@@ -548,7 +548,7 @@ sub commentmoderation ($$) {
# pending comment before untainting.
my ($f)= $id =~ /$config{wiki_file_regexp}/;
if (! defined $f || ! length $f ||
- IkiWiki::file_pruned($f, $config{srcdir})) {
+ IkiWiki::file_pruned($f)) {
error("illegal file");
}
@@ -644,18 +644,14 @@ sub comments_pending () {
find({
no_chdir => 1,
wanted => sub {
- $_=decode_utf8($_);
- if (IkiWiki::file_pruned($_, $dir)) {
- $File::Find::prune=1;
- }
- elsif (! -l $_ && ! -d _) {
- $File::Find::prune=0;
- my ($f)=/$config{wiki_file_regexp}/; # untaint
- if (defined $f && $f =~ /\Q._comment\E$/) {
- my $ctime=(stat($f))[10];
- $f=~s/^\Q$dir\E\/?//;
- push @ret, [$f, $ctime];
- }
+ my $file=decode_utf8($_);
+ $file=~s/^\Q$dir\E\/?//;
+ return if ! length $file || IkiWiki::file_pruned($file)
+ || -l $_ || -d _ || $file !~ /\Q._comment\E$/;
+ my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
+ if (defined $f) {
+ my $ctime=(stat($_))[10];
+ push @ret, [$f, $ctime];
}
}
}, $dir);
diff --git a/IkiWiki/Plugin/darcs.pm b/IkiWiki/Plugin/darcs.pm
index c1d6661d3..f17fadcb1 100644
--- a/IkiWiki/Plugin/darcs.pm
+++ b/IkiWiki/Plugin/darcs.pm
@@ -63,7 +63,7 @@ sub file_in_vc ($$) {
}
my $found=0;
while (<DARCS_MANIFEST>) {
- $found = 1, last if /^(\.\/)?$file$/;
+ $found = 1 if /^(\.\/)?$file$/;
}
close(DARCS_MANIFEST) or error("'darcs query manifest' exited " . $?);
diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
index 44fe5514a..26e38abc1 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -92,9 +92,9 @@ sub cgi_editpage ($$) {
# wiki_file_regexp.
my ($page)=$form->field('page')=~/$config{wiki_file_regexp}/;
$page=possibly_foolish_untaint($page);
- my $absolute=($page =~ s#^/+##);
+ my $absolute=($page =~ s#^/+##); # absolute name used to force location
if (! defined $page || ! length $page ||
- file_pruned($page, $config{srcdir})) {
+ file_pruned($page)) {
error(gettext("bad page name"));
}
@@ -220,8 +220,7 @@ sub cgi_editpage ($$) {
my $best_loc;
if (! defined $from || ! length $from ||
$from ne $form->field('from') ||
- file_pruned($from, $config{srcdir}) ||
- $from=~/^\// ||
+ file_pruned($from) ||
$absolute ||
$form->submitted) {
@page_locs=$best_loc=$page;
diff --git a/IkiWiki/Plugin/passwordauth.pm b/IkiWiki/Plugin/passwordauth.pm
index 4848b47bb..baddca093 100644
--- a/IkiWiki/Plugin/passwordauth.pm
+++ b/IkiWiki/Plugin/passwordauth.pm
@@ -105,11 +105,13 @@ sub formbuilder_setup (@) {
my $session=$params{session};
my $cgi=$params{cgi};
- if ($form->title eq "signin" || $form->title eq "register" || $cgi->param("do") eq "register") {
+ my $do_register=defined $cgi->param("do") && $cgi->param("do") eq "register";
+
+ if ($form->title eq "signin" || $form->title eq "register" || $do_register) {
$form->field(name => "name", required => 0);
$form->field(name => "password", type => "password", required => 0);
- if ($form->submitted eq "Register" || $form->submitted eq "Create Account" || $cgi->param("do") eq "register") {
+ if ($form->submitted eq "Register" || $form->submitted eq "Create Account" || $do_register) {
$form->field(name => "confirm_password", type => "password");
$form->field(name => "account_creation_password", type => "password")
if (defined $config{account_creation_password} &&
@@ -247,8 +249,10 @@ sub formbuilder (@) {
my $cgi=$params{cgi};
my $buttons=$params{buttons};
+ my $do_register=defined $cgi->param("do") && $cgi->param("do") eq "register";
+
if ($form->title eq "signin" || $form->title eq "register") {
- if (($form->submitted && $form->validate) || $cgi->param("do") eq "register") {
+ if (($form->submitted && $form->validate) || $do_register) {
if ($form->submitted eq 'Login') {
$session->param("name", $form->field("name"));
IkiWiki::cgi_postsignin($cgi, $session);
@@ -311,7 +315,7 @@ sub formbuilder (@) {
$form->field(name => "name", required => 0);
push @$buttons, "Reset Password";
}
- elsif ($form->submitted eq "Register" || $cgi->param("do") eq "register") {
+ elsif ($form->submitted eq "Register" || $do_register) {
@$buttons="Create Account";
}
}
diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm
index 1a9da6363..69e615ead 100644
--- a/IkiWiki/Plugin/rename.pm
+++ b/IkiWiki/Plugin/rename.pm
@@ -63,9 +63,8 @@ sub check_canrename ($$$$$$) {
error(gettext("no change to the file name was specified"));
}
- # Must be a legal filename, and not absolute.
- if (IkiWiki::file_pruned($destfile, $config{srcdir}) ||
- $destfile=~/^\//) {
+ # Must be a legal filename.
+ if (IkiWiki::file_pruned($destfile)) {
error(sprintf(gettext("illegal name")));
}
diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm
index c0e8703d8..a1e7026ca 100644
--- a/IkiWiki/Plugin/search.pm
+++ b/IkiWiki/Plugin/search.pm
@@ -70,7 +70,7 @@ sub index (@) {
# A unique pageterm is used to identify the document for a page.
my $pageterm=pageterm($params{page});
- return $params{content} unless defined $pageterm;
+ return unless defined $pageterm;
my $db=xapiandb();
my $doc=Search::Xapian::Document->new();