summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2010-12-20 14:27:21 +0100
committerintrigeri <intrigeri@boum.org>2010-12-20 14:27:21 +0100
commit75196e76b627709a6ecae3fa948e1fba7928a5ce (patch)
tree6aa2baeb9cc68f98ca256ce0ff5cb20909f52ef9 /IkiWiki
parent8c2962ec48ae57605d6d0e297be437a97b6229ca (diff)
parente5ed3c9e3801360cc00ce4f4f325f68ac0770bff (diff)
Merge remote branch 'upstream/master' into prv/po
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/CGI.pm10
-rw-r--r--IkiWiki/Plugin/aggregate.pm11
-rw-r--r--IkiWiki/Plugin/attachment.pm4
-rw-r--r--IkiWiki/Plugin/blogspam.pm12
-rw-r--r--IkiWiki/Plugin/calendar.pm1
-rw-r--r--IkiWiki/Plugin/comments.pm40
-rw-r--r--IkiWiki/Plugin/cutpaste.pm31
-rw-r--r--IkiWiki/Plugin/editpage.pm14
-rw-r--r--IkiWiki/Plugin/edittemplate.pm11
-rw-r--r--IkiWiki/Plugin/external.pm2
-rw-r--r--IkiWiki/Plugin/filecheck.pm3
-rw-r--r--IkiWiki/Plugin/format.pm24
-rw-r--r--IkiWiki/Plugin/git.pm225
-rw-r--r--IkiWiki/Plugin/goto.pm4
-rw-r--r--IkiWiki/Plugin/highlight.pm61
-rw-r--r--IkiWiki/Plugin/htmlbalance.pm2
-rw-r--r--IkiWiki/Plugin/htmlscrubber.pm4
-rw-r--r--IkiWiki/Plugin/htmltidy.pm15
-rw-r--r--IkiWiki/Plugin/httpauth.pm9
-rw-r--r--IkiWiki/Plugin/img.pm9
-rw-r--r--IkiWiki/Plugin/inline.pm76
-rw-r--r--IkiWiki/Plugin/listdirectives.pm2
-rw-r--r--IkiWiki/Plugin/meta.pm25
-rw-r--r--IkiWiki/Plugin/monotone.pm13
-rw-r--r--IkiWiki/Plugin/more.pm5
-rw-r--r--IkiWiki/Plugin/openid.pm8
-rw-r--r--IkiWiki/Plugin/parentlinks.pm2
-rw-r--r--IkiWiki/Plugin/pinger.pm3
-rw-r--r--IkiWiki/Plugin/po.pm112
-rw-r--r--IkiWiki/Plugin/poll.pm6
-rw-r--r--IkiWiki/Plugin/recentchanges.pm84
-rw-r--r--IkiWiki/Plugin/relativedate.pm11
-rw-r--r--IkiWiki/Plugin/remove.pm10
-rw-r--r--IkiWiki/Plugin/rename.pm12
-rw-r--r--IkiWiki/Plugin/search.pm4
-rw-r--r--IkiWiki/Plugin/skeleton.pm.example4
-rw-r--r--IkiWiki/Plugin/sortnaturally.pm1
-rw-r--r--IkiWiki/Plugin/table.pm6
-rw-r--r--IkiWiki/Plugin/template.pm7
-rw-r--r--IkiWiki/Plugin/teximg.pm1
-rw-r--r--IkiWiki/Plugin/theme.pm1
-rw-r--r--IkiWiki/Plugin/toggle.pm11
-rw-r--r--IkiWiki/Plugin/txt.pm38
-rw-r--r--IkiWiki/Plugin/version.pm1
-rw-r--r--IkiWiki/Plugin/websetup.pm10
-rw-r--r--IkiWiki/Plugin/wmd.pm9
-rw-r--r--IkiWiki/Receive.pm65
-rw-r--r--IkiWiki/Render.pm9
-rw-r--r--IkiWiki/Wrapper.pm3
49 files changed, 658 insertions, 373 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index f2a32a958..ede194ff9 100644
--- a/IkiWiki/CGI.pm
+++ b/IkiWiki/CGI.pm
@@ -12,7 +12,7 @@ use Encode;
sub printheader ($) {
my $session=shift;
- if ($config{sslcookie}) {
+ if ($ENV{HTTPS} || $config{sslcookie}) {
print $session->header(-charset => 'utf-8',
-cookie => $session->cookie(-httponly => 1, -secure => 1));
}
@@ -116,7 +116,7 @@ sub cgi_signin ($$;$) {
required => 'NONE',
javascript => 0,
params => $q,
- action => $config{cgiurl},
+ action => cgiurl(),
header => 0,
template => {type => 'div'},
stylesheet => 1,
@@ -198,7 +198,7 @@ sub cgi_prefs ($$) {
required => 'NONE',
javascript => 0,
params => $q,
- action => $config{cgiurl},
+ action => cgiurl(),
template => {type => 'div'},
stylesheet => 1,
fieldsets => [
@@ -231,11 +231,11 @@ sub cgi_prefs ($$) {
if ($form->submitted eq 'Logout') {
$session->delete();
- redirect($q, $config{url});
+ redirect($q, baseurl(undef));
return;
}
elsif ($form->submitted eq 'Cancel') {
- redirect($q, $config{url});
+ redirect($q, baseurl(undef));
return;
}
elsif ($form->submitted eq 'Save Preferences' && $form->validate) {
diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index 7789c4c2a..9b70e5df0 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -210,6 +210,8 @@ sub needsbuild (@) {
markunseen($feed->{sourcepage});
}
}
+
+ return $needsbuild;
}
sub preprocess (@) {
@@ -642,7 +644,14 @@ sub add_page (@) {
$guid->{md5}=$digest;
# Create the page.
- my $template=template($feed->{template}, blind_cache => 1);
+ my $template;
+ eval {
+ $template=template($feed->{template}, blind_cache => 1);
+ };
+ if ($@) {
+ print STDERR gettext("failed to process template:")." $@";
+ return;
+ }
$template->param(title => $params{title})
if defined $params{title} && length($params{title});
$template->param(content => wikiescape(htmlabs($params{content},
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm
index ee105a170..bd93d3718 100644
--- a/IkiWiki/Plugin/attachment.pm
+++ b/IkiWiki/Plugin/attachment.pm
@@ -146,7 +146,7 @@ sub formbuilder (@) {
# Check that the user is allowed to edit a page with the
# name of the attachment.
- IkiWiki::check_canedit($filename, $q, $session, 1);
+ IkiWiki::check_canedit($filename, $q, $session);
# And that the attachment itself is acceptable.
check_canattach($session, $filename, $tempfile);
@@ -242,7 +242,7 @@ sub attachment_list ($) {
push @ret, {
"field-select" => '<input type="checkbox" name="attachment_select" value="'.$f.'" />',
link => htmllink($page, $page, $f, noimageinline => 1),
- size => IkiWiki::Plugin::filecheck::humansize((stat(_))[7]),
+ size => IkiWiki::Plugin::filecheck::humansize((stat($f))[7]),
mtime => displaytime($IkiWiki::pagemtime{$f}),
mtime_raw => $IkiWiki::pagemtime{$f},
};
diff --git a/IkiWiki/Plugin/blogspam.pm b/IkiWiki/Plugin/blogspam.pm
index 8db3780e8..f0b6cb2a2 100644
--- a/IkiWiki/Plugin/blogspam.pm
+++ b/IkiWiki/Plugin/blogspam.pm
@@ -4,6 +4,7 @@ package IkiWiki::Plugin::blogspam;
use warnings;
use strict;
use IkiWiki 3.00;
+use Encode;
my $defaulturl='http://test.blogspam.net:8888/';
@@ -68,6 +69,7 @@ sub checkcontent (@) {
my $url=$defaulturl;
$url = $config{blogspam_server} if exists $config{blogspam_server};
+
my $client = RPC::XML::Client->new($url);
my @options = split(",", $config{blogspam_options})
@@ -90,12 +92,12 @@ sub checkcontent (@) {
my %req=(
ip => $session->remote_addr(),
- comment => defined $params{diff} ? $params{diff} : $params{content},
- subject => defined $params{subject} ? $params{subject} : "",
- name => defined $params{author} ? $params{author} : "",
- link => exists $params{url} ? $params{url} : "",
+ comment => encode_utf8(defined $params{diff} ? $params{diff} : $params{content}),
+ subject => encode_utf8(defined $params{subject} ? $params{subject} : ""),
+ name => encode_utf8(defined $params{author} ? $params{author} : ""),
+ link => encode_utf8(exists $params{url} ? $params{url} : ""),
options => join(",", @options),
- site => $config{url},
+ site => encode_utf8($config{url}),
version => "ikiwiki ".$IkiWiki::version,
);
my $res = $client->send_request('testComment', \%req);
diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm
index bb995d499..c7d2b7c01 100644
--- a/IkiWiki/Plugin/calendar.pm
+++ b/IkiWiki/Plugin/calendar.pm
@@ -491,6 +491,7 @@ sub needsbuild (@) {
}
}
}
+ return $needsbuild;
}
1
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 851f4862e..68ac4cfae 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -237,7 +237,7 @@ sub preprocess {
}
if ($params{page} =~ m/\/\Q$config{comments_pagename}\E\d+_/) {
- $pagestate{$page}{meta}{permalink} = urlto(IkiWiki::dirname($params{page}), undef, 1).
+ $pagestate{$page}{meta}{permalink} = urlto(IkiWiki::dirname($params{page})).
"#".page_to_id($params{page});
}
@@ -301,7 +301,7 @@ sub editcomment ($$) {
required => [qw{editcontent}],
javascript => 0,
params => $cgi,
- action => $config{cgiurl},
+ action => IkiWiki::cgiurl(),
header => 0,
table => 0,
template => { template('editcomment.tmpl') },
@@ -372,7 +372,7 @@ sub editcomment ($$) {
error(gettext("bad page name"));
}
- my $baseurl = urlto($page, undef, 1);
+ my $baseurl = urlto($page);
$form->title(sprintf(gettext("commenting on %s"),
IkiWiki::pagetitle($page)));
@@ -385,8 +385,7 @@ sub editcomment ($$) {
if ($form->submitted eq CANCEL) {
# bounce back to the page they wanted to comment on, and exit.
- # CANCEL need not be considered in future
- IkiWiki::redirect($cgi, urlto($page, undef, 1));
+ IkiWiki::redirect($cgi, $baseurl);
exit;
}
@@ -552,7 +551,7 @@ 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).
+ IkiWiki::redirect($cgi, urlto($page).
"?updated#".page_to_id($location));
}
@@ -656,6 +655,7 @@ sub commentmoderation ($$) {
$template->param(
sid => $session->id,
comments => \@comments,
+ cgiurl => IkiWiki::cgiurl(),
);
IkiWiki::printheader($session);
my $out=$template->output;
@@ -727,6 +727,10 @@ sub previewcomment ($$$) {
my $page=shift;
my $time=shift;
+ # Previewing a comment should implicitly enable comment posting mode.
+ my $oldpostcomment=$postcomment;
+ $postcomment=1;
+
my $preview = IkiWiki::htmlize($location, $page, '_comment',
IkiWiki::linkify($location, $page,
IkiWiki::preprocess($location, $page,
@@ -745,6 +749,8 @@ sub previewcomment ($$$) {
$template->param(have_actions => 0);
+ $postcomment=$oldpostcomment;
+
return $template->output;
}
@@ -804,14 +810,14 @@ sub pagetemplate (@) {
if ($shown) {
if ($template->query(name => 'commentsurl')) {
$template->param(commentsurl =>
- urlto($page, undef, 1).'#comments');
+ urlto($page).'#comments');
}
if ($template->query(name => 'atomcommentsurl') && $config{usedirs}) {
# This will 404 until there are some comments, but I
# think that's probably OK...
$template->param(atomcommentsurl =>
- urlto($page, undef, 1).'comments.atom');
+ urlto($page).'comments.atom');
}
if ($template->query(name => 'commentslink')) {
@@ -941,14 +947,16 @@ sub match_comment ($$;@) {
my $page = shift;
my $glob = shift;
- # To see if it's a comment, check the source file type.
- # Deal with comments that were just deleted.
- my $source=exists $IkiWiki::pagesources{$page} ?
- $IkiWiki::pagesources{$page} :
- $IkiWiki::delpagesources{$page};
- my $type=defined $source ? IkiWiki::pagetype($source) : undef;
- if (! defined $type || $type ne "_comment") {
- return IkiWiki::FailReason->new("$page is not a comment");
+ if (! $postcomment) {
+ # To see if it's a comment, check the source file type.
+ # Deal with comments that were just deleted.
+ my $source=exists $IkiWiki::pagesources{$page} ?
+ $IkiWiki::pagesources{$page} :
+ $IkiWiki::delpagesources{$page};
+ my $type=defined $source ? IkiWiki::pagetype($source) : undef;
+ if (! defined $type || $type ne "_comment") {
+ return IkiWiki::FailReason->new("$page is not a comment");
+ }
}
return match_glob($page, "$glob/*", internal => 1, @_);
diff --git a/IkiWiki/Plugin/cutpaste.pm b/IkiWiki/Plugin/cutpaste.pm
index 4a8817168..0f6ea0b1f 100644
--- a/IkiWiki/Plugin/cutpaste.pm
+++ b/IkiWiki/Plugin/cutpaste.pm
@@ -5,10 +5,9 @@ use warnings;
use strict;
use IkiWiki 3.00;
-my %savedtext;
-
sub import {
hook(type => "getsetup", id => "cutpaste", call => \&getsetup);
+ hook(type => "needsbuild", id => "cutpaste", call => \&needsbuild);
hook(type => "preprocess", id => "cut", call => \&preprocess_cut, scan => 1);
hook(type => "preprocess", id => "copy", call => \&preprocess_copy, scan => 1);
hook(type => "preprocess", id => "paste", call => \&preprocess_paste);
@@ -23,6 +22,22 @@ sub getsetup () {
},
}
+sub needsbuild (@) {
+ my $needsbuild=shift;
+ foreach my $page (keys %pagestate) {
+ if (exists $pagestate{$page}{cutpaste}) {
+ if (exists $pagesources{$page} &&
+ grep { $_ eq $pagesources{$page} } @$needsbuild) {
+ # remove state, will be re-added if
+ # the cut/copy directive is still present
+ # on rebuild.
+ delete $pagestate{$page}{cutpaste};
+ }
+ }
+ }
+ return $needsbuild;
+}
+
sub preprocess_cut (@) {
my %params=@_;
@@ -32,8 +47,7 @@ sub preprocess_cut (@) {
}
}
- $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
- $savedtext{$params{page}}->{$params{id}} = $params{text};
+ $pagestate{$params{page}}{cutpaste}{$params{id}} = $params{text};
return "" if defined wantarray;
}
@@ -47,8 +61,7 @@ sub preprocess_copy (@) {
}
}
- $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
- $savedtext{$params{page}}->{$params{id}} = $params{text};
+ $pagestate{$params{page}}{cutpaste}{$params{id}} = $params{text};
return IkiWiki::preprocess($params{page}, $params{destpage}, $params{text})
if defined wantarray;
@@ -63,15 +76,15 @@ sub preprocess_paste (@) {
}
}
- if (! exists $savedtext{$params{page}}) {
+ if (! exists $pagestate{$params{page}}{cutpaste}) {
error gettext('no text was copied in this page');
}
- if (! exists $savedtext{$params{page}}->{$params{id}}) {
+ if (! exists $pagestate{$params{page}}{cutpaste}{$params{id}}) {
error sprintf(gettext('no text was copied in this page with id %s'), $params{id});
}
return IkiWiki::preprocess($params{page}, $params{destpage},
- $savedtext{$params{page}}->{$params{id}});
+ $pagestate{$params{page}}{cutpaste}{$params{id}});
}
1;
diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
index 1a04a72b5..da071d492 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -75,7 +75,7 @@ sub cgi_editpage ($$) {
required => [qw{editcontent}],
javascript => 0,
params => $q,
- action => $config{cgiurl},
+ action => IkiWiki::cgiurl(),
header => 0,
table => 0,
template => { template("editpage.tmpl") },
@@ -98,7 +98,7 @@ sub cgi_editpage ($$) {
error(gettext("bad page name"));
}
- my $baseurl = urlto($page, undef, 1);
+ my $baseurl = urlto($page);
my $from;
if (defined $form->field('from')) {
@@ -156,13 +156,13 @@ sub cgi_editpage ($$) {
my $previewing=0;
if ($form->submitted eq "Cancel") {
if ($form->field("do") eq "create" && defined $from) {
- redirect($q, urlto($from, undef, 1));
+ redirect($q, urlto($from));
}
elsif ($form->field("do") eq "create") {
- redirect($q, $config{url});
+ redirect($q, baseurl(undef));
}
else {
- redirect($q, urlto($page, undef, 1));
+ redirect($q, $baseurl);
}
exit;
}
@@ -262,7 +262,7 @@ sub cgi_editpage ($$) {
@page_locs=$page;
}
else {
- redirect($q, urlto($page, undef, 1));
+ redirect($q, $baseurl);
exit;
}
}
@@ -434,7 +434,7 @@ sub cgi_editpage ($$) {
else {
# The trailing question mark tries to avoid broken
# caches and get the most recent version of the page.
- redirect($q, urlto($page, undef, 1)."?updated");
+ redirect($q, $baseurl."?updated");
}
}
diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm
index 226f83bb4..061242fd8 100644
--- a/IkiWiki/Plugin/edittemplate.pm
+++ b/IkiWiki/Plugin/edittemplate.pm
@@ -41,6 +41,8 @@ sub needsbuild (@) {
}
}
}
+
+ return $needsbuild;
}
sub preprocess (@) {
@@ -105,9 +107,11 @@ sub formbuilder (@) {
my $template=$pagestate{$registering_page}{edittemplate}{$pagespec};
$form->field(name => "editcontent",
value => filltemplate($template, $page));
- $form->field(name => "type",
- value => pagetype($pagesources{$template}))
+ my $type=pagetype($pagesources{$template})
if $pagesources{$template};
+ $form->field(name => "type",
+ value => $type)
+ if defined $type;
return;
}
}
@@ -130,9 +134,6 @@ sub filltemplate ($$) {
# up a template that doesn't work.
return "[[!pagetemplate ".gettext("failed to process template:")." $@]]";
}
- if (! defined $template) {
- return;
- }
$template->param(name => $page);
diff --git a/IkiWiki/Plugin/external.pm b/IkiWiki/Plugin/external.pm
index ec91c79db..a4cc1dd3c 100644
--- a/IkiWiki/Plugin/external.pm
+++ b/IkiWiki/Plugin/external.pm
@@ -28,7 +28,9 @@ sub import {
$plugins{$plugin}={in => $plugin_read, out => $plugin_write, pid => $pid,
accum => ""};
+
$RPC::XML::ENCODING="utf-8";
+ $RPC::XML::FORCE_STRING_ENCODING="true";
rpc_call($plugins{$plugin}, "import");
}
diff --git a/IkiWiki/Plugin/filecheck.pm b/IkiWiki/Plugin/filecheck.pm
index a78058ffe..4f4e67489 100644
--- a/IkiWiki/Plugin/filecheck.pm
+++ b/IkiWiki/Plugin/filecheck.pm
@@ -148,6 +148,7 @@ sub match_mimetype ($$;@) {
if (! defined $mimetype) {
open(my $file_h, "-|", "file", "-bi", $file);
$mimetype=<$file_h>;
+ chomp $mimetype;
close $file_h;
}
if (! defined $mimetype || $mimetype !~s /;.*//) {
@@ -160,7 +161,7 @@ sub match_mimetype ($$;@) {
}
my $regexp=IkiWiki::glob2re($wanted);
- if ($mimetype!~/^$regexp$/i) {
+ if ($mimetype!~$regexp) {
return IkiWiki::FailReason->new("file MIME type is $mimetype, not $wanted");
}
else {
diff --git a/IkiWiki/Plugin/format.pm b/IkiWiki/Plugin/format.pm
index d54e71131..b596bc0a1 100644
--- a/IkiWiki/Plugin/format.pm
+++ b/IkiWiki/Plugin/format.pm
@@ -29,22 +29,24 @@ sub preprocess (@) {
if (! defined $format || ! defined $text) {
error(gettext("must specify format and text"));
}
+
+ # Other plugins can register htmlizeformat hooks to add support
+ # for page types not suitable for htmlize, or that need special
+ # processing when included via format. Try them until one succeeds.
+ my $ret;
+ IkiWiki::run_hooks(htmlizeformat => sub {
+ $ret=shift->($format, $text)
+ unless defined $ret;
+ });
+
+ if (defined $ret) {
+ return $ret;
+ }
elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
return IkiWiki::htmlize($params{page}, $params{destpage},
$format, $text);
}
else {
- # Other plugins can register htmlizefallback
- # hooks to add support for page types
- # not suitable for htmlize. Try them until
- # one succeeds.
- my $ret;
- IkiWiki::run_hooks(htmlizefallback => sub {
- $ret=shift->($format, $text)
- unless defined $ret;
- });
- return $ret if defined $ret;
-
error(sprintf(gettext("unsupported page format %s"), $format));
}
}
diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm
index d342a7398..3db4af729 100644
--- a/IkiWiki/Plugin/git.pm
+++ b/IkiWiki/Plugin/git.pm
@@ -9,7 +9,7 @@ use open qw{:utf8 :std};
my $sha1_pattern = qr/[0-9a-fA-F]{40}/; # pattern to validate Git sha1sums
my $dummy_commit_msg = 'dummy commit'; # message to skip in recent changes
-my $no_chdir=0;
+my $git_dir=undef;
sub import {
hook(type => "checkconfig", id => "git", call => \&checkconfig);
@@ -27,6 +27,8 @@ sub import {
hook(type => "rcs", id => "rcs_getctime", call => \&rcs_getctime);
hook(type => "rcs", id => "rcs_getmtime", call => \&rcs_getmtime);
hook(type => "rcs", id => "rcs_receive", call => \&rcs_receive);
+ hook(type => "rcs", id => "rcs_preprevert", call => \&rcs_preprevert);
+ hook(type => "rcs", id => "rcs_revert", call => \&rcs_revert);
}
sub checkconfig () {
@@ -162,9 +164,13 @@ sub safe_git (&@) {
if (!$pid) {
# In child.
# Git commands want to be in wc.
- if (! $no_chdir) {
+ if (! defined $git_dir) {
chdir $config{srcdir}
- or error("Cannot chdir to $config{srcdir}: $!");
+ or error("cannot chdir to $config{srcdir}: $!");
+ }
+ else {
+ chdir $git_dir
+ or error("cannot chdir to $git_dir: $!");
}
exec @cmdline or error("Cannot exec '@cmdline': $!");
}
@@ -462,7 +468,7 @@ sub rcs_update () {
# Update working directory.
if (length $config{gitorigin_branch}) {
- run_or_cry('git', 'pull', $config{gitorigin_branch});
+ run_or_cry('git', 'pull', '--prune', $config{gitorigin_branch});
}
}
@@ -490,16 +496,16 @@ sub rcs_commit (@) {
return $conflict if defined $conflict;
}
- rcs_add($params{file});
- return rcs_commit_staged(
- message => $params{message},
- session => $params{session},
- );
+ return rcs_commit_helper(@_);
}
sub rcs_commit_staged (@) {
# Commits all staged changes. Changes can be staged using rcs_add,
# rcs_remove, and rcs_rename.
+ return rcs_commit_helper(@_);
+}
+
+sub rcs_commit_helper (@) {
my %params=@_;
my %env=%ENV;
@@ -540,10 +546,12 @@ sub rcs_commit_staged (@) {
$params{message}.=".";
}
}
- push @opts, '-q';
- # git commit returns non-zero if file has not been really changed.
- # so we should ignore its exit status (hence run_or_non).
- if (run_or_non('git', 'commit', @opts, '-m', $params{message})) {
+ if (exists $params{file}) {
+ push @opts, '--', $params{file};
+ }
+ # git commit returns non-zero if nothing really changed.
+ # So we should ignore its exit status (hence run_or_non).
+ if (run_or_non('git', 'commit', '-m', $params{message}, '-q', @opts)) {
if (length $config{gitorigin_branch}) {
run_or_cry('git', 'push', $config{gitorigin_branch});
}
@@ -682,7 +690,7 @@ sub findtimes ($$) {
if (! keys %time_cache) {
my $date;
foreach my $line (run_or_die('git', 'log',
- '--pretty=format:%ct',
+ '--pretty=format:%at',
'--name-only', '--relative')) {
if (! defined $date && $line =~ /^(\d+)$/) {
$date=$line;
@@ -718,10 +726,15 @@ sub rcs_getmtime ($) {
return findtimes($file, 0);
}
-sub rcs_receive () {
+{
+my $ret;
+sub git_find_root {
# The wiki may not be the only thing in the git repo.
# Determine if it is in a subdirectory by examining the srcdir,
# and its parents, looking for the .git directory.
+
+ return @$ret if defined $ret;
+
my $subdir="";
my $dir=$config{srcdir};
while (! -d "$dir/.git") {
@@ -732,83 +745,139 @@ sub rcs_receive () {
}
}
+ $ret=[$subdir, $dir];
+ return @$ret;
+}
+
+}
+
+sub git_parse_changes {
+ my @changes = @_;
+
+ my ($subdir, $rootdir) = git_find_root();
+ my @rets;
+ foreach my $ci (@changes) {
+ foreach my $detail (@{ $ci->{'details'} }) {
+ my $file = $detail->{'file'};
+
+ # check that all changed files are in the subdir
+ if (length $subdir &&
+ ! ($file =~ s/^\Q$subdir\E//)) {
+ error sprintf(gettext("you are not allowed to change %s"), $file);
+ }
+
+ my ($action, $mode, $path);
+ if ($detail->{'status'} =~ /^[M]+\d*$/) {
+ $action="change";
+ $mode=$detail->{'mode_to'};
+ }
+ elsif ($detail->{'status'} =~ /^[AM]+\d*$/) {
+ $action="add";
+ $mode=$detail->{'mode_to'};
+ }
+ elsif ($detail->{'status'} =~ /^[DAM]+\d*/) {
+ $action="remove";
+ $mode=$detail->{'mode_from'};
+ }
+ else {
+ error "unknown status ".$detail->{'status'};
+ }
+
+ # test that the file mode is ok
+ if ($mode !~ /^100[64][64][64]$/) {
+ error sprintf(gettext("you cannot act on a file with mode %s"), $mode);
+ }
+ if ($action eq "change") {
+ if ($detail->{'mode_from'} ne $detail->{'mode_to'}) {
+ error gettext("you are not allowed to change file modes");
+ }
+ }
+
+ # extract attachment to temp file
+ if (($action eq 'add' || $action eq 'change') &&
+ ! pagetype($file)) {
+ eval q{use File::Temp};
+ die $@ if $@;
+ my $fh;
+ ($fh, $path)=File::Temp::tempfile(undef, UNLINK => 1);
+ my $cmd = "cd $git_dir && ".
+ "git show $detail->{sha1_to} > '$path'";
+ if (system($cmd) != 0) {
+ error("failed writing temp file '$path'.");
+ }
+ }
+
+ push @rets, {
+ file => $file,
+ action => $action,
+ path => $path,
+ };
+ }
+ }
+
+ return @rets;
+}
+
+sub rcs_receive () {
my @rets;
while (<>) {
chomp;
my ($oldrev, $newrev, $refname) = split(' ', $_, 3);
-
+
# only allow changes to gitmaster_branch
if ($refname !~ /^refs\/heads\/\Q$config{gitmaster_branch}\E$/) {
error sprintf(gettext("you are not allowed to change %s"), $refname);
}
-
+
# Avoid chdir when running git here, because the changes
# are in the master git repo, not the srcdir repo.
- # The pre-recieve hook already puts us in the right place.
- $no_chdir=1;
- my @changes=git_commit_info($oldrev."..".$newrev);
- $no_chdir=0;
-
- foreach my $ci (@changes) {
- foreach my $detail (@{ $ci->{'details'} }) {
- my $file = $detail->{'file'};
-
- # check that all changed files are in the
- # subdir
- if (length $subdir &&
- ! ($file =~ s/^\Q$subdir\E//)) {
- error sprintf(gettext("you are not allowed to change %s"), $file);
- }
+ # (Also, if a subdir is involved, we don't want to chdir to
+ # it and only see changes in it.)
+ # The pre-receive hook already puts us in the right place.
+ $git_dir=".";
+ push @rets, git_parse_changes(git_commit_info($oldrev."..".$newrev));
+ $git_dir=undef;
+ }
- my ($action, $mode, $path);
- if ($detail->{'status'} =~ /^[M]+\d*$/) {
- $action="change";
- $mode=$detail->{'mode_to'};
- }
- elsif ($detail->{'status'} =~ /^[AM]+\d*$/) {
- $action="add";
- $mode=$detail->{'mode_to'};
- }
- elsif ($detail->{'status'} =~ /^[DAM]+\d*/) {
- $action="remove";
- $mode=$detail->{'mode_from'};
- }
- else {
- error "unknown status ".$detail->{'status'};
- }
-
- # test that the file mode is ok
- if ($mode !~ /^100[64][64][64]$/) {
- error sprintf(gettext("you cannot act on a file with mode %s"), $mode);
- }
- if ($action eq "change") {
- if ($detail->{'mode_from'} ne $detail->{'mode_to'}) {
- error gettext("you are not allowed to change file modes");
- }
- }
-
- # extract attachment to temp file
- if (($action eq 'add' || $action eq 'change') &&
- ! pagetype($file)) {
- eval q{use File::Temp};
- die $@ if $@;
- my $fh;
- ($fh, $path)=File::Temp::tempfile("XXXXXXXXXX", UNLINK => 1);
- if (system("git show ".$detail->{sha1_to}." > '$path'") != 0) {
- error("failed writing temp file");
- }
- }
+ return reverse @rets;
+}
- push @rets, {
- file => $file,
- action => $action,
- path => $path,
- };
- }
- }
+sub rcs_preprevert ($) {
+ my $rev=shift;
+ my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
+
+ # Examine changes from root of git repo, not from any subdir,
+ # in order to see all changes.
+ my ($subdir, $rootdir) = git_find_root();
+ $git_dir=$rootdir;
+ my @commits=git_commit_info($sha1, 1);
+ $git_dir=undef;
+
+ if (! @commits) {
+ error "unknown commit"; # just in case
}
- return reverse @rets;
+ # git revert will fail on merge commits. Add a nice message.
+ if (exists $commits[0]->{parents} &&
+ @{$commits[0]->{parents}} > 1) {
+ error gettext("you are not allowed to revert a merge");
+ }
+
+ return git_parse_changes(@commits);
+}
+
+sub rcs_revert ($) {
+ # Try to revert the given rev; returns undef on _success_.
+ my $rev = shift;
+ my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
+
+ if (run_or_non('git', 'revert', '--no-commit', $sha1)) {
+ return undef;
+ }
+ else {
+ run_or_die('git', 'reset', '--hard');
+ return sprintf(gettext("Failed to revert commit %s"), $sha1);
+ }
}
1
diff --git a/IkiWiki/Plugin/goto.pm b/IkiWiki/Plugin/goto.pm
index 42d2425ca..0eb83fc20 100644
--- a/IkiWiki/Plugin/goto.pm
+++ b/IkiWiki/Plugin/goto.pm
@@ -52,7 +52,7 @@ sub cgi_goto ($;$) {
IkiWiki::redirect($q, $pagestate{$page}{meta}{permalink});
}
- if (! length $link) {
+ if (! defined $link || ! length $link) {
IkiWiki::cgi_custom_failure(
$q,
"404 Not Found",
@@ -64,7 +64,7 @@ sub cgi_goto ($;$) {
)
}
else {
- IkiWiki::redirect($q, urlto($link, undef, 1));
+ IkiWiki::redirect($q, urlto($link));
}
exit;
diff --git a/IkiWiki/Plugin/highlight.pm b/IkiWiki/Plugin/highlight.pm
index e517ac5c0..9d05e9fcf 100644
--- a/IkiWiki/Plugin/highlight.pm
+++ b/IkiWiki/Plugin/highlight.pm
@@ -6,16 +6,12 @@ use strict;
use IkiWiki 3.00;
use Encode;
-# locations of highlight's files
-my $filetypes="/etc/highlight/filetypes.conf";
-my $langdefdir="/usr/share/highlight/langDefs";
-
sub import {
hook(type => "getsetup", id => "highlight", call => \&getsetup);
hook(type => "checkconfig", id => "highlight", call => \&checkconfig);
# this hook is used by the format plugin
- hook(type => "htmlizefallback", id => "highlight", call =>
- \&htmlizefallback);
+ hook(type => "htmlizeformat", id => "highlight",
+ call => \&htmlizeformat, last => 1);
}
sub getsetup () {
@@ -32,9 +28,29 @@ sub getsetup () {
safe => 1,
rebuild => 1,
},
+ filetypes_conf => {
+ type => "string",
+ example => "/etc/highlight/filetypes.conf",
+ description => "location of highlight's filetypes.conf",
+ safe => 0,
+ rebuild => undef,
+ },
+ langdefdir => {
+ type => "string",
+ example => "/usr/share/highlight/langDefs",
+ description => "location of highlight's langDefs directory",
+ safe => 0,
+ rebuild => undef,
+ },
}
sub checkconfig () {
+ if (! exists $config{filetypes_conf}) {
+ $config{filetypes_conf}="/etc/highlight/filetypes.conf";
+ }
+ if (! exists $config{langdefdir}) {
+ $config{langdefdir}="/usr/share/highlight/langDefs";
+ }
if (exists $config{tohighlight}) {
foreach my $file (split ' ', $config{tohighlight}) {
my @opts = $file=~s/^\.// ?
@@ -63,7 +79,7 @@ sub checkconfig () {
}
}
-sub htmlizefallback {
+sub htmlizeformat {
my $format=lc shift;
my $langfile=ext2langfile($format);
@@ -80,14 +96,29 @@ my %highlighters;
# Parse highlight's config file to get extension => language mappings.
sub read_filetypes () {
- open (IN, $filetypes) || error("$filetypes: $!");
- while (<IN>) {
- chomp;
- if (/^\$ext\((.*)\)=(.*)$/) {
- $ext2lang{$_}=$1 foreach $1, split ' ', $2;
+ open (my $f, $config{filetypes_conf}) || error("$config{filetypes_conf}: $!");
+ local $/=undef;
+ my $config=<$f>;
+ close $f;
+
+ # highlight >= 3.2 format (bind-style)
+ while ($config=~m/Lang\s*=\s*\"([^"]+)\"[,\s]+Extensions\s*=\s*{([^}]+)}/sg) {
+ my $lang=$1;
+ foreach my $bit (split ',', $2) {
+ $bit=~s/.*"(.*)".*/$1/s;
+ $ext2lang{$bit}=$lang;
+ }
+ }
+
+ # highlight < 3.2 format
+ if (! keys %ext2lang) {
+ foreach (split("\n", $config)) {
+ if (/^\$ext\((.*)\)=(.*)$/) {
+ $ext2lang{$_}=$1 foreach $1, split ' ', $2;
+ }
}
}
- close IN;
+
$filetypes_read=1;
}
@@ -97,12 +128,12 @@ sub read_filetypes () {
sub ext2langfile ($) {
my $ext=shift;
- my $langfile="$langdefdir/$ext.lang";
+ my $langfile="$config{langdefdir}/$ext.lang";
return $langfile if exists $highlighters{$langfile};
read_filetypes() unless $filetypes_read;
if (exists $ext2lang{$ext}) {
- return "$langdefdir/$ext2lang{$ext}.lang";
+ return "$config{langdefdir}/$ext2lang{$ext}.lang";
}
# If a language only has one common extension, it will not
# be listed in filetypes, so check the langfile.
diff --git a/IkiWiki/Plugin/htmlbalance.pm b/IkiWiki/Plugin/htmlbalance.pm
index 26f8e494b..da450eea7 100644
--- a/IkiWiki/Plugin/htmlbalance.pm
+++ b/IkiWiki/Plugin/htmlbalance.pm
@@ -43,7 +43,7 @@ sub sanitize (@) {
my @nodes = $tree->disembowel();
foreach my $node (@nodes) {
if (ref $node) {
- $ret .= $node->as_XML();
+ $ret .= $node->as_HTML(undef, '', {});
chomp $ret;
$node->delete();
}
diff --git a/IkiWiki/Plugin/htmlscrubber.pm b/IkiWiki/Plugin/htmlscrubber.pm
index 927792f79..a58a27d52 100644
--- a/IkiWiki/Plugin/htmlscrubber.pm
+++ b/IkiWiki/Plugin/htmlscrubber.pm
@@ -57,8 +57,8 @@ sub sanitize (@) {
if (exists $config{htmlscrubber_skip} &&
length $config{htmlscrubber_skip} &&
- exists $params{destpage} &&
- pagespec_match($params{destpage}, $config{htmlscrubber_skip})) {
+ exists $params{page} &&
+ pagespec_match($params{page}, $config{htmlscrubber_skip})) {
return $params{content};
}
diff --git a/IkiWiki/Plugin/htmltidy.pm b/IkiWiki/Plugin/htmltidy.pm
index e6d377f8a..1108aeb89 100644
--- a/IkiWiki/Plugin/htmltidy.pm
+++ b/IkiWiki/Plugin/htmltidy.pm
@@ -15,6 +15,7 @@ use IPC::Open2;
sub import {
hook(type => "getsetup", id => "tidy", call => \&getsetup);
hook(type => "sanitize", id => "tidy", call => \&sanitize);
+ hook(type => "checkconfig", id => "tidy", call => \&checkconfig);
}
sub getsetup () {
@@ -23,6 +24,18 @@ sub getsetup () {
safe => 1,
rebuild => undef,
},
+ htmltidy => {
+ type => "string",
+ description => "tidy command line",
+ safe => 0, # path
+ rebuild => undef,
+ },
+}
+
+sub checkconfig () {
+ if (! defined $config{htmltidy}) {
+ $config{htmltidy}="tidy -quiet -asxhtml -utf8 --show-body-only yes --show-warnings no --tidy-mark no --markup yes";
+ }
}
sub sanitize (@) {
@@ -31,7 +44,7 @@ sub sanitize (@) {
my $pid;
my $sigpipe=0;
$SIG{PIPE}=sub { $sigpipe=1 };
- $pid=open2(*IN, *OUT, 'tidy -quiet -asxhtml -utf8 --show-body-only yes --show-warnings no --tidy-mark no --markup yes 2>/dev/null');
+ $pid=open2(*IN, *OUT, "$config{htmltidy} 2>/dev/null");
# open2 doesn't respect "use open ':utf8'"
binmode (IN, ':utf8');
diff --git a/IkiWiki/Plugin/httpauth.pm b/IkiWiki/Plugin/httpauth.pm
index 478f67446..cb488449d 100644
--- a/IkiWiki/Plugin/httpauth.pm
+++ b/IkiWiki/Plugin/httpauth.pm
@@ -78,19 +78,14 @@ sub formbuilder_setup (@) {
}
}
-sub test_httpauth_pagespec ($) {
- my $page=shift;
-
- return (
- );
-}
-
sub canedit ($$$) {
my $page=shift;
my $cgi=shift;
my $session=shift;
if (! defined $cgi->remote_user() &&
+ (! defined $session->param("name") ||
+ ! IkiWiki::userinfo_get($session->param("name"), "regdate")) &&
defined $config{httpauth_pagespec} &&
length $config{httpauth_pagespec} &&
defined $config{cgiauthurl} &&
diff --git a/IkiWiki/Plugin/img.pm b/IkiWiki/Plugin/img.pm
index 2375ead89..103f6b2b3 100644
--- a/IkiWiki/Plugin/img.pm
+++ b/IkiWiki/Plugin/img.pm
@@ -152,14 +152,11 @@ sub preprocess (@) {
$imgurl=urlto($imglink, $params{destpage});
}
else {
- $fileurl="$config{url}/$file";
- $imgurl="$config{url}/$imglink";
+ $fileurl=urlto($file);
+ $imgurl=urlto($imglink);
}
- if (exists $params{class}) {
- $params{class}.=" img";
- }
- else {
+ if (! exists $params{class}) {
$params{class}="img";
}
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 715a3d652..b58c8780b 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -104,7 +104,7 @@ sub checkconfig () {
}
sub format (@) {
- my %params=@_;
+ my %params=@_;
# Fill in the inline content generated earlier. This is actually an
# optimisation.
@@ -160,7 +160,7 @@ sub preprocess_inline (@) {
my $rss=(($config{rss} || $config{allowrss}) && exists $params{rss}) ? yesno($params{rss}) : $config{rss};
my $atom=(($config{atom} || $config{allowatom}) && exists $params{atom}) ? yesno($params{atom}) : $config{atom};
my $quick=exists $params{quick} ? yesno($params{quick}) : 0;
- my $feeds=! $nested && (exists $params{feeds} ? yesno($params{feeds}) : !$quick && ! $raw);
+ my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick && ! $raw;
my $emptyfeeds=exists $params{emptyfeeds} ? yesno($params{emptyfeeds}) : 1;
my $feedonly=yesno($params{feedonly});
if (! exists $params{show} && ! $archive) {
@@ -269,7 +269,7 @@ sub preprocess_inline (@) {
}
$params{feedfile}=possibly_foolish_untaint($params{feedfile});
}
- $feedbase=targetpage($params{destpage}, "", $params{feedfile});
+ $feedbase=targetpage($params{page}, "", $params{feedfile});
my $feedid=join("\0", $feedbase, map { $_."\0".$params{$_} } sort keys %params);
if (exists $knownfeeds{$feedid}) {
@@ -300,7 +300,7 @@ sub preprocess_inline (@) {
IkiWiki->can("cgi_editpage")) {
# Add a blog post form, with feed buttons.
my $formtemplate=template_depends("blogpost.tmpl", $params{page}, blind_cache => 1);
- $formtemplate->param(cgiurl => $config{cgiurl});
+ $formtemplate->param(cgiurl => IkiWiki::cgiurl());
$formtemplate->param(rootpage => rootpage(%params));
$formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
$formtemplate->param(atomurl => $atomurl) if $feeds && $atom;
@@ -336,10 +336,7 @@ sub preprocess_inline (@) {
blind_cache => 1);
};
if ($@) {
- error gettext("failed to process template:")." $@";
- }
- if (! $template) {
- error sprintf(gettext("template %s not found"), $params{template}.".tmpl");
+ error sprintf(gettext("failed to process template %s"), $params{template}.".tmpl").": $@";
}
}
my $needcontent=$raw || (!($archive && $quick) && $template->query(name => 'content'));
@@ -509,26 +506,59 @@ sub date_822 ($) {
}
sub absolute_urls ($$) {
- # sucky sub because rss sucks
- my $content=shift;
+ # needed because rss sucks
+ my $html=shift;
my $baseurl=shift;
my $url=$baseurl;
$url=~s/[^\/]+$//;
+ my $urltop; # calculated if needed
+
+ my $ret="";
+
+ eval q{use HTML::Parser; use HTML::Tagset};
+ die $@ if $@;
+ my $p = HTML::Parser->new(api_version => 3);
+ $p->handler(default => sub { $ret.=join("", @_) }, "text");
+ $p->handler(start => sub {
+ my ($tagname, $pos, $text) = @_;
+ if (ref $HTML::Tagset::linkElements{$tagname}) {
+ while (4 <= @$pos) {
+ # use attribute sets from right to left
+ # to avoid invalidating the offsets
+ # when replacing the values
+ my ($k_offset, $k_len, $v_offset, $v_len) =
+ splice(@$pos, -4);
+ my $attrname = lc(substr($text, $k_offset, $k_len));
+ next unless grep { $_ eq $attrname } @{$HTML::Tagset::linkElements{$tagname}};
+ next unless $v_offset; # 0 v_offset means no value
+ my $v = substr($text, $v_offset, $v_len);
+ $v =~ s/^([\'\"])(.*)\1$/$2/;
+ if ($v=~/^#/) {
+ $v=$baseurl.$v; # anchor
+ }
+ elsif ($v=~/^(?!\w+:)[^\/]/) {
+ $v=$url.$v; # relative url
+ }
+ elsif ($v=~/^\//) {
+ if (! defined $urltop) {
+ # what is the non path part of the url?
+ my $top_uri = URI->new($url);
+ $top_uri->path_query(""); # reset the path
+ $urltop = $top_uri->as_string;
+ }
+ $v=$urltop.$v; # url relative to top of site
+ }
+ $v =~ s/\"/&quot;/g; # since we quote with ""
+ substr($text, $v_offset, $v_len) = qq("$v");
+ }
+ }
+ $ret.=$text;
+ }, "tagname, tokenpos, text");
+ $p->parse($html);
+ $p->eof;
- # what is the non path part of the url?
- my $top_uri = URI->new($url);
- $top_uri->path_query(""); # reset the path
- my $urltop = $top_uri->as_string;
-
- $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(#[^"]+)"/$1 href="$baseurl$2"/mig;
- # relative to another wiki page
- $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(?!\w+:)([^\/][^"]*)"/$1 href="$url$2"/mig;
- $content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"(?!\w+:)([^\/][^"]*)"/$1 src="$url$2"/mig;
- # relative to the top of the site
- $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(?!\w+:)(\/[^"]*)"/$1 href="$urltop$2"/mig;
- $content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"(?!\w+:)(\/[^"]*)"/$1 src="$urltop$2"/mig;
- return $content;
+ return $ret;
}
sub genfeed ($$$$$@) {
diff --git a/IkiWiki/Plugin/listdirectives.pm b/IkiWiki/Plugin/listdirectives.pm
index 8a67f7160..835e25388 100644
--- a/IkiWiki/Plugin/listdirectives.pm
+++ b/IkiWiki/Plugin/listdirectives.pm
@@ -64,6 +64,8 @@ sub needsbuild (@) {
}
}
}
+
+ return $needsbuild;
}
sub preprocess (@) {
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index d18585d3d..abc8f1b1a 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -37,12 +37,13 @@ sub needsbuild (@) {
}
}
}
+ return $needsbuild;
}
-sub scrub ($$) {
+sub scrub ($$$) {
if (IkiWiki::Plugin::htmlscrubber->can("sanitize")) {
return IkiWiki::Plugin::htmlscrubber::sanitize(
- content => shift, destpage => shift);
+ content => shift, page => shift, destpage => shift);
}
else {
return shift;
@@ -161,7 +162,7 @@ sub preprocess (@) {
# Metadata handling that happens only during preprocessing pass.
if ($key eq 'permalink') {
if (safeurl($value)) {
- push @{$metaheaders{$page}}, scrub('<link rel="bookmark" href="'.encode_entities($value).'" />', $destpage);
+ push @{$metaheaders{$page}}, scrub('<link rel="bookmark" href="'.encode_entities($value).'" />', $page, $destpage);
}
}
elsif ($key eq 'stylesheet') {
@@ -197,8 +198,12 @@ sub preprocess (@) {
'" rel="openid2.local_id" />' if $delegate ne 1;
}
if (exists $params{"xrds-location"} && safeurl($params{"xrds-location"})) {
- push @{$metaheaders{$page}}, '<meta http-equiv="X-XRDS-Location"'.
- 'content="'.encode_entities($params{"xrds-location"}).'" />';
+ # force url absolute
+ eval q{use URI};
+ error($@) if $@;
+ my $url=URI->new_abs($params{"xrds-location"}, $config{url});
+ push @{$metaheaders{$page}}, '<meta http-equiv="X-XRDS-Location" '.
+ 'content="'.encode_entities($url).'" />';
}
}
elsif ($key eq 'redir') {
@@ -235,7 +240,7 @@ sub preprocess (@) {
my $delay=int(exists $params{delay} ? $params{delay} : 0);
my $redir="<meta http-equiv=\"refresh\" content=\"$delay; URL=$value\" />";
if (! $safe) {
- $redir=scrub($redir, $destpage);
+ $redir=scrub($redir, $page, $destpage);
}
push @{$metaheaders{$page}}, $redir;
}
@@ -245,7 +250,7 @@ sub preprocess (@) {
join(" ", map {
encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\""
} keys %params).
- " />\n", $destpage);
+ " />\n", $page, $destpage);
}
}
elsif ($key eq 'robots') {
@@ -261,12 +266,12 @@ sub preprocess (@) {
push @{$metaheaders{$page}}, scrub('<meta '.$key.'="'.
encode_entities($value).
join(' ', map { "$_=\"$params{$_}\"" } keys %params).
- ' />', $destpage);
+ ' />', $page, $destpage);
}
else {
push @{$metaheaders{$page}}, scrub('<meta name="'.
encode_entities($key).'" content="'.
- encode_entities($value).'" />', $destpage);
+ encode_entities($value).'" />', $page, $destpage);
}
return "";
@@ -350,7 +355,7 @@ sub match {
}
if (defined $val) {
- if ($val=~/^$re$/i) {
+ if ($val=~$re) {
return IkiWiki::SuccessReason->new("$re matches $field of $page", $page => $IkiWiki::DEPEND_CONTENT, "" => 1);
}
else {
diff --git a/IkiWiki/Plugin/monotone.pm b/IkiWiki/Plugin/monotone.pm
index 95fbcee76..75bf2f458 100644
--- a/IkiWiki/Plugin/monotone.pm
+++ b/IkiWiki/Plugin/monotone.pm
@@ -252,9 +252,20 @@ sub get_changed_files ($$) {
my @ret;
my %seen = ();
-
+
+ # we need to strip off the relative path to the source dir
+ # because monotone outputs all file paths absolute according
+ # to the workspace root
+ my $rel_src_dir = $config{'srcdir'};
+ $rel_src_dir =~ s/^\Q$config{'mtnrootdir'}\E\/?//;
+ $rel_src_dir .= "/" if length $rel_src_dir;
+
while ($changes =~ m/\s*(add_file|patch|delete|rename)\s"(.*?)(?<!\\)"\n/sg) {
my $file = $2;
+ # ignore all file changes outside the source dir
+ next unless $file =~ m/^\Q$rel_src_dir\E/;
+ $file =~ s/^\Q$rel_src_dir\E//;
+
# don't add the same file multiple times
if (! $seen{$file}) {
push @ret, $file;
diff --git a/IkiWiki/Plugin/more.pm b/IkiWiki/Plugin/more.pm
index 80e339a1b..6880e366d 100644
--- a/IkiWiki/Plugin/more.pm
+++ b/IkiWiki/Plugin/more.pm
@@ -26,7 +26,10 @@ sub preprocess (@) {
$params{linktext} = $linktext unless defined $params{linktext};
- if ($params{page} ne $params{destpage}) {
+ if ($params{page} ne $params{destpage} &&
+ (! exists $params{pages} ||
+ pagespec_match($params{destpage}, $params{pages},
+ location => $params{page}))) {
return "\n".
htmllink($params{page}, $params{destpage}, $params{page},
linktext => $params{linktext},
diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm
index fae9fb77f..0220a3cf6 100644
--- a/IkiWiki/Plugin/openid.pm
+++ b/IkiWiki/Plugin/openid.pm
@@ -77,7 +77,7 @@ sub openid_selector {
my $template=IkiWiki::template("openid-selector.tmpl");
$template->param(
- cgiurl => $config{cgiurl},
+ cgiurl => IkiWiki::cgiurl(),
(defined $openid_error ? (openid_error => $openid_error) : ()),
(defined $openid_url ? (openid_url => $openid_url) : ()),
($real_cgi_signin ? (nonopenidform => $real_cgi_signin->($q, $session, 1)) : ()),
@@ -148,7 +148,7 @@ sub validate ($$$;$) {
}
my $cgiurl=$config{openid_cgiurl};
- $cgiurl=$config{cgiurl} if ! defined $cgiurl;
+ $cgiurl=IkiWiki::cgiurl() if ! defined $cgiurl;
my $trust_root=$config{openid_realm};
$trust_root=$cgiurl if ! defined $trust_root;
@@ -175,7 +175,7 @@ sub auth ($$) {
IkiWiki::redirect($q, $setup_url);
}
elsif ($csr->user_cancel) {
- IkiWiki::redirect($q, $config{url});
+ IkiWiki::redirect($q, IkiWiki::baseurl(undef));
}
elsif (my $vident = $csr->verified_identity) {
$session->param(name => $vident->url);
@@ -249,7 +249,7 @@ sub getobj ($$) {
}
my $cgiurl=$config{openid_cgiurl};
- $cgiurl=$config{cgiurl} if ! defined $cgiurl;
+ $cgiurl=IkiWiki::cgiurl() if ! defined $cgiurl;
return Net::OpenID::Consumer->new(
ua => $ua,
diff --git a/IkiWiki/Plugin/parentlinks.pm b/IkiWiki/Plugin/parentlinks.pm
index bbd2c5752..203ea13b6 100644
--- a/IkiWiki/Plugin/parentlinks.pm
+++ b/IkiWiki/Plugin/parentlinks.pm
@@ -27,7 +27,7 @@ sub parentlinks ($) {
if (! length $page) {
# dynamic page
return {
- url => $config{url},
+ url => IkiWiki::baseurl(undef),
page => $config{wikiname},
};
}
diff --git a/IkiWiki/Plugin/pinger.pm b/IkiWiki/Plugin/pinger.pm
index c20ecb5d4..932619496 100644
--- a/IkiWiki/Plugin/pinger.pm
+++ b/IkiWiki/Plugin/pinger.pm
@@ -45,6 +45,7 @@ sub needsbuild (@) {
}
}
}
+ return $needsbuild;
}
sub preprocess (@) {
@@ -105,6 +106,8 @@ sub ping {
# only ping when a page was changed, so a ping loop
# will still be avoided.
next if $url=~/^\Q$config{cgiurl}\E/;
+ my $local_cgiurl = IkiWiki::cgiurl();
+ next if $url=~/^\Q$local_cgiurl\E/;
$ua->get($url);
}
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index f3530faf3..79142ed1f 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -25,10 +25,12 @@ use File::Temp;
use Memoize;
use UNIVERSAL;
+my ($master_language_code, $master_language_name);
my %translations;
my @origneedsbuild;
my %origsubs;
my @slavelanguages; # language codes ordered as in config po_slave_languages
+my %slavelanguages; # language code to name lookup
memoize("istranslatable");
memoize("_istranslation");
@@ -89,16 +91,13 @@ sub import {
sub getsetup () {
return
plugin => {
- safe => 0,
+ safe => 1,
rebuild => 1, # format plugin
section => "format",
},
po_master_language => {
type => "string",
- example => {
- 'code' => 'en',
- 'name' => 'English'
- },
+ example => "en|English",
description => "master language (non-PO files)",
safe => 1,
rebuild => 1,
@@ -110,7 +109,7 @@ sub getsetup () {
'es|EspaƱol',
'de|Deutsch'
],
- description => "slave languages (PO files)",
+ description => "slave languages (translated via PO files) format: ll|Langname",
safe => 1,
rebuild => 1,
},
@@ -132,39 +131,49 @@ sub getsetup () {
}
sub checkconfig () {
- foreach my $field (qw{po_master_language}) {
- if (! exists $config{$field} || ! defined $config{$field}) {
- error(sprintf(gettext("Must specify %s when using the %s plugin"),
- $field, 'po'));
+ if (exists $config{po_master_language}) {
+ if (! ref $config{po_master_language}) {
+ ($master_language_code, $master_language_name)=
+ splitlangpair($config{po_master_language});
+ }
+ else {
+ $master_language_code=$config{po_master_language}{code};
+ $master_language_name=$config{po_master_language}{name};
+ $config{po_master_language}=joinlangpair($master_language_code, $master_language_name);
}
}
+ if (! defined $master_language_code) {
+ $master_language_code='en';
+ }
+ if (! defined $master_language_name) {
+ $master_language_name='English';
+ }
if (ref $config{po_slave_languages} eq 'ARRAY') {
- my %slaves;
foreach my $pair (@{$config{po_slave_languages}}) {
- my ($code, $name) = ( $pair =~ /^([a-z]{2})\|(.+)$/ );
- if (!defined $code || !defined $name) {
- error(sprintf(gettext("%s has invalid syntax: must use CODE|NAME"),
- $pair));
+ my ($code, $name)=splitlangpair($pair);
+ if (defined $code && ! exists $slavelanguages{$code}) {
+ push @slavelanguages, $code;
+ $slavelanguages{$code} = $name;
}
- $slaves{$code} = $name;
- push @slavelanguages, $code;
-
}
- $config{po_slave_languages} = \%slaves;
}
elsif (ref $config{po_slave_languages} eq 'HASH') {
+ %slavelanguages=%{$config{po_slave_languages}};
@slavelanguages = sort {
$config{po_slave_languages}->{$a} cmp $config{po_slave_languages}->{$b};
- } keys %{$config{po_slave_languages}};
+ } keys %slavelanguages;
+ $config{po_slave_languages}=[
+ map { joinlangpair($_, $slavelanguages{$_}) } @slavelanguages
+ ]
}
- delete $config{po_slave_languages}{$config{po_master_language}{code}};;
+ delete $slavelanguages{$master_language_code};
map {
islanguagecode($_)
or error(sprintf(gettext("%s is not a valid language code"), $_));
- } ($config{po_master_language}{code}, @slavelanguages);
+ } ($master_language_code, @slavelanguages);
if (! exists $config{po_translatable_pages} ||
! defined $config{po_translatable_pages}) {
@@ -198,11 +207,11 @@ sub checkconfig () {
if -d "$config{underlaydirbase}/po/$ll/$underlay";
}
- if ($config{po_master_language}{code} ne 'en') {
+ if ($master_language_code ne 'en') {
# Add underlay containing translated source files
# for the master language.
- add_underlay("locale/$config{po_master_language}{code}/$underlay")
- if -d "$config{underlaydirbase}/locale/$config{po_master_language}{code}/$underlay";
+ add_underlay("locale/$master_language_code/$underlay")
+ if -d "$config{underlaydirbase}/locale/$master_language_code/$underlay";
}
}
}
@@ -221,6 +230,8 @@ sub needsbuild () {
foreach my $master (keys %translations) {
map add_depends($_, $master), values %{otherlanguages_pages($master)};
}
+
+ return $needsbuild;
}
sub scan (@) {
@@ -510,7 +521,7 @@ sub formbuilder_setup (@) {
if ($form->field("do") eq "create") {
# Warn the user: new pages must be written in master language.
my $template=template("pocreatepage.tmpl");
- $template->param(LANG => $config{po_master_language}{name});
+ $template->param(LANG => $master_language_name);
$form->tmpl_param(message => $template->output);
}
elsif ($form->field("do") eq "edit") {
@@ -599,7 +610,7 @@ sub mybeautify_urlpath ($) {
my $res=$origsubs{'beautify_urlpath'}->($url);
if (defined $config{po_link_to} && $config{po_link_to} eq "negotiated") {
- $res =~ s!/\Qindex.$config{po_master_language}{code}.$config{htmlext}\E$!/!;
+ $res =~ s!/\Qindex.$master_language_code.$config{htmlext}\E$!/!;
$res =~ s!/\Qindex.$config{htmlext}\E$!/!;
map {
$res =~ s!/\Qindex.$_.$config{htmlext}\E$!/!;
@@ -790,7 +801,7 @@ sub _istranslation ($) {
return 0 unless defined $masterpage && defined $lang
&& length $masterpage && length $lang
&& defined $pagesources{$masterpage}
- && defined $config{po_slave_languages}{$lang};
+ && defined $slavelanguages{$lang};
return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang)
if istranslatable($masterpage);
@@ -822,7 +833,7 @@ sub lang ($) {
if (1 < (my ($masterpage, $lang) = _istranslation($page))) {
return $lang;
}
- return $config{po_master_language}{code};
+ return $master_language_code;
}
sub islanguagecode ($) {
@@ -835,7 +846,7 @@ sub otherlanguage_page ($$) {
my $page=shift;
my $code=shift;
- return masterpage($page) if $code eq $config{po_master_language}{code};
+ return masterpage($page) if $code eq $master_language_code;
return masterpage($page) . '.' . $code;
}
@@ -849,9 +860,9 @@ sub otherlanguages_codes ($) {
return \@ret unless istranslation($page) || istranslatable($page);
my $curlang=lang($page);
foreach my $lang
- ($config{po_master_language}{code}, @slavelanguages) {
+ ($master_language_code, @slavelanguages) {
next if $lang eq $curlang;
- if ($lang eq $config{po_master_language}{code} ||
+ if ($lang eq $master_language_code ||
istranslatedto(masterpage($page), $lang)) {
push @ret, $lang;
}
@@ -1006,10 +1017,10 @@ sub percenttranslated ($) {
sub languagename ($) {
my $code=shift;
- return $config{po_master_language}{name}
- if $code eq $config{po_master_language}{code};
- return $config{po_slave_languages}{$code}
- if defined $config{po_slave_languages}{$code};
+ return $master_language_name
+ if $code eq $master_language_code;
+ return $slavelanguages{$code}
+ if defined $slavelanguages{$code};
return;
}
@@ -1020,13 +1031,13 @@ sub otherlanguagesloop ($) {
if (istranslation($page)) {
push @ret, {
url => urlto_with_orig_beautiful_urlpath(masterpage($page), $page),
- code => $config{po_master_language}{code},
- language => $config{po_master_language}{name},
+ code => $master_language_code,
+ language => $master_language_name,
master => 1,
};
}
foreach my $lang (@{otherlanguages_codes($page)}) {
- next if $lang eq $config{po_master_language}{code};
+ next if $lang eq $master_language_code;
my $otherpage = otherlanguage_page($page, $lang);
push @ret, {
url => urlto_with_orig_beautiful_urlpath($otherpage, $page),
@@ -1231,6 +1242,27 @@ sub po4a_options($) {
return %options;
}
+sub splitlangpair ($) {
+ my $pair=shift;
+
+ my ($code, $name) = ( $pair =~ /^([a-z]{2})\|(.+)$/ );
+ if (! defined $code || ! defined $name ||
+ ! length $code || ! length $name) {
+ # not a fatal error to avoid breaking if used with web setup
+ warn sprintf(gettext("%s has invalid syntax: must use CODE|NAME"),
+ $pair);
+ }
+
+ return $code, $name;
+}
+
+sub joinlangpair ($$) {
+ my $code=shift;
+ my $name=shift;
+
+ return "$code|$name";
+}
+
# ,----
# | PageSpecs
# `----
@@ -1265,7 +1297,7 @@ sub match_lang ($$;@) {
my $regexp=IkiWiki::glob2re($wanted);
my $lang=IkiWiki::Plugin::po::lang($page);
- if ($lang !~ /^$regexp$/i) {
+ if ($lang !~ $regexp) {
return IkiWiki::FailReason->new("file language is $lang, not $wanted");
}
else {
diff --git a/IkiWiki/Plugin/poll.pm b/IkiWiki/Plugin/poll.pm
index b333e2cdc..2773486a6 100644
--- a/IkiWiki/Plugin/poll.pm
+++ b/IkiWiki/Plugin/poll.pm
@@ -52,7 +52,7 @@ sub preprocess (@) {
foreach my $choice (@choices) {
if ($open && exists $config{cgiurl}) {
# use POST to avoid robots
- $ret.="<form method=\"POST\" action=\"$config{cgiurl}\">\n";
+ $ret.="<form method=\"POST\" action=\"".IkiWiki::cgiurl()."\">\n";
}
my $percent=$total > 0 ? int($choices{$choice} / $total * 100) : 0;
$ret.="<p>\n";
@@ -103,7 +103,7 @@ sub sessioncgi ($$) {
my $oldchoice=$session->param($choice_param);
if (defined $oldchoice && $oldchoice eq $choice) {
# Same vote; no-op.
- IkiWiki::redirect($cgi, urlto($page, undef, 1));
+ IkiWiki::redirect($cgi, urlto($page));
exit;
}
@@ -153,7 +153,7 @@ sub sessioncgi ($$) {
error($@) if $@;
my $cookie = CGI::Cookie->new(-name=> $session->name, -value=> $session->id);
print $cgi->redirect(-cookie => $cookie,
- -url => urlto($page, undef, 1));
+ -url => urlto($page));
exit;
}
}
diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm
index 758b98348..6fccd16f6 100644
--- a/IkiWiki/Plugin/recentchanges.pm
+++ b/IkiWiki/Plugin/recentchanges.pm
@@ -13,6 +13,7 @@ sub import {
hook(type => "refresh", id => "recentchanges", call => \&refresh);
hook(type => "pagetemplate", id => "recentchanges", call => \&pagetemplate);
hook(type => "htmlize", id => "_change", call => \&htmlize);
+ hook(type => "sessioncgi", id => "recentchanges", call => \&sessioncgi);
# Load goto to fix up links from recentchanges
IkiWiki::loadplugin("goto");
}
@@ -60,6 +61,76 @@ sub refresh ($) {
}
}
+sub sessioncgi ($$) {
+ my ($q, $session) = @_;
+ my $do = $q->param('do');
+ my $rev = $q->param('rev');
+
+ return unless $do eq 'revert' && $rev;
+
+ my @changes=$IkiWiki::hooks{rcs}{rcs_preprevert}{call}->($rev);
+ IkiWiki::check_canchange(
+ cgi => $q,
+ session => $session,
+ changes => \@changes,
+ );
+
+ eval q{use CGI::FormBuilder};
+ error($@) if $@;
+ my $form = CGI::FormBuilder->new(
+ name => "revert",
+ header => 0,
+ charset => "utf-8",
+ method => 'POST',
+ javascript => 0,
+ params => $q,
+ action => IkiWiki::cgiurl(),
+ stylesheet => 1,
+ template => { template('revert.tmpl') },
+ fields => [qw{revertmessage do sid rev}],
+ );
+ my $buttons=["Revert", "Cancel"];
+
+ $form->field(name => "revertmessage", type => "text", size => 80);
+ $form->field(name => "sid", type => "hidden", value => $session->id,
+ force => 1);
+ $form->field(name => "do", type => "hidden", value => "revert",
+ force => 1);
+
+ IkiWiki::decode_form_utf8($form);
+
+ if ($form->submitted eq 'Revert' && $form->validate) {
+ IkiWiki::checksessionexpiry($q, $session, $q->param('sid'));
+ my $message=sprintf(gettext("This reverts commit %s"), $rev);
+ if (defined $form->field('revertmessage') &&
+ length $form->field('revertmessage')) {
+ $message=$form->field('revertmessage')."\n\n".$message;
+ }
+ my $r = $IkiWiki::hooks{rcs}{rcs_revert}{call}->($rev);
+ error $r if defined $r;
+ IkiWiki::disable_commit_hook();
+ IkiWiki::rcs_commit_staged(
+ message => $message,
+ session => $session,
+ );
+ IkiWiki::enable_commit_hook();
+
+ require IkiWiki::Render;
+ IkiWiki::refresh();
+ IkiWiki::saveindex();
+ }
+ elsif ($form->submitted ne 'Cancel') {
+ $form->title(sprintf(gettext("confirm reversion of %s"), $rev));
+ $form->tmpl_param(diff => encode_entities(scalar IkiWiki::rcs_diff($rev)));
+ $form->field(name => "rev", type => "hidden", value => $rev, force => 1);
+ IkiWiki::showform($form, $buttons, $session, $q);
+ exit 0;
+ }
+
+ IkiWiki::redirect($q, urlto($config{recentchangespage}));
+ exit 0;
+}
+
# Enable the recentchanges link.
sub pagetemplate (@) {
my %params=@_;
@@ -107,12 +178,21 @@ sub store ($$$) {
else {
$_->{link} = pagetitle($_->{page});
}
- $_->{baseurl}="$config{url}/" if length $config{url};
+ $_->{baseurl}=IkiWiki::baseurl(undef) if length $config{url};
$_;
} @{$change->{pages}}
];
push @{$change->{pages}}, { link => '...' } if $is_excess;
+
+ if (length $config{cgiurl} &&
+ exists $IkiWiki::hooks{rcs}{rcs_preprevert} &&
+ exists $IkiWiki::hooks{rcs}{rcs_revert}) {
+ $change->{reverturl} = IkiWiki::cgiurl(
+ do => "revert",
+ rev => $change->{rev}
+ );
+ }
$change->{author}=$change->{user};
my $oiduser=eval { IkiWiki::openiduser($change->{user}) };
@@ -146,7 +226,7 @@ sub store ($$$) {
wikiname => $config{wikiname},
);
- $template->param(permalink => "$config{url}/$config{recentchangespage}/#change-".titlepage($change->{rev}))
+ $template->param(permalink => urlto($config{recentchangespage}, undef)."#change-".titlepage($change->{rev}))
if exists $config{url};
IkiWiki::run_hooks(pagetemplate => sub {
diff --git a/IkiWiki/Plugin/relativedate.pm b/IkiWiki/Plugin/relativedate.pm
index 7296889ab..4ae0be861 100644
--- a/IkiWiki/Plugin/relativedate.pm
+++ b/IkiWiki/Plugin/relativedate.pm
@@ -28,18 +28,17 @@ sub format (@) {
if (! ($params{content}=~s!^(<body[^>]*>)!$1.include_javascript($params{page})!em)) {
# no <body> tag, probably in preview mode
- $params{content}=include_javascript($params{page}, 1).$params{content};
+ $params{content}=include_javascript(undef).$params{content};
}
return $params{content};
}
-sub include_javascript ($;$) {
- my $page=shift;
- my $absolute=shift;
+sub include_javascript ($) {
+ my $from=shift;
- return '<script src="'.urlto("ikiwiki/ikiwiki.js", $page, $absolute).
+ return '<script src="'.urlto("ikiwiki/ikiwiki.js", $from).
'" type="text/javascript" charset="utf-8"></script>'."\n".
- '<script src="'.urlto("ikiwiki/relativedate.js", $page, $absolute).
+ '<script src="'.urlto("ikiwiki/relativedate.js", $from).
'" type="text/javascript" charset="utf-8"></script>';
}
diff --git a/IkiWiki/Plugin/remove.pm b/IkiWiki/Plugin/remove.pm
index 95f148183..bc481502a 100644
--- a/IkiWiki/Plugin/remove.pm
+++ b/IkiWiki/Plugin/remove.pm
@@ -42,9 +42,6 @@ sub check_canremove ($$$) {
error(sprintf(gettext("%s is not a file"), $file));
}
- # Must be editable.
- IkiWiki::check_canedit($page, $q, $session);
-
# If a user can't upload an attachment, don't let them delete it.
# This is sorta overkill, but better safe than sorry.
if (! defined pagetype($pagesources{$page})) {
@@ -74,6 +71,7 @@ sub check_canremove ($$$) {
}
}
});
+ return defined $canremove ? $canremove : 1;
}
sub formbuilder_setup (@) {
@@ -102,7 +100,7 @@ sub confirmation_form ($$) {
method => 'POST',
javascript => 0,
params => $q,
- action => $config{cgiurl},
+ action => IkiWiki::cgiurl(),
stylesheet => 1,
fields => [qw{do page}],
);
@@ -121,6 +119,7 @@ sub removal_confirm ($$@) {
my @pages=@_;
foreach my $page (@pages) {
+ IkiWiki::check_canedit($page, $q, $session);
check_canremove($page, $q, $session);
}
@@ -198,6 +197,7 @@ sub sessioncgi ($$) {
# and that the user is allowed to edit(/remove) it.
my @files;
foreach my $page (@pages) {
+ IkiWiki::check_canedit($page, $q, $session);
check_canremove($page, $q, $session);
# This untaint is safe because of the
@@ -240,7 +240,7 @@ sub sessioncgi ($$) {
if (! exists $pagesources{$parent}) {
$parent="index";
}
- IkiWiki::redirect($q, urlto($parent, '/', 1));
+ IkiWiki::redirect($q, urlto($parent));
}
}
else {
diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm
index 61d39d4b5..57747d3c9 100644
--- a/IkiWiki/Plugin/rename.pm
+++ b/IkiWiki/Plugin/rename.pm
@@ -108,6 +108,7 @@ sub check_canrename ($$$$$$) {
}
}
});
+ return defined $canrename ? $canrename : 1;
}
sub rename_form ($$$) {
@@ -125,7 +126,7 @@ sub rename_form ($$$) {
method => 'POST',
javascript => 0,
params => $q,
- action => $config{cgiurl},
+ action => IkiWiki::cgiurl(),
stylesheet => 1,
fields => [qw{do page new_name attachment}],
);
@@ -573,11 +574,10 @@ sub fixlinks ($$$) {
eval { writefile($file, $config{srcdir}, $content) };
next if $@;
my $conflict=IkiWiki::rcs_commit(
- $file,
- sprintf(gettext("update for rename of %s to %s"), $rename->{srcfile}, $rename->{destfile}),
- $token,
- $session->param("name"),
- $session->remote_addr(),
+ file => $file,
+ message => sprintf(gettext("update for rename of %s to %s"), $rename->{srcfile}, $rename->{destfile}),
+ token => $token,
+ session => $session,
);
push @fixedlinks, $page if ! defined $conflict;
}
diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm
index 8fb9dff0c..78eb750b5 100644
--- a/IkiWiki/Plugin/search.pm
+++ b/IkiWiki/Plugin/search.pm
@@ -58,7 +58,7 @@ sub pagetemplate (@) {
if ($template->query(name => "searchform")) {
if (! defined $form) {
my $searchform = template("searchform.tmpl", blind_cache => 1);
- $searchform->param(searchaction => $config{cgiurl});
+ $searchform->param(searchaction => IkiWiki::cgiurl());
$searchform->param(html5 => $config{html5});
$form=$searchform->output;
}
@@ -176,7 +176,7 @@ sub cgi ($) {
# only works for GET requests
chdir("$config{wikistatedir}/xapian") || error("chdir: $!");
$ENV{OMEGA_CONFIG_FILE}="./omega.conf";
- $ENV{CGIURL}=$config{cgiurl},
+ $ENV{CGIURL}=IkiWiki::cgiurl();
IkiWiki::loadindex();
$ENV{HELPLINK}=htmllink("", "", "ikiwiki/searching",
noimageinline => 1, linktext => "Help");
diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example
index 341d67867..7974d5e53 100644
--- a/IkiWiki/Plugin/skeleton.pm.example
+++ b/IkiWiki/Plugin/skeleton.pm.example
@@ -73,7 +73,11 @@ sub refresh () {
}
sub needsbuild ($) {
+ my $needsbuild=shift;
+
debug("skeleton plugin needsbuild");
+
+ return $needsbuild;
}
sub preprocess (@) {
diff --git a/IkiWiki/Plugin/sortnaturally.pm b/IkiWiki/Plugin/sortnaturally.pm
index 62e42767c..b038b2f9a 100644
--- a/IkiWiki/Plugin/sortnaturally.pm
+++ b/IkiWiki/Plugin/sortnaturally.pm
@@ -7,6 +7,7 @@ no warnings;
sub import {
hook(type => "getsetup", id => "sortnaturally", call => \&getsetup);
+ hook(type => "checkconfig", id => "sortnaturally", call => \&checkconfig);
}
sub getsetup {
diff --git a/IkiWiki/Plugin/table.pm b/IkiWiki/Plugin/table.pm
index 2edd1eacd..f3c425a37 100644
--- a/IkiWiki/Plugin/table.pm
+++ b/IkiWiki/Plugin/table.pm
@@ -40,6 +40,9 @@ sub preprocess (@) {
# scan that file too.
return unless exists $params{file};
+ # Preprocess in scan-only mode.
+ IkiWiki::preprocess($params{page}, $params{page}, $params{data}, 1);
+
IkiWiki::run_hooks(scan => sub {
shift->(
page => $params{page},
@@ -47,9 +50,6 @@ sub preprocess (@) {
);
});
- # Preprocess in scan-only mode.
- IkiWiki::preprocess($params{page}, $params{page}, $params{data}, 1);
-
return;
}
diff --git a/IkiWiki/Plugin/template.pm b/IkiWiki/Plugin/template.pm
index db26bfe31..3df06e652 100644
--- a/IkiWiki/Plugin/template.pm
+++ b/IkiWiki/Plugin/template.pm
@@ -41,12 +41,9 @@ sub preprocess (@) {
blind_cache => 1);
};
if ($@) {
- error gettext("failed to process template:")." $@";
- }
- if (! $template) {
- error sprintf(gettext("%s not found"),
+ error sprintf(gettext("failed to process template %s"),
htmllink($params{page}, $params{destpage},
- "/templates/$params{id}"))
+ "/templates/$params{id}"))." $@";
}
$params{basename}=IkiWiki::basename($params{page});
diff --git a/IkiWiki/Plugin/teximg.pm b/IkiWiki/Plugin/teximg.pm
index 521af499f..195792aca 100644
--- a/IkiWiki/Plugin/teximg.pm
+++ b/IkiWiki/Plugin/teximg.pm
@@ -13,6 +13,7 @@ use IkiWiki 3.00;
my $default_prefix = <<EOPREFIX;
\\documentclass{article}
+\\usepackage[utf8]{inputenc}
\\usepackage{amsmath}
\\usepackage{amsfonts}
\\usepackage{amssymb}
diff --git a/IkiWiki/Plugin/theme.pm b/IkiWiki/Plugin/theme.pm
index 03b0816ed..ee94547e9 100644
--- a/IkiWiki/Plugin/theme.pm
+++ b/IkiWiki/Plugin/theme.pm
@@ -60,6 +60,7 @@ sub needsbuild ($) {
$wikistate{theme}{currenttheme}=$config{theme};
}
+ return $needsbuild;
}
1
diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm
index 1f93f87fe..af4d2ba3a 100644
--- a/IkiWiki/Plugin/toggle.pm
+++ b/IkiWiki/Plugin/toggle.pm
@@ -70,19 +70,18 @@ sub format (@) {
$params{content}=~s/<div class="toggleableend">//g;
if (! ($params{content}=~s!^(<body[^>]*>)!$1.include_javascript($params{page})!em)) {
# no <body> tag, probably in preview mode
- $params{content}=include_javascript($params{page}, 1).$params{content};
+ $params{content}=include_javascript(undef).$params{content};
}
}
return $params{content};
}
-sub include_javascript ($;$) {
- my $page=shift;
- my $absolute=shift;
+sub include_javascript ($) {
+ my $from=shift;
- return '<script src="'.urlto("ikiwiki/ikiwiki.js", $page, $absolute).
+ return '<script src="'.urlto("ikiwiki/ikiwiki.js", $from).
'" type="text/javascript" charset="utf-8"></script>'."\n".
- '<script src="'.urlto("ikiwiki/toggle.js", $page, $absolute).
+ '<script src="'.urlto("ikiwiki/toggle.js", $from).
'" type="text/javascript" charset="utf-8"></script>';
}
diff --git a/IkiWiki/Plugin/txt.pm b/IkiWiki/Plugin/txt.pm
index 0d9a0b35b..fcfb68be9 100644
--- a/IkiWiki/Plugin/txt.pm
+++ b/IkiWiki/Plugin/txt.pm
@@ -17,6 +17,7 @@ sub import {
hook(type => "getsetup", id => "txt", call => \&getsetup);
hook(type => "filter", id => "txt", call => \&filter);
hook(type => "htmlize", id => "txt", call => \&htmlize);
+ hook(type => "htmlizeformat", id => "txt", call => \&htmlizeformat);
eval q{use URI::Find};
if (! $@) {
@@ -46,25 +47,42 @@ sub filter (@) {
will_render($params{page}, 'robots.txt');
writefile('robots.txt', $config{destdir}, $content);
}
-
- encode_entities($content, "<>&");
- if ($findurl) {
- my $finder = URI::Find->new(sub {
- my ($uri, $orig_uri) = @_;
- return qq|<a href="$uri">$orig_uri</a>|;
- });
- $finder->find(\$content);
- }
- $content = "<pre>" . $content . "</pre>";
+ return txt2html($content);
}
return $content;
}
+sub txt2html ($) {
+ my $content=shift;
+
+ encode_entities($content, "<>&");
+ if ($findurl) {
+ my $finder = URI::Find->new(sub {
+ my ($uri, $orig_uri) = @_;
+ return qq|<a href="$uri">$orig_uri</a>|;
+ });
+ $finder->find(\$content);
+ }
+ return "<pre>" . $content . "</pre>";
+}
+
# We need this to register the .txt file extension
sub htmlize (@) {
my %params=@_;
return $params{content};
}
+sub htmlizeformat ($$) {
+ my $format=shift;
+ my $content=shift;
+
+ if ($format eq 'txt') {
+ return txt2html($content);
+ }
+ else {
+ return;
+ }
+}
+
1
diff --git a/IkiWiki/Plugin/version.pm b/IkiWiki/Plugin/version.pm
index c13643478..fc265526c 100644
--- a/IkiWiki/Plugin/version.pm
+++ b/IkiWiki/Plugin/version.pm
@@ -37,6 +37,7 @@ sub needsbuild (@) {
}
}
}
+ return $needsbuild;
}
sub preprocess (@) {
diff --git a/IkiWiki/Plugin/websetup.pm b/IkiWiki/Plugin/websetup.pm
index 11b4428e3..6a5190301 100644
--- a/IkiWiki/Plugin/websetup.pm
+++ b/IkiWiki/Plugin/websetup.pm
@@ -219,7 +219,8 @@ sub showfields ($$$@) {
options => [ [ 1 => $description ] ],
fieldset => $section,
);
- if (! $form->submitted) {
+ if (! $form->submitted ||
+ ($info{advanced} && $form->submitted eq 'Advanced Mode')) {
$form->field(name => $name, value => $value);
}
}
@@ -287,7 +288,7 @@ sub showform ($$) {
fieldsets => [
[main => gettext("main")],
],
- action => $config{cgiurl},
+ action => IkiWiki::cgiurl(),
template => {type => 'div'},
stylesheet => 1,
);
@@ -295,6 +296,7 @@ sub showform ($$) {
$form->field(name => "do", type => "hidden", value => "setup",
force => 1);
$form->field(name => "rebuild_asked", type => "hidden");
+ $form->field(name => "showadvanced", type => "hidden");
if ($form->submitted eq 'Basic Mode') {
$form->field(name => "showadvanced", type => "hidden",
@@ -342,7 +344,7 @@ sub showform ($$) {
IkiWiki::decode_form_utf8($form);
if ($form->submitted eq "Cancel") {
- IkiWiki::redirect($cgi, $config{url});
+ IkiWiki::redirect($cgi, IkiWiki::baseurl(undef));
return;
}
elsif (($form->submitted eq 'Save Setup' || $form->submitted eq 'Rebuild Wiki') && $form->validate) {
@@ -473,7 +475,7 @@ sub showform ($$) {
join(" ", @command), $ret).
'</p>';
open(OUT, ">", $config{setupfile}) || error("$config{setupfile}: $!");
- print OUT $oldsetup;
+ print OUT Encode::encode_utf8($oldsetup);
close OUT;
}
diff --git a/IkiWiki/Plugin/wmd.pm b/IkiWiki/Plugin/wmd.pm
index 71d7c9d17..134cfb910 100644
--- a/IkiWiki/Plugin/wmd.pm
+++ b/IkiWiki/Plugin/wmd.pm
@@ -31,14 +31,13 @@ sub formbuilder_setup (@) {
$form->field("do") eq "comment";
$form->tmpl_param("wmd_preview", "<div class=\"wmd-preview\"></div>\n".
- include_javascript(undef, 1));
+ include_javascript(undef));
}
-sub include_javascript ($;$) {
- my $page=shift;
- my $absolute=shift;
+sub include_javascript ($) {
+ my $from=shift;
- my $wmdjs=urlto("wmd/wmd.js", $page, $absolute);
+ my $wmdjs=urlto("wmd/wmd.js", $from);
return <<"EOF"
<script type="text/javascript">
wmd_options = {
diff --git a/IkiWiki/Receive.pm b/IkiWiki/Receive.pm
index fdd463025..c73adfbbb 100644
--- a/IkiWiki/Receive.pm
+++ b/IkiWiki/Receive.pm
@@ -48,10 +48,10 @@ EOF
sub test () {
exit 0 if trusted();
-
+
IkiWiki::lockwiki();
IkiWiki::loadindex();
-
+
# Dummy up a cgi environment to use when calling check_canedit
# and friends.
eval q{use CGI};
@@ -72,63 +72,12 @@ sub test () {
regdate => time,
}) || error("failed adding user");
}
-
- my %newfiles;
-
- foreach my $change (IkiWiki::rcs_receive()) {
- # This untaint is safe because we check file_pruned and
- # wiki_file_regexp.
- my ($file)=$change->{file}=~/$config{wiki_file_regexp}/;
- $file=IkiWiki::possibly_foolish_untaint($file);
- if (! defined $file || ! length $file ||
- IkiWiki::file_pruned($file)) {
- error(gettext("bad file name %s"), $file);
- }
-
- my $type=pagetype($file);
- my $page=pagename($file) if defined $type;
-
- if ($change->{action} eq 'add') {
- $newfiles{$file}=1;
- }
-
- if ($change->{action} eq 'change' ||
- $change->{action} eq 'add') {
- if (defined $page) {
- if (IkiWiki->can("check_canedit")) {
- IkiWiki::check_canedit($page, $cgi, $session);
- next;
- }
- }
- else {
- if (IkiWiki::Plugin::attachment->can("check_canattach")) {
- IkiWiki::Plugin::attachment::check_canattach($session, $file, $change->{path});
- next;
- }
- }
- }
- elsif ($change->{action} eq 'remove') {
- # check_canremove tests to see if the file is present
- # on disk. This will fail is a single commit adds a
- # file and then removes it again. Avoid the problem
- # by not testing the removal in such pairs of changes.
- # (The add is still tested, just to make sure that
- # no data is added to the repo that a web edit
- # could not add.)
- next if $newfiles{$file};
-
- if (IkiWiki::Plugin::remove->can("check_canremove")) {
- IkiWiki::Plugin::remove::check_canremove(defined $page ? $page : $file, $cgi, $session);
- next;
- }
- }
- else {
- error "unknown action ".$change->{action};
- }
-
- error sprintf(gettext("you are not allowed to change %s"), $file);
- }
+ IkiWiki::check_canchange(
+ cgi => $cgi,
+ session => $session,
+ changes => [IkiWiki::rcs_receive()]
+ );
exit 0;
}
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index 9921915b4..8e8336b99 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -5,7 +5,6 @@ package IkiWiki;
use warnings;
use strict;
use IkiWiki;
-use Encode;
my (%backlinks, %rendered);
our %brokenlinks;
@@ -94,7 +93,8 @@ sub genpage ($$) {
}
if (defined $config{historyurl} && length $config{historyurl}) {
my $u=$config{historyurl};
- $u=~s/\[\[file\]\]/$pagesources{$page}/g;
+ my $p=uri_escape_utf8($pagesources{$page});
+ $u=~s/\[\[file\]\]/$p/g;
$template->param(historyurl => $u);
$actions++;
}
@@ -759,7 +759,10 @@ sub refresh () {
my ($new, $internal_new)=find_new_files($files);
my ($del, $internal_del)=find_del_files($pages);
my ($changed, $internal_changed)=find_changed($files);
- run_hooks(needsbuild => sub { shift->($changed) });
+ run_hooks(needsbuild => sub {
+ my $ret=shift->($changed, [@$del, @$internal_del]);
+ $changed=$ret if ref $ret eq 'ARRAY';
+ });
my $oldlink_targets=calculate_old_links($changed, $del);
foreach my $file (@$changed) {
diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm
index 927368fae..5eb96f4ae 100644
--- a/IkiWiki/Wrapper.pm
+++ b/IkiWiki/Wrapper.pm
@@ -128,7 +128,7 @@ EOF
#include <sys/file.h>
extern char **environ;
-char *newenviron[$#envsave+6];
+char *newenviron[$#envsave+7];
int i=0;
void addenv(char *var, char *val) {
@@ -147,6 +147,7 @@ $check_commit_hook
@wrapper_hooks
$envsave
newenviron[i++]="HOME=$ENV{HOME}";
+ newenviron[i++]="PATH=$ENV{PATH}";
newenviron[i++]="WRAPPED_OPTIONS=$configstring";
#ifdef __TINYC__