summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/404.pm3
-rw-r--r--IkiWiki/Plugin/comments.pm23
-rw-r--r--IkiWiki/Plugin/git.pm18
-rw-r--r--IkiWiki/Plugin/inline.pm11
-rw-r--r--IkiWiki/Plugin/mercurial.pm4
5 files changed, 43 insertions, 16 deletions
diff --git a/IkiWiki/Plugin/404.pm b/IkiWiki/Plugin/404.pm
index 5550ea7d1..bae9e15d1 100644
--- a/IkiWiki/Plugin/404.pm
+++ b/IkiWiki/Plugin/404.pm
@@ -67,7 +67,8 @@ sub cgi_page_from_404 ($$$) {
sub cgi ($) {
my $cgi=shift;
- if ($ENV{REDIRECT_STATUS} eq '404') {
+ if (exists $ENV{REDIRECT_STATUS} &&
+ $ENV{REDIRECT_STATUS} eq '404') {
my $page = cgi_page_from_404($ENV{REDIRECT_URL},
$config{url}, $config{usedirs});
IkiWiki::Plugin::goto::cgi_goto($cgi, $page);
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index ee53dbc91..98f9f8b3d 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -224,7 +224,7 @@ sub preprocess {
if ($params{page} =~ m/\/(\Q$config{comments_pagename}\E\d+)$/) {
$pagestate{$page}{meta}{permalink} = urlto(IkiWiki::dirname($params{page}), undef, 1).
- "#".$params{page};
+ "#".page_to_id($params{page});
}
eval q{use Date::Parse};
@@ -490,7 +490,8 @@ sub editcomment ($$) {
# Jump to the new comment on the page.
# The trailing question mark tries to avoid broken
# caches and get the most recent version of the page.
- IkiWiki::redirect($cgi, urlto($page, undef, 1)."?updated#$location");
+ IkiWiki::redirect($cgi, urlto($page, undef, 1).
+ "?updated#".page_to_id($location));
}
else {
@@ -672,7 +673,7 @@ sub previewcomment ($$$) {
sub commentsshown ($) {
my $page=shift;
- return ! pagespec_match($page, "*/$config{comments_pagename}*",
+ return ! pagespec_match($page, "internal(*/$config{comments_pagename}*)",
location => $page) &&
pagespec_match($page, $config{comments_pagespec},
location => $page);
@@ -759,6 +760,10 @@ sub pagetemplate (@) {
if (!exists $commentstate{$page}) {
return;
}
+
+ if ($template->query(name => 'commentid')) {
+ $template->param(commentid => page_to_id($page));
+ }
if ($template->query(name => 'commentuser')) {
$template->param(commentuser =>
@@ -808,6 +813,18 @@ sub unique_comment_location ($) {
return $location;
}
+sub page_to_id ($) {
+ # Converts a comment page name into a unique, legal html id
+ # addtibute value, that can be used as an anchor to link to the
+ # comment.
+ my $page=shift;
+
+ eval q{use Digest::MD5 'md5_hex'};
+ error($@) if $@;
+
+ return "comment-".md5_hex($page);
+}
+
package IkiWiki::PageSpec;
sub match_postcomment ($$;@) {
diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm
index 042c69f5a..68b114a73 100644
--- a/IkiWiki/Plugin/git.pm
+++ b/IkiWiki/Plugin/git.pm
@@ -136,14 +136,16 @@ sub safe_git (&@) {
}
# In parent.
+ # git output is probably utf-8 encoded, but may contain
+ # other encodings or invalidly encoded stuff. So do not rely
+ # on the normal utf-8 IO layer, decode it by hand.
+ binmode($OUT);
+
my @lines;
while (<$OUT>) {
+ $_=decode_utf8($_, 0);
+
chomp;
-
- # check for invalid utf-8, and toss it back to avoid crashes
- if (! utf8::valid($_)) {
- $_=encode_utf8($_);
- }
push @lines, $_;
}
@@ -447,7 +449,7 @@ sub rcs_commit_staged ($$$) {
# Set the commit author and email to the web committer.
my %env=%ENV;
if (defined $user || defined $ipaddr) {
- my $u=defined $user ? $user : $ipaddr;
+ my $u=encode_utf8(defined $user ? $user : $ipaddr);
$ENV{GIT_AUTHOR_NAME}=$u;
$ENV{GIT_AUTHOR_EMAIL}="$u\@web";
}
@@ -592,8 +594,8 @@ sub rcs_getctime ($) {
# Remove srcdir prefix
$file =~ s/^\Q$config{srcdir}\E\/?//;
- my $sha1 = git_sha1($file);
- my $ci = git_commit_info($sha1, 1);
+ my @sha1s = run_or_non('git', 'rev-list', 'HEAD', '--', $file);
+ my $ci = git_commit_info($sha1s[$#sha1s], 1);
my $ctime = $ci->{'author_epoch'};
debug("ctime for '$file': ". localtime($ctime));
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 2205ebffc..9d7d4b0fd 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -194,6 +194,13 @@ sub preprocess_inline (@) {
if (exists $params{sort} && $params{sort} eq 'title') {
@list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list;
}
+ elsif (exists $params{sort} && $params{sort} eq 'title_natural') {
+ eval q{use Sort::Naturally};
+ if ($@) {
+ error(gettext("Sort::Naturally needed for title_natural sort"));
+ }
+ @list=sort { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) } @list;
+ }
elsif (exists $params{sort} && $params{sort} eq 'mtime') {
@list=sort { $pagemtime{$b} <=> $pagemtime{$a} } @list;
}
@@ -274,8 +281,8 @@ sub preprocess_inline (@) {
}
}
- my $rssurl=basename($feedbase."rss".$feednum) if $feeds && $rss;
- my $atomurl=basename($feedbase."atom".$feednum) if $feeds && $atom;
+ my $rssurl=abs2rel($feedbase."rss".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $rss;
+ my $atomurl=abs2rel($feedbase."atom".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $atom;
my $ret="";
diff --git a/IkiWiki/Plugin/mercurial.pm b/IkiWiki/Plugin/mercurial.pm
index 6c4855e57..11fdec529 100644
--- a/IkiWiki/Plugin/mercurial.pm
+++ b/IkiWiki/Plugin/mercurial.pm
@@ -236,7 +236,7 @@ sub rcs_getctime ($) {
# XXX filename passes through the shell here, should try to avoid
# that just in case
- my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v", "-l", '1',
+ my @cmdline = ("hg", "-R", $config{srcdir}, "log", "-v",
"--style", "default", "$config{srcdir}/$file");
open (my $out, "@cmdline |");
@@ -249,7 +249,7 @@ sub rcs_getctime ($) {
eval q{use Date::Parse};
error($@) if $@;
- my $ctime = str2time($log[0]->{"date"});
+ my $ctime = str2time($log[$#log]->{"date"});
return $ctime;
}