summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/aggregate.pm23
-rw-r--r--IkiWiki/Plugin/autoindex.pm102
-rw-r--r--IkiWiki/Plugin/blogspam.pm14
-rw-r--r--IkiWiki/Plugin/comments.pm4
-rw-r--r--IkiWiki/Plugin/editpage.pm6
-rw-r--r--IkiWiki/Plugin/htmltidy.pm2
-rw-r--r--IkiWiki/Plugin/inline.pm39
-rw-r--r--IkiWiki/Plugin/po.pm3
-rw-r--r--IkiWiki/Plugin/rename.pm1
-rw-r--r--IkiWiki/Plugin/transient.pm8
10 files changed, 131 insertions, 71 deletions
diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index 59185e97f..419b40fdb 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -162,10 +162,14 @@ sub migrate_to_internal {
$config{aggregateinternal} = 0;
my $oldname = "$config{srcdir}/".htmlfn($data->{page});
+ if (! -e $oldname) {
+ $oldname = $IkiWiki::Plugin::transient::transientdir."/".htmlfn($data->{page});
+ }
+
my $oldoutput = $config{destdir}."/".IkiWiki::htmlpage($data->{page});
$config{aggregateinternal} = 1;
- my $newname = "$config{srcdir}/".htmlfn($data->{page});
+ my $newname = $IkiWiki::Plugin::transient::transientdir."/".htmlfn($data->{page});
debug "moving $oldname -> $newname";
if (-e $newname) {
@@ -385,13 +389,16 @@ sub garbage_collect () {
foreach my $guid (values %guids) {
# any guid whose feed is gone should be removed
if (! exists $feeds{$guid->{feed}}) {
- unlink "$config{srcdir}/".htmlfn($guid->{page})
- if exists $guid->{page};
+ if (exists $guid->{page}) {
+ unlink $IkiWiki::Plugin::transient::transientdir."/".htmlfn($guid->{page})
+ || unlink "$config{srcdir}/".htmlfn($guid->{page});
+ }
delete $guids{$guid->{guid}};
}
# handle expired guids
elsif ($guid->{expired} && exists $guid->{page}) {
unlink "$config{srcdir}/".htmlfn($guid->{page});
+ unlink $IkiWiki::Plugin::transient::transientdir."/".htmlfn($guid->{page});
delete $guid->{page};
delete $guid->{md5};
}
@@ -611,6 +618,7 @@ sub add_page (@) {
}
my $c="";
while (exists $IkiWiki::pagecase{lc $page.$c} ||
+ -e $IkiWiki::Plugin::transient::transientdir."/".htmlfn($page.$c) ||
-e "$config{srcdir}/".htmlfn($page.$c)) {
$c++
}
@@ -622,6 +630,8 @@ sub add_page (@) {
$c="";
$page=$feed->{dir}."/item";
while (exists $IkiWiki::pagecase{lc $page.$c} ||
+ -e $IkiWiki::Plugin::transient::transientdir."/".htmlfn($page.$c) ||
+
-e "$config{srcdir}/".htmlfn($page.$c)) {
$c++
}
@@ -664,13 +674,14 @@ sub add_page (@) {
if (ref $feed->{tags}) {
$template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
}
- writefile(htmlfn($guid->{page}), $config{srcdir},
- $template->output);
+ writefile(htmlfn($guid->{page}),
+ $IkiWiki::Plugin::transient::transientdir, $template->output);
if (defined $mtime && $mtime <= time) {
# Set the mtime, this lets the build process get the right
# creation time on record for the new page.
- utime $mtime, $mtime, "$config{srcdir}/".htmlfn($guid->{page});
+ utime $mtime, $mtime,
+ $IkiWiki::Plugin::transient::transientdir."/".htmlfn($guid->{page});
# Store it in pagectime for expiry code to use also.
$IkiWiki::pagectime{$guid->{page}}=$mtime
unless exists $IkiWiki::pagectime{$guid->{page}};
diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm
index 11595e217..78571b276 100644
--- a/IkiWiki/Plugin/autoindex.pm
+++ b/IkiWiki/Plugin/autoindex.pm
@@ -7,8 +7,10 @@ use IkiWiki 3.00;
use Encode;
sub import {
+ hook(type => "checkconfig", id => "autoindex", call => \&checkconfig);
hook(type => "getsetup", id => "autoindex", call => \&getsetup);
hook(type => "refresh", id => "autoindex", call => \&refresh);
+ IkiWiki::loadplugin("transient");
}
sub getsetup () {
@@ -17,17 +19,47 @@ sub getsetup () {
safe => 1,
rebuild => 0,
},
+ autoindex_commit => {
+ type => "boolean",
+ example => 1,
+ default => 1,
+ description => "commit autocreated index pages",
+ safe => 1,
+ rebuild => 0,
+ },
+}
+
+sub checkconfig () {
+ if (! defined $config{autoindex_commit}) {
+ $config{autoindex_commit} = 1;
+ }
}
sub genindex ($) {
my $page=shift;
my $file=newpagefile($page, $config{default_pageext});
- my $template=template("autoindex.tmpl");
- $template->param(page => $page);
- writefile($file, $config{srcdir}, $template->output);
- if ($config{rcs}) {
- IkiWiki::rcs_add($file);
- }
+
+ add_autofile($file, "autoindex", sub {
+ my $message = sprintf(gettext("creating index page %s"),
+ $page);
+ debug($message);
+
+ my $dir = $config{srcdir};
+ if (! $config{autoindex_commit}) {
+ $dir = $IkiWiki::Plugin::transient::transientdir;
+ }
+
+ my $template = template("autoindex.tmpl");
+ $template->param(page => $page);
+ writefile($file, $dir, $template->output);
+
+ if ($config{rcs} && $config{autoindex_commit}) {
+ IkiWiki::disable_commit_hook();
+ IkiWiki::rcs_add($file);
+ IkiWiki::rcs_commit_staged(message => $message);
+ IkiWiki::enable_commit_hook();
+ }
+ });
}
sub refresh () {
@@ -39,6 +71,7 @@ sub refresh () {
my (%pages, %dirs);
foreach my $dir ($config{srcdir}, @{$config{underlaydirs}}, $config{underlaydir}) {
+ next if $dir eq $IkiWiki::Plugin::transient::transientdir;
chdir($dir) || next;
find({
@@ -66,60 +99,39 @@ sub refresh () {
chdir($origdir) || die "chdir $origdir: $!";
}
-
+
+ # Compatibility code.
+ #
+ # {deleted} contains pages that have been deleted at some point.
+ # This plugin used to delete from the hash sometimes, but no longer
+ # does; in [[todo/autoindex_should_use_add__95__autofile]] Joey
+ # thought the old behaviour was probably a bug.
+ #
+ # The effect of listing a page in {deleted} was to avoid re-creating
+ # it; we migrate these pages to {autofile} which has the same effect.
+ # However, {autofile} contains source filenames whereas {deleted}
+ # contains page names.
my %deleted;
if (ref $wikistate{autoindex}{deleted}) {
%deleted=%{$wikistate{autoindex}{deleted}};
+ delete $wikistate{autoindex}{deleted};
}
elsif (ref $pagestate{index}{autoindex}{deleted}) {
- # compatability code
+ # an even older version
%deleted=%{$pagestate{index}{autoindex}{deleted}};
delete $pagestate{index}{autoindex};
}
if (keys %deleted) {
foreach my $dir (keys %deleted) {
- # remove deleted page state if the deleted page is re-added,
- # or if all its subpages are deleted
- if ($deleted{$dir} && (exists $pages{$dir} ||
- ! grep /^$dir\/.*/, keys %pages)) {
- delete $deleted{$dir};
- }
+ my $file=newpagefile($dir, $config{default_pageext});
+ $wikistate{autoindex}{autofile}{$file} = 1;
}
- $wikistate{autoindex}{deleted}=\%deleted;
}
- my @needed;
foreach my $dir (keys %dirs) {
- if (! exists $pages{$dir} && ! $deleted{$dir} &&
- grep /^$dir\/.*/, keys %pages) {
- if (exists $IkiWiki::pagemtime{$dir}) {
- # This page must have just been deleted, so
- # don't re-add it. And remember it was
- # deleted.
- if (! ref $wikistate{autoindex}{deleted}) {
- $wikistate{autoindex}{deleted}={};
- }
- ${$wikistate{autoindex}{deleted}}{$dir}=1;
- }
- else {
- push @needed, $dir;
- }
- }
- }
-
- if (@needed) {
- if ($config{rcs}) {
- IkiWiki::disable_commit_hook();
- }
- foreach my $page (@needed) {
- genindex($page);
- }
- if ($config{rcs}) {
- IkiWiki::rcs_commit_staged(
- message => gettext("automatic index generation"),
- );
- IkiWiki::enable_commit_hook();
+ if (! exists $pages{$dir} && grep /^$dir\/.*/, keys %pages) {
+ genindex($dir);
}
}
}
diff --git a/IkiWiki/Plugin/blogspam.pm b/IkiWiki/Plugin/blogspam.pm
index f0b6cb2a2..d32c2f169 100644
--- a/IkiWiki/Plugin/blogspam.pm
+++ b/IkiWiki/Plugin/blogspam.pm
@@ -61,12 +61,18 @@ sub checkcontent (@) {
my %params=@_;
my $session=$params{session};
- if (exists $config{blogspam_pagespec}) {
- return undef
- if ! pagespec_match($params{page}, $config{blogspam_pagespec},
- location => $params{page});
+ my $spec='!admin()';
+ if (exists $config{blogspam_pagespec} &&
+ length $config{blogspam_pagespec}) {
+ $spec.=" and (".$config{blogspam_pagespec}.")";
}
+ my $user=$session->param("name");
+ return undef unless pagespec_match($params{page}, $spec,
+ (defined $user ? (user => $user) : ()),
+ (defined $session->remote_addr() ? (ip => $session->remote_addr()) : ()),
+ location => $params{page});
+
my $url=$defaulturl;
$url = $config{blogspam_server} if exists $config{blogspam_server};
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 1287590a7..6691dbafa 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -364,8 +364,8 @@ sub editcomment ($$) {
}
# The untaint is OK (as in editpage) because we're about to pass
- # it to file_pruned anyway
- my $page = $form->field('page');
+ # it to file_pruned and wiki_file_regexp anyway.
+ my ($page) = $form->field('page')=~/$config{wiki_file_regexp}/;
$page = IkiWiki::possibly_foolish_untaint($page);
if (! defined $page || ! length $page ||
IkiWiki::file_pruned($page)) {
diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
index df29bcc98..3d094c263 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -91,6 +91,9 @@ sub cgi_editpage ($$) {
# This untaint is safe because we check file_pruned and
# wiki_file_regexp.
my ($page)=$form->field('page')=~/$config{wiki_file_regexp}/;
+ if (! defined $page) {
+ error(gettext("bad page name"));
+ }
$page=possibly_foolish_untaint($page);
my $absolute=($page =~ s#^/+##); # absolute name used to force location
if (! defined $page || ! length $page ||
@@ -128,7 +131,8 @@ sub cgi_editpage ($$) {
# favor the type of linking page
$type=pagetype($pagesources{$from});
}
- $type=$config{default_pageext} unless defined $type;
+ $type=$config{default_pageext}
+ if ! defined $type || $type=~/^_/; # not internal type
$file=newpagefile($page, $type);
if (! $form->submitted) {
$form->field(name => "rcsinfo", value => "", force => 1);
diff --git a/IkiWiki/Plugin/htmltidy.pm b/IkiWiki/Plugin/htmltidy.pm
index 1108aeb89..da77e60f1 100644
--- a/IkiWiki/Plugin/htmltidy.pm
+++ b/IkiWiki/Plugin/htmltidy.pm
@@ -41,6 +41,8 @@ sub checkconfig () {
sub sanitize (@) {
my %params=@_;
+ return $params{content} unless defined $config{htmltidy};
+
my $pid;
my $sigpipe=0;
$SIG{PIPE}=sub { $sigpipe=1 };
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 7c5da7343..285077204 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -290,8 +290,17 @@ sub preprocess_inline (@) {
}
}
- 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 ($rssurl, $atomurl, $rssdesc, $atomdesc);
+ if ($feeds) {
+ if ($rss) {
+ $rssurl=abs2rel($feedbase."rss".$feednum, dirname(htmlpage($params{destpage})));
+ $rssdesc = sprintf(gettext("%s (RSS feed)"), $desc);
+ }
+ if ($atom) {
+ $atomurl=abs2rel($feedbase."atom".$feednum, dirname(htmlpage($params{destpage})));
+ $atomdesc = sprintf(gettext("%s (Atom feed)"), $desc);
+ }
+ }
my $ret="";
@@ -302,8 +311,16 @@ sub preprocess_inline (@) {
my $formtemplate=template_depends("blogpost.tmpl", $params{page}, blind_cache => 1);
$formtemplate->param(cgiurl => IkiWiki::cgiurl());
$formtemplate->param(rootpage => rootpage(%params));
- $formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
- $formtemplate->param(atomurl => $atomurl) if $feeds && $atom;
+ if ($feeds) {
+ if ($rss) {
+ $formtemplate->param(rssurl => $rssurl);
+ $formtemplate->param(rssdesc => $rssdesc);
+ }
+ if ($atom) {
+ $formtemplate->param(atomurl => $atomurl);
+ $formtemplate->param(atomdesc => $atomdesc);
+ }
+ }
if (exists $params{postformtext}) {
$formtemplate->param(postformtext =>
$params{postformtext});
@@ -321,8 +338,14 @@ sub preprocess_inline (@) {
elsif ($feeds && !$params{preview} && ($emptyfeeds || @feedlist)) {
# Add feed buttons.
my $linktemplate=template_depends("feedlink.tmpl", $params{page}, blind_cache => 1);
- $linktemplate->param(rssurl => $rssurl) if $rss;
- $linktemplate->param(atomurl => $atomurl) if $atom;
+ if ($rss) {
+ $linktemplate->param(rssurl => $rssurl);
+ $linktemplate->param(rssdesc => $rssdesc);
+ }
+ if ($atom) {
+ $linktemplate->param(atomurl => $atomurl);
+ $linktemplate->param(atomdesc => $atomdesc);
+ }
$ret.=$linktemplate->output;
}
@@ -419,7 +442,7 @@ sub preprocess_inline (@) {
genfeed("rss",
$config{url}."/".$rssp, $desc, $params{guid}, $params{destpage}, @feedlist));
$toping{$params{destpage}}=1 unless $config{rebuild};
- $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/rss+xml" title="$desc (RSS)" href="$rssurl" />};
+ $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/rss+xml" title="$rssdesc" href="$rssurl" />};
}
}
if ($atom) {
@@ -429,7 +452,7 @@ sub preprocess_inline (@) {
writefile($atomp, $config{destdir},
genfeed("atom", $config{url}."/".$atomp, $desc, $params{guid}, $params{destpage}, @feedlist));
$toping{$params{destpage}}=1 unless $config{rebuild};
- $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/atom+xml" title="$desc (Atom)" href="$atomurl" />};
+ $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/atom+xml" title="$atomdesc" href="$atomurl" />};
}
}
}
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 9ed4a1adb..4f8d5036e 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -38,7 +38,8 @@ memoize("percenttranslated");
sub import {
hook(type => "getsetup", id => "po", call => \&getsetup);
- hook(type => "checkconfig", id => "po", call => \&checkconfig);
+ hook(type => "checkconfig", id => "po", call => \&checkconfig,
+ last => 1);
hook(type => "needsbuild", id => "po", call => \&needsbuild);
hook(type => "scan", id => "po", call => \&scan, last => 1);
hook(type => "filter", id => "po", call => \&filter);
diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm
index 57747d3c9..e871b815d 100644
--- a/IkiWiki/Plugin/rename.pm
+++ b/IkiWiki/Plugin/rename.pm
@@ -567,6 +567,7 @@ sub fixlinks ($$$) {
}
if ($needfix) {
my $file=$pagesources{$page};
+ next unless -e $config{srcdir}."/".$file;
my $oldcontent=readfile($config{srcdir}."/".$file);
my $content=renamepage_hook($page, $rename->{src}, $rename->{dest}, $oldcontent);
if ($oldcontent ne $content) {
diff --git a/IkiWiki/Plugin/transient.pm b/IkiWiki/Plugin/transient.pm
index c482b8552..9811aa010 100644
--- a/IkiWiki/Plugin/transient.pm
+++ b/IkiWiki/Plugin/transient.pm
@@ -25,10 +25,10 @@ sub getsetup () {
our $transientdir;
sub checkconfig () {
- eval q{use Cwd 'abs_path'};
- error($@) if $@;
- $transientdir = abs_path($config{wikistatedir})."/transient";
- add_underlay($transientdir);
+ $transientdir = $config{wikistatedir}."/transient";
+ # add_underlay treats relative underlays as relative to the installed
+ # location, not the cwd. That's not what we want here.
+ IkiWiki::add_literal_underlay($transientdir);
}
sub change (@) {