* Turn $config{wiki_file_prune_regexps} into an array that is easier to
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Thu, 21 Dec 2006 19:36:15 +0000 (19:36 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Thu, 21 Dec 2006 19:36:15 +0000 (19:36 +0000)
  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
IkiWiki/CGI.pm
IkiWiki/Plugin/html.pm
IkiWiki/Plugin/inline.pm
IkiWiki/Render.pm
IkiWiki/Setup/Standard.pm
debian/changelog
doc/bugs/pruning_is_too_strict.mdwn
doc/patchqueue/pruning_is_too_strict.mdwn [deleted file]
ikiwiki.in

index 4869b3ef3b32fee7a0ed2ab4cda7221461302b1e..f76e9fe30dabef80bf8df1a5149f9b92d990fdfb 100644 (file)
@@ -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;
index 9b5ee6c19b980d491773b027afb6bc4d9a8cd95f..a41349be518a648fa9f71cd5df83b4810a3ce98c 100644 (file)
@@ -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;
index 4270a7eb67c247123cacf2a4fd486157ccbdb780..fd40d5ad97910b72f5d81ceded2a287efd44f96d 100644 (file)
@@ -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 (@) { #{{{
index c623df1c5755f995ae930c5288f03347c8b2c652..78a8813a3fe62903e20b4431544805bac16e135b 100644 (file)
@@ -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;
index d086537114544581cab44682df4c97bc220fd112..4033468b23a7917aadc01c0fd9fc9fed416c4573 100644 (file)
@@ -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 $_) {
index 7512c258758eb7e7a577d73e08b2679dc5a6e6b0..77c164e34a61f6cac39e7acb16f331aedfd21878 100644 (file)
@@ -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})) {
index 6566ede9e3c81168703e51535fa0b429c47821b9..558e156c2b1a1a873ef22e2b56ac229fc8830207 100644 (file)
@@ -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 <joeyh@debian.org>  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 <joeyh@debian.org>  Thu, 21 Dec 2006 13:54:24 -0500
 
 ikiwiki (1.35) unstable; urgency=low
 
index ef8d887e9a2dfccec6ecc0d276c00aa2cdd7ac71..628cdc6d49449382b31090c019ba8023bcfa3761 100644 (file)
@@ -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 (file)
index 0b7ea76..0000000
+++ /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
index 7d13ab455c60dd80a743d6fb519d1400b9e02b4b..ad25582581e38fffa807c9b6a4594c1b65ca29de 100755 (executable)
@@ -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]