]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki.pm
some design work on rename/delete
[git.ikiwiki.info.git] / IkiWiki.pm
index d9b3dcdb473df66c4505a1b47e429febac493b63..80e31711062694fb9494306e5900df4ca54f8b2f 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
 package IkiWiki;
 #!/usr/bin/perl
 
 package IkiWiki;
+
 use warnings;
 use strict;
 use Encode;
 use warnings;
 use strict;
 use Encode;
@@ -188,11 +189,6 @@ sub loadplugin ($) { #{{{
 sub error ($;$) { #{{{
        my $message=shift;
        my $cleaner=shift;
 sub error ($;$) { #{{{
        my $message=shift;
        my $cleaner=shift;
-       if ($config{cgi}) {
-               print "Content-type: text/html\n\n";
-               print misctemplate(gettext("Error"),
-                       "<p>".gettext("Error").": $message</p>");
-       }
        log_message('err' => $message) if $config{syslog};
        if (defined $cleaner) {
                $cleaner->();
        log_message('err' => $message) if $config{syslog};
        if (defined $cleaner) {
                $cleaner->();
@@ -336,7 +332,7 @@ sub readfile ($;$$) { #{{{
        return $ret;
 } #}}}
 
        return $ret;
 } #}}}
 
-sub prep_writefile ($$) {
+sub prep_writefile ($$) { #{{{
        my $file=shift;
        my $destdir=shift;
        
        my $file=shift;
        my $destdir=shift;
        
@@ -360,7 +356,7 @@ sub prep_writefile ($$) {
        }
 
        return 1;
        }
 
        return 1;
-}
+} #}}}
 
 sub writefile ($$$;$$) { #{{{
        my $file=shift; # can include subdirs
 
 sub writefile ($$$;$$) { #{{{
        my $file=shift; # can include subdirs
@@ -532,13 +528,18 @@ sub displaytime ($;$) { #{{{
        return decode_utf8(POSIX::strftime($format, localtime($time)));
 } #}}}
 
        return decode_utf8(POSIX::strftime($format, localtime($time)));
 } #}}}
 
-sub beautify_url ($) { #{{{
+sub beautify_urlpath ($) { #{{{
        my $url=shift;
 
        if ($config{usedirs}) {
                $url =~ s!/index.$config{htmlext}$!/!;
        }
        my $url=shift;
 
        if ($config{usedirs}) {
                $url =~ s!/index.$config{htmlext}$!/!;
        }
-       $url =~ s!^$!./!; # Browsers don't like empty links...
+
+       # Ensure url is not an empty link, and
+       # if it's relative, make that explicit to avoid colon confusion.
+       if ($url !~ /\//) {
+               $url="./$url";
+       }
 
        return $url;
 } #}}}
 
        return $url;
 } #}}}
@@ -548,7 +549,7 @@ sub urlto ($$) { #{{{
        my $from=shift;
 
        if (! length $to) {
        my $from=shift;
 
        if (! length $to) {
-               return beautify_url(baseurl($from)."index.$config{htmlext}");
+               return beautify_urlpath(baseurl($from)."index.$config{htmlext}");
        }
 
        if (! $destsources{$to}) {
        }
 
        if (! $destsources{$to}) {
@@ -557,7 +558,7 @@ sub urlto ($$) { #{{{
 
        my $link = abs2rel($to, dirname(htmlpage($from)));
 
 
        my $link = abs2rel($to, dirname(htmlpage($from)));
 
-       return beautify_url($link);
+       return beautify_urlpath($link);
 } #}}}
 
 sub htmllink ($$$;@) { #{{{
 } #}}}
 
 sub htmllink ($$$;@) { #{{{
@@ -596,7 +597,7 @@ sub htmllink ($$$;@) { #{{{
                        return "<span class=\"createlink\"><a href=\"".
                                cgiurl(
                                        do => "create",
                        return "<span class=\"createlink\"><a href=\"".
                                cgiurl(
                                        do => "create",
-                                       page => pagetitle(lc($link), 1),
+                                       page => lc($link),
                                        from => $lpage
                                ).
                                "\" rel=\"nofollow\">?</a>$linktext</span>"
                                        from => $lpage
                                ).
                                "\" rel=\"nofollow\">?</a>$linktext</span>"
@@ -604,7 +605,7 @@ sub htmllink ($$$;@) { #{{{
        }
        
        $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
        }
        
        $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
-       $bestlink=beautify_url($bestlink);
+       $bestlink=beautify_urlpath($bestlink);
        
        if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
                return "<img src=\"$bestlink\" alt=\"$linktext\" />";
        
        if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
                return "<img src=\"$bestlink\" alt=\"$linktext\" />";
@@ -767,21 +768,30 @@ sub preprocess ($$$;$$) { #{{{
                        }
                        my $ret;
                        if (! $scan) {
                        }
                        my $ret;
                        if (! $scan) {
-                               $ret=$hooks{preprocess}{$command}{call}->(
-                                       @params,
-                                       page => $page,
-                                       destpage => $destpage,
-                                       preview => $preprocess_preview,
-                               );
+                               $ret=eval {
+                                       $hooks{preprocess}{$command}{call}->(
+                                               @params,
+                                               page => $page,
+                                               destpage => $destpage,
+                                               preview => $preprocess_preview,
+                                       );
+                               };
+                               if ($@) {
+                                       chomp $@;
+                                       $ret="[[!$command <span class=\"error\">".
+                                               gettext("Error").": $@"."</span>]]";
+                               }
                        }
                        else {
                                # use void context during scan pass
                        }
                        else {
                                # use void context during scan pass
-                               $hooks{preprocess}{$command}{call}->(
-                                       @params,
-                                       page => $page,
-                                       destpage => $destpage,
-                                       preview => $preprocess_preview,
-                               );
+                               eval {
+                                       $hooks{preprocess}{$command}{call}->(
+                                               @params,
+                                               page => $page,
+                                               destpage => $destpage,
+                                               preview => $preprocess_preview,
+                                       );
+                               };
                                $ret="";
                        }
                        $preprocessing{$page}--;
                                $ret="";
                        }
                        $preprocessing{$page}--;
@@ -1196,6 +1206,12 @@ sub gettext { #{{{
        }
 } #}}}
 
        }
 } #}}}
 
+sub yesno ($) { #{{{
+       my $val=shift;
+
+       return (defined $val && lc($val) eq gettext("yes"));
+} #}}}
+
 sub pagespec_merge ($$) { #{{{
        my $a=shift;
        my $b=shift;
 sub pagespec_merge ($$) { #{{{
        my $a=shift;
        my $b=shift;
@@ -1290,6 +1306,13 @@ sub pagespec_valid ($) { #{{{
        my $sub=pagespec_translate($spec);
        return ! $@;
 } #}}}
        my $sub=pagespec_translate($spec);
        return ! $@;
 } #}}}
+       
+sub glob2re ($) { #{{{
+       my $re=quotemeta(shift);
+       $re=~s/\\\*/.*/g;
+       $re=~s/\\\?/./g;
+       return $re;
+} #}}}
 
 package IkiWiki::FailReason;
 
 
 package IkiWiki::FailReason;
 
@@ -1337,12 +1360,8 @@ sub match_glob ($$;@) { #{{{
                $glob="$from/$glob" if length $from;
        }
 
                $glob="$from/$glob" if length $from;
        }
 
-       # turn glob into safe regexp
-       $glob=quotemeta($glob);
-       $glob=~s/\\\*/.*/g;
-       $glob=~s/\\\?/./g;
-
-       if ($page=~/^$glob$/i) {
+       my $regexp=IkiWiki::glob2re($glob);
+       if ($page=~/^$regexp$/i) {
                if (! IkiWiki::isinternal($page) || $params{internal}) {
                        return IkiWiki::SuccessReason->new("$glob matches $page");
                }
                if (! IkiWiki::isinternal($page) || $params{internal}) {
                        return IkiWiki::SuccessReason->new("$glob matches $page");
                }