From 472dabbb6002219d324ae8480df57d02b6f0ca94 Mon Sep 17 00:00:00 2001 From: joey Date: Thu, 21 Dec 2006 19:36:15 +0000 Subject: [PATCH] * Turn $config{wiki_file_prune_regexps} into an array that is easier to manipulate. * Only exclude rss and atom files from processing if the inline plugin is enabled and that feed type is enabled. Else it's just a copyable file type. * Move rss and atom option handling code into the inline plugin. * Applied a rather old patch from Recai to fix the "pruning is too strict" issue. Now you can have wiki source directories inside dotdirs and the like, if you want. --- IkiWiki.pm | 17 +++-- IkiWiki/CGI.pm | 5 +- IkiWiki/Plugin/html.pm | 2 +- IkiWiki/Plugin/inline.pm | 25 +++++++ IkiWiki/Render.pm | 4 +- IkiWiki/Setup/Standard.pm | 2 +- debian/changelog | 13 +++- doc/bugs/pruning_is_too_strict.mdwn | 6 +- doc/patchqueue/pruning_is_too_strict.mdwn | 80 ----------------------- ikiwiki.in | 4 +- 10 files changed, 60 insertions(+), 98 deletions(-) delete mode 100644 doc/patchqueue/pruning_is_too_strict.mdwn diff --git a/IkiWiki.pm b/IkiWiki.pm index 4869b3ef3..f76e9fe30 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -22,12 +22,14 @@ our $VERSION = 1.01; # plugin interface version use Memoize; memoize("abs2rel"); memoize("pagespec_translate"); +memoize("file_pruned"); my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE sub defaultconfig () { #{{{ - wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.x?html?$|\.rss$|\.atom$|.arch-ids/|{arch}/)}, + wiki_file_prune_regexps => [qr/\.\./, qr/^\./, qr/\/\./, qr/\.x?html?$/, + qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//], wiki_link_regexp => qr/\[\[(?:([^\]\|]+)\|)?([^\s\]]+)\]\]/, wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/, web_commit_regexp => qr/^web commit (by (.*?(?=: |$))|from (\d+\.\d+\.\d+\.\d+)):?(.*)/, @@ -96,9 +98,6 @@ sub checkconfig () { #{{{ if ($config{cgi} && ! length $config{url}) { error("Must specify url to wiki with --url when using --cgi\n"); } - if (($config{rss} || $config{atom}) && ! length $config{url}) { - error("Must specify url to wiki with --url when using --rss or --atom\n"); - } $config{wikistatedir}="$config{srcdir}/.ikiwiki" unless exists $config{wikistatedir}; @@ -780,6 +779,16 @@ sub add_depends ($$) { #{{{ } } # }}} +sub file_pruned ($$) { #{{{ + require File::Spec; + my $file=File::Spec->canonpath(shift); + my $base=File::Spec->canonpath(shift); + $file=~s#^\Q$base\E/*##; + + my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')'; + $file =~ m/$regexp/; +} #}}} + sub pagespec_match ($$) { #{{{ my $page=shift; my $spec=shift; diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 9b5ee6c19..a41349be5 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -303,8 +303,7 @@ sub cgi_editpage ($$) { #{{{ # characters. my ($page)=$form->field('page'); $page=titlepage(possibly_foolish_untaint($page)); - if (! defined $page || ! length $page || - $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) { + if (! defined $page || ! length $page || file_pruned($page, $config{srcdir}) || $page=~/^\//) { error("bad page name"); } @@ -394,7 +393,7 @@ sub cgi_editpage ($$) { #{{{ my $best_loc; if (! defined $from || ! length $from || $from ne $form->field('from') || - $from=~/$config{wiki_file_prune_regexp}/ || + file_pruned($from, $config{srcdir}) || $from=~/^\// || $form->submitted eq "Preview") { @page_locs=$best_loc=$page; diff --git a/IkiWiki/Plugin/html.pm b/IkiWiki/Plugin/html.pm index 4270a7eb6..fd40d5ad9 100644 --- a/IkiWiki/Plugin/html.pm +++ b/IkiWiki/Plugin/html.pm @@ -12,7 +12,7 @@ sub import { #{{{ # ikiwiki defaults to skipping .html files as a security measure; # make it process them so this plugin can take effect - $config{wiki_file_prune_regexp} =~ s/\|\\\.x\?html\?\$//; + $config{wiki_file_prune_regexps} = [ grep { !m/\\\.x\?html\?\$/ } @{$config{wiki_file_prune_regexps}} ]; } # }}} sub htmlize (@) { #{{{ diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index c623df1c5..78a8813a3 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -9,6 +9,8 @@ use IkiWiki::Render; # for displaytime use URI; sub import { #{{{ + hook(type => "getopt", id => "inline", call => \&getopt); + hook(type => "checkconfig", id => "inline", call => \&checkconfig); hook(type => "preprocess", id => "inline", call => \&IkiWiki::preprocess_inline); hook(type => "pagetemplate", id => "inline", @@ -20,6 +22,29 @@ sub import { #{{{ call => \&IkiWiki::pingurl); } # }}} +sub getopt () { #{{{ + eval q{use Getopt::Long}; + error($@) if $@; + Getopt::Long::Configure('pass_through'); + GetOptions( + "rss!" => \$config{rss}, + "atom!" => \$config{atom}, + ); +} + +sub checkconfig () { #{{{ + if (($config{rss} || $config{atom}) && ! length $config{url}) { + error("Must specify url to wiki with --url when using --rss or --atom"); + } + if ($config{rss}) { + print STDERR "!!\n"; + push @{$config{wiki_file_prune_regexps}}, qr/\.rss$/; + } + if ($config{atom}) { + push @{$config{wiki_file_prune_regexps}}, qr/\.atom$/; + } +} #}}} + # Back to ikiwiki namespace for the rest, this code is very much # internal to ikiwiki even though it's separated into a plugin. package IkiWiki; diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index d08653711..4033468b2 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -218,7 +218,7 @@ sub refresh () { #{{{ no_chdir => 1, wanted => sub { $_=decode_utf8($_); - if (/$config{wiki_file_prune_regexp}/) { + if (file_pruned($_, $config{srcdir})) { $File::Find::prune=1; } elsif (! -d $_ && ! -l $_) { @@ -238,7 +238,7 @@ sub refresh () { #{{{ no_chdir => 1, wanted => sub { $_=decode_utf8($_); - if (/$config{wiki_file_prune_regexp}/) { + if (file_pruned($_, $config{underlaydir})) { $File::Find::prune=1; } elsif (! -d $_ && ! -l $_) { diff --git a/IkiWiki/Setup/Standard.pm b/IkiWiki/Setup/Standard.pm index 7512c2587..77c164e34 100644 --- a/IkiWiki/Setup/Standard.pm +++ b/IkiWiki/Setup/Standard.pm @@ -31,7 +31,7 @@ sub setup_standard { delete $setup{disable_plugins}; } if (exists $setup{exclude}) { - $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$setup{exclude}/; + push @{$config{wiki_file_prune_regexps}}, $setup{exclude}; } if (! $config{render} && (! $config{refresh} || $config{wrappers})) { diff --git a/debian/changelog b/debian/changelog index 6566ede9e..558e156c2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,8 +7,17 @@ ikiwiki (1.36) UNRELEASED; urgency=low * Fix man page perms in install. * Fix an issue with inlining a page with a rss feed inside another page with an rss feed. - - -- Joey Hess Thu, 21 Dec 2006 08:50:41 -0500 + * Turn $config{wiki_file_prune_regexps} into an array that is easier to + manipulate. + * Only exclude rss and atom files from processing if the inline plugin + is enabled and that feed type is enabled. Else it's just a copyable file + type. + * Move rss and atom option handling code into the inline plugin. + * Applied a rather old patch from Recai to fix the "pruning is too strict" + issue. Now you can have wiki source directories inside dotdirs and the + like, if you want. + + -- Joey Hess Thu, 21 Dec 2006 13:54:24 -0500 ikiwiki (1.35) unstable; urgency=low diff --git a/doc/bugs/pruning_is_too_strict.mdwn b/doc/bugs/pruning_is_too_strict.mdwn index ef8d887e9..628cdc6d4 100644 --- a/doc/bugs/pruning_is_too_strict.mdwn +++ b/doc/bugs/pruning_is_too_strict.mdwn @@ -3,6 +3,8 @@ ikiwiki compiles my wiki successfully. But the svn post-commit hook it installs I think the prune regexp would be more useful if it was only used to check the relative path from the src root to a file in the wiki. > I agree with this feature wish. Here is a _first cut_ -> [[implementation|patchqueue/pruning_is_too_strict]] for this feature. +> implementation for this feature. > -> --[[roktas]] \ No newline at end of file +> --[[roktas]] + +[[bugs/Done]], and sorry it took so long to apply --[[Joey]] diff --git a/doc/patchqueue/pruning_is_too_strict.mdwn b/doc/patchqueue/pruning_is_too_strict.mdwn deleted file mode 100644 index 0b7ea76f9..000000000 --- a/doc/patchqueue/pruning_is_too_strict.mdwn +++ /dev/null @@ -1,80 +0,0 @@ -Preliminary patch for a feature wishlist item: [[bugs/pruning_is_too_strict]]. - - diff -ur ikiwiki-orig/IkiWiki/CGI.pm ikiwiki/IkiWiki/CGI.pm - --- ikiwiki-orig/IkiWiki/CGI.pm 2006-10-27 20:15:17.000000000 -0700 - +++ ikiwiki/IkiWiki/CGI.pm 2006-11-07 22:32:41.000000000 -0800 - @@ -405,7 +405,7 @@ - my ($page)=$form->field('page'); - $page=titlepage(possibly_foolish_untaint($page)); - if (! defined $page || ! length $page || - - $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) { - + is_prune($page) || $page=~/^\//) { - error("bad page name"); - } - - @@ -495,8 +495,7 @@ - my $best_loc; - if (! defined $from || ! length $from || - $from ne $form->field('from') || - - $from=~/$config{wiki_file_prune_regexp}/ || - - $from=~/^\// || - + is_prune($from) || $from=~/^\// || - $form->submitted eq "Preview") { - @page_locs=$best_loc=$page; - } - diff -ur ikiwiki-orig/IkiWiki/Render.pm ikiwiki/IkiWiki/Render.pm - --- ikiwiki-orig/IkiWiki/Render.pm 2006-10-27 20:15:17.000000000 -0700 - +++ ikiwiki/IkiWiki/Render.pm 2006-11-07 22:36:48.000000000 -0800 - @@ -189,7 +193,7 @@ - no_chdir => 1, - wanted => sub { - $_=decode_utf8($_); - - if (/$config{wiki_file_prune_regexp}/) { - + if (is_prune($_)) { - $File::Find::prune=1; - } - elsif (! -d $_ && ! -l $_) { - @@ -209,7 +213,7 @@ - no_chdir => 1, - wanted => sub { - $_=decode_utf8($_); - - if (/$config{wiki_file_prune_regexp}/) { - + if (is_prune($_, $config{underlaydir})) { - $File::Find::prune=1; - } - elsif (! -d $_ && ! -l $_) { - diff -ur ikiwiki-orig/IkiWiki.pm ikiwiki/IkiWiki.pm - --- ikiwiki-orig/IkiWiki.pm 2006-10-27 20:15:23.000000000 -0700 - +++ ikiwiki/IkiWiki.pm 2006-11-07 22:21:17.000000000 -0800 - @@ -21,6 +21,8 @@ - # Optimisation. - use Memoize; - memoize("abs2rel"); - +memoize("basefile"); - +memoize("is_prune"); - memoize("pagespec_translate"); - - my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE - @@ -343,6 +352,22 @@ - return $page; - } #}}} - - +sub basefile ($;$) { #{{{ - + my $file=shift; - + my $base=shift || $config{srcdir}; - + - + require File::Spec; - + $base=File::Spec->canonpath($base); - + my $ret=File::Spec->canonpath($file); - + - + $ret=~s#^$base/*##; - + return $ret; - +} #}}} - + - +sub is_prune ($;$) { #{{{ - + return basefile($_[0], $_[1])=~m/$config{wiki_file_prune_regexp}/; - +} #}}} - + - sub abs2rel ($$) { #{{{ - # Work around very innefficient behavior in File::Spec if abs2rel - # is passed two relative paths. It's much faster if paths are diff --git a/ikiwiki.in b/ikiwiki.in index 7d13ab455..ad2558258 100755 --- a/ikiwiki.in +++ b/ikiwiki.in @@ -32,8 +32,6 @@ sub getconfig () { #{{{ "rcs=s" => \$config{rcs}, "no-rcs" => sub { $config{rcs}="" }, "anonok!" => \$config{anonok}, - "rss!" => \$config{rss}, - "atom!" => \$config{atom}, "cgi!" => \$config{cgi}, "discussion!" => \$config{discussion}, "w3mmode!" => \$config{w3mmode}, @@ -49,7 +47,7 @@ sub getconfig () { #{{{ "sslcookie!" => \$config{sslcookie}, "httpauth!" => \$config{httpauth}, "exclude=s@" => sub { - $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/; + push @{$config{wiki_file_prune_regexp}}, $_[1]; }, "adminuser=s@" => sub { push @{$config{adminuser}}, $_[1] -- 2.26.2