]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki.pm
Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[git.ikiwiki.info.git] / IkiWiki.pm
index 3f92bda06bf352980be8fe1a9559dbdeb4020e69..c1d9119e840662f449d0cd257c0ca1c14df48653 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;
@@ -88,6 +89,7 @@ sub defaultconfig () { #{{{
        account_creation_password => "",
        prefix_directives => 0,
        hardlink => 0,
        account_creation_password => "",
        prefix_directives => 0,
        hardlink => 0,
+       cgi_disable_uploads => 1,
 } #}}}
 
 sub checkconfig () { #{{{
 } #}}}
 
 sub checkconfig () { #{{{
@@ -531,13 +533,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;
 } #}}}
@@ -547,7 +554,7 @@ sub urlto ($$) { #{{{
        my $from=shift;
 
        if (! length $to) {
        my $from=shift;
 
        if (! length $to) {
-               return beautify_url(baseurl($from));
+               return beautify_urlpath(baseurl($from)."index.$config{htmlext}");
        }
 
        if (! $destsources{$to}) {
        }
 
        if (! $destsources{$to}) {
@@ -556,7 +563,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 ($$$;@) { #{{{
@@ -595,7 +602,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>"
@@ -603,7 +610,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\" />";
@@ -641,8 +648,9 @@ sub userlink ($) { #{{{
        }
 } #}}}
 
        }
 } #}}}
 
-sub htmlize ($$$) { #{{{
+sub htmlize ($$$$) { #{{{
        my $page=shift;
        my $page=shift;
+       my $destpage=shift;
        my $type=shift;
        my $content=shift;
        
        my $type=shift;
        my $content=shift;
        
@@ -661,6 +669,7 @@ sub htmlize ($$$) { #{{{
        run_hooks(sanitize => sub {
                $content=shift->(
                        page => $page,
        run_hooks(sanitize => sub {
                $content=shift->(
                        page => $page,
+                       destpage => $destpage,
                        content => $content,
                );
        });
                        content => $content,
                );
        });
@@ -1287,6 +1296,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;
 
@@ -1334,12 +1350,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");
                }