aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2011-01-22 22:35:37 +0000
committerSimon McVittie <smcv@debian.org>2011-01-22 22:35:37 +0000
commit594a9194561ad373a31a7d34c6b5c7a84ec417a0 (patch)
treea0032b56a36a9ca6f77873f8cc6a290e72b95ae7 /IkiWiki
parent44b0cea85f1641f33ccb305f9da6f96e812b84e9 (diff)
parent8ee9eabb1c5314f51641aaec4cb45d5c2d0fa7b8 (diff)
downloadikiwiki-594a9194561ad373a31a7d34c6b5c7a84ec417a0.tar
ikiwiki-594a9194561ad373a31a7d34c6b5c7a84ec417a0.tar.gz
Merge branch 'ready/autoindex-autofile' into HEAD
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/autoindex.pm80
-rw-r--r--IkiWiki/Plugin/comments.pm4
-rw-r--r--IkiWiki/Plugin/editpage.pm4
-rw-r--r--IkiWiki/Plugin/inline.pm39
-rw-r--r--IkiWiki/Plugin/rename.pm1
5 files changed, 71 insertions, 57 deletions
diff --git a/IkiWiki/Plugin/autoindex.pm b/IkiWiki/Plugin/autoindex.pm
index 11595e217..5a58c820a 100644
--- a/IkiWiki/Plugin/autoindex.pm
+++ b/IkiWiki/Plugin/autoindex.pm
@@ -22,12 +22,23 @@ sub getsetup () {
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 $template = template("autoindex.tmpl");
+ $template->param(page => $page);
+ writefile($file, $config{srcdir}, $template->output);
+
+ if ($config{rcs}) {
+ IkiWiki::disable_commit_hook();
+ IkiWiki::rcs_add($file);
+ IkiWiki::rcs_commit_staged(message => $message);
+ IkiWiki::enable_commit_hook();
+ }
+ });
}
sub refresh () {
@@ -66,60 +77,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/comments.pm b/IkiWiki/Plugin/comments.pm
index 1287590a7..d9183970d 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..8c78e853c 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -91,12 +91,12 @@ 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}/;
- $page=possibly_foolish_untaint($page);
- my $absolute=($page =~ s#^/+##); # absolute name used to force location
if (! defined $page || ! length $page ||
file_pruned($page)) {
error(gettext("bad page name"));
}
+ $page=possibly_foolish_untaint($page);
+ my $absolute=($page =~ s#^/+##); # absolute name used to force location
my $baseurl = urlto($page);
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 7c5da7343..d89e14197 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 = gettext("%s (RSS feed)", $desc);
+ }
+ if ($atom) {
+ $atomurl=abs2rel($feedbase."atom".$feednum, dirname(htmlpage($params{destpage})));
+ $atomdesc = 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/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) {