aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/CGI.pm14
-rw-r--r--IkiWiki/Plugin/comments.pm10
-rw-r--r--IkiWiki/Plugin/conditional.pm6
-rw-r--r--IkiWiki/Plugin/edittemplate.pm19
-rw-r--r--IkiWiki/Plugin/git.pm17
-rw-r--r--IkiWiki/Plugin/highlight.pm34
-rw-r--r--IkiWiki/Plugin/inline.pm8
-rw-r--r--IkiWiki/Plugin/linkmap.pm17
-rw-r--r--IkiWiki/Plugin/trail.pm7
9 files changed, 110 insertions, 22 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index c0d8f598b..cb83319e6 100644
--- a/IkiWiki/CGI.pm
+++ b/IkiWiki/CGI.pm
@@ -110,11 +110,23 @@ sub decode_cgi_utf8 ($) {
}
}
+sub safe_decode_utf8 ($) {
+ my $octets = shift;
+ # call decode_utf8 on >= 5.20 only if it's not already decoded,
+ # otherwise it balks, on < 5.20, always call it
+ if ($] < 5.02 || !Encode::is_utf8($octets)) {
+ return decode_utf8($octets);
+ }
+ else {
+ return $octets;
+ }
+}
+
sub decode_form_utf8 ($) {
if ($] >= 5.01) {
my $form = shift;
foreach my $f ($form->field) {
- my @value=map { decode_utf8($_) } $form->field($f);
+ my @value=map { safe_decode_utf8($_) } $form->field($f);
$form->field(name => $f,
value => \@value,
force => 1,
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index a0ca9f32e..98ae13810 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -438,6 +438,16 @@ sub editcomment ($$) {
$page));
}
+ # There's no UI to get here, but someone might construct the URL,
+ # leading to a comment that exists in the repository but isn't
+ # shown
+ if (!pagespec_match($page, $config{comments_pagespec},
+ location => $page)) {
+ error(sprintf(gettext(
+ "comments on page '%s' are not allowed"),
+ $page));
+ }
+
if (pagespec_match($page, $config{comments_closed_pagespec},
location => $page)) {
error(sprintf(gettext(
diff --git a/IkiWiki/Plugin/conditional.pm b/IkiWiki/Plugin/conditional.pm
index 0a3d7fb4c..b450f1a0a 100644
--- a/IkiWiki/Plugin/conditional.pm
+++ b/IkiWiki/Plugin/conditional.pm
@@ -33,11 +33,15 @@ sub preprocess_if (@) {
# An optimisation to avoid needless looping over every page
# for simple uses of some of the tests.
$params{test} =~ /^([\s\!()]*((enabled|sourcepage|destpage|included)\([^)]*\)|(and|or))[\s\!()]*)+$/) {
- add_depends($params{page}, "($params{test}) and $params{page}");
$result=pagespec_match($params{page}, $params{test},
location => $params{page},
sourcepage => $params{page},
destpage => $params{destpage});
+ my $i = $result->influences;
+ foreach my $k (keys %$i) {
+ # minor optimization: influences are always simple dependencies
+ $IkiWiki::depends_simple{$params{page}}{lc $k} |= $i->{$k};
+ }
}
else {
$result=pagespec_match_list($params{page}, $params{test},
diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm
index e3ce5e3d9..c2a8da29f 100644
--- a/IkiWiki/Plugin/edittemplate.pm
+++ b/IkiWiki/Plugin/edittemplate.pm
@@ -139,6 +139,25 @@ sub filltemplate ($$) {
$template->param(name => $page);
+ if ($template->query(name => 'uuid')) {
+ my $uuid;
+ if (open(my $fh, "<", "/proc/sys/kernel/random/uuid")) {
+ $uuid = <$fh>;
+ chomp $uuid;
+ close $fh;
+ }
+ else {
+ eval {
+ require UUID::Tiny;
+ $uuid = UUID::Tiny::create_uuid_as_string(UUID::Tiny::UUID_V4());
+ };
+ }
+ $template->param(uuid => $uuid);
+ }
+
+ my $time = time();
+ $template->param(time => IkiWiki::date_3339($time));
+
return $template->output;
}
diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm
index 4b0e5a86d..75b89e476 100644
--- a/IkiWiki/Plugin/git.pm
+++ b/IkiWiki/Plugin/git.pm
@@ -467,6 +467,11 @@ sub git_commit_info ($;$) {
sub rcs_find_changes ($) {
my $oldrev=shift;
+ # Note that git log will sometimes show files being added that
+ # don't exist. Particularly, git merge -s ours can result in a
+ # merge commit where some files were not really added.
+ # This is why the code below verifies that the files really
+ # exist.
my @raw_lines = run_or_die('git', 'log',
'--pretty=raw', '--raw', '--abbrev=40', '--always', '-c',
'--no-renames', , '--reverse',
@@ -482,12 +487,16 @@ sub rcs_find_changes ($) {
foreach my $i (@{$ci->{details}}) {
my $file=$i->{file};
if ($i->{sha1_to} eq $nullsha) {
- delete $changed{$file};
- $deleted{$file}=1;
+ if (! -e "$config{srcdir}/$file") {
+ delete $changed{$file};
+ $deleted{$file}=1;
+ }
}
else {
- delete $deleted{$file};
- $changed{$file}=1;
+ if (-e "$config{srcdir}/$file") {
+ delete $deleted{$file};
+ $changed{$file}=1;
+ }
}
}
}
diff --git a/IkiWiki/Plugin/highlight.pm b/IkiWiki/Plugin/highlight.pm
index fbe7ddff4..ce919748a 100644
--- a/IkiWiki/Plugin/highlight.pm
+++ b/IkiWiki/Plugin/highlight.pm
@@ -60,14 +60,22 @@ sub checkconfig () {
}
if (! exists $config{filetypes_conf}) {
- $config{filetypes_conf}=
- ($data_dir ? $data_dir->getConfDir() : "/etc/highlight/")
- . "filetypes.conf";
+ if (! $data_dir ) {
+ $config{filetypes_conf}= "/etc/highlight/filetypes.conf";
+ } elsif ( $data_dir -> can('searchFile') ) {
+ # 3.18 +
+ $config{filetypes_conf}=
+ $data_dir -> searchFile("filetypes.conf");
+ } else {
+ # 3.9 +
+ $config{filetypes_conf}=
+ $data_dir -> getConfDir() . "/filetypes.conf";
+ }
}
+ # note that this is only used for old versions of highlight
+ # where $data_dir will not be defined.
if (! exists $config{langdefdir}) {
- $config{langdefdir}=
- ($data_dir ? $data_dir->getLangPath("")
- : "/usr/share/highlight/langDefs");
+ $config{langdefdir}= "/usr/share/highlight/langDefs";
}
if (exists $config{tohighlight} && read_filetypes()) {
@@ -147,17 +155,27 @@ sub read_filetypes () {
}
+sub searchlangdef {
+ my $lang=shift;
+
+ if ($data_dir) {
+ return $data_dir->getLangPath($lang . ".lang");
+ } else {
+ return "$config{langdefdir}/$lang.lang";
+ }
+
+}
# Given a filename extension, determines the language definition to
# use to highlight it.
sub ext2langfile ($) {
my $ext=shift;
- my $langfile="$config{langdefdir}/$ext.lang";
+ my $langfile=searchlangdef($ext);
return $langfile if exists $highlighters{$langfile};
read_filetypes() unless $filetypes_read;
if (exists $ext2lang{$ext}) {
- return "$config{langdefdir}/$ext2lang{$ext}.lang";
+ return searchlangdef($ext2lang{$ext});
}
# If a language only has one common extension, it will not
# be listed in filetypes, so check the langfile.
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 123dfd364..f578526cc 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -329,8 +329,12 @@ sub preprocess_inline (@) {
my $ret="";
- if (length $config{cgiurl} && ! $params{preview} && (exists $params{rootpage} ||
- (exists $params{postform} && yesno($params{postform}))) &&
+ my $postform = (exists $params{rootpage});
+ if (exists $params{postform}) {
+ $postform = yesno($params{postform});
+ }
+
+ if (length $config{cgiurl} && ! $params{preview} && $postform &&
IkiWiki->can("cgi_editpage")) {
# Add a blog post form, with feed buttons.
my $formtemplate=template_depends("blogpost.tmpl", $params{page}, blind_cache => 1);
diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm
index ac26e072e..b5ef1a137 100644
--- a/IkiWiki/Plugin/linkmap.pm
+++ b/IkiWiki/Plugin/linkmap.pm
@@ -5,6 +5,7 @@ use warnings;
use strict;
use IkiWiki 3.00;
use IPC::Open2;
+use HTML::Entities;
sub import {
hook(type => "getsetup", id => "linkmap", call => \&getsetup);
@@ -22,6 +23,18 @@ sub getsetup () {
my $mapnum=0;
+sub pageescape {
+ my $item = shift;
+ # encoding explicitly in case ikiwiki is configured to accept <> or &
+ # in file names
+ my $title = pagetitle($item, 1);
+ # it would not be necessary to encode *all* the html entities (<> would
+ # be sufficient, &" probably a good idea), as dot accepts utf8, but it
+ # isn't bad either
+ $title = encode_entities($title);
+ return("<$title>");
+}
+
sub preprocess (@) {
my %params=@_;
@@ -63,7 +76,7 @@ sub preprocess (@) {
my $show=sub {
my $item=shift;
if (! $shown{$item}) {
- print OUT "\"$item\" [shape=box,href=\"$mapitems{$item}\"];\n";
+ print OUT pageescape($item)." [shape=box,href=\"$mapitems{$item}\"];\n";
$shown{$item}=1;
}
};
@@ -74,7 +87,7 @@ sub preprocess (@) {
foreach my $endpoint ($item, $link) {
$show->($endpoint);
}
- print OUT "\"$item\" -> \"$link\";\n";
+ print OUT pageescape($item)." -> ".pageescape($link).";\n";
}
}
print OUT "}\n";
diff --git a/IkiWiki/Plugin/trail.pm b/IkiWiki/Plugin/trail.pm
index d5fb2b5d6..476db4dcb 100644
--- a/IkiWiki/Plugin/trail.pm
+++ b/IkiWiki/Plugin/trail.pm
@@ -319,10 +319,9 @@ sub prerender {
}
if (defined $pagestate{$trail}{trail}{sort}) {
- # re-sort
- @$members = pagespec_match_list($trail, 'internal(*)',
- list => $members,
- sort => $pagestate{$trail}{trail}{sort});
+ @$members = IkiWiki::sort_pages(
+ $pagestate{$trail}{trail}{sort},
+ $members);
}
if (IkiWiki::yesno $pagestate{$trail}{trail}{reverse}) {