]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
Stop prepending urn:uuid: to guids that look like UUIDs
[ikiwiki.git] / IkiWiki.pm
index f5cf8ba96bbc8d61a6e801d9058e13955e5108c6..f1a5f8058ec551667027e1af755848f7c11655aa 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
 package IkiWiki;
+
 use warnings;
 use strict;
 use Encode;
@@ -88,6 +89,7 @@ sub defaultconfig () { #{{{
        account_creation_password => "",
        prefix_directives => 0,
        hardlink => 0,
+       cgi_disable_uploads => 1,
 } #}}}
 
 sub checkconfig () { #{{{
@@ -103,6 +105,12 @@ sub checkconfig () { #{{{
                }
        }
 
+       if (ref $config{ENV} eq 'HASH') {
+               foreach my $val (keys %{$config{ENV}}) {
+                       $ENV{$val}=$config{ENV}{$val};
+               }
+       }
+
        if ($config{w3mmode}) {
                eval q{use Cwd q{abs_path}};
                error($@) if $@;
@@ -282,18 +290,22 @@ sub htmlpage ($) { #{{{
        return targetpage($page, $config{htmlext});
 } #}}}
 
-sub srcfile ($;$) { #{{{
+sub srcfile_stat { #{{{
        my $file=shift;
        my $nothrow=shift;
 
-       return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
+       return "$config{srcdir}/$file", stat(_) if -e "$config{srcdir}/$file";
        foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) {
-               return "$dir/$file" if -e "$dir/$file";
+               return "$dir/$file", stat(_) if -e "$dir/$file";
        }
        error("internal error: $file cannot be found in $config{srcdir} or underlay") unless $nothrow;
        return;
 } #}}}
 
+sub srcfile ($;$) { #{{{
+       return (srcfile_stat(@_))[0];
+} #}}}
+
 sub add_underlay ($) { #{{{
        my $dir=shift;
 
@@ -325,7 +337,7 @@ sub readfile ($;$$) { #{{{
        return $ret;
 } #}}}
 
-sub prep_writefile ($$) {
+sub prep_writefile ($$) { #{{{
        my $file=shift;
        my $destdir=shift;
        
@@ -349,7 +361,7 @@ sub prep_writefile ($$) {
        }
 
        return 1;
-}
+} #}}}
 
 sub writefile ($$$;$$) { #{{{
        my $file=shift; # can include subdirs
@@ -521,13 +533,18 @@ sub displaytime ($;$) { #{{{
        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}$!/!;
        }
-       $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;
 } #}}}
@@ -537,7 +554,7 @@ sub urlto ($$) { #{{{
        my $from=shift;
 
        if (! length $to) {
-               return beautify_url(baseurl($from));
+               return beautify_urlpath(baseurl($from)."index.$config{htmlext}");
        }
 
        if (! $destsources{$to}) {
@@ -546,7 +563,7 @@ sub urlto ($$) { #{{{
 
        my $link = abs2rel($to, dirname(htmlpage($from)));
 
-       return beautify_url($link);
+       return beautify_urlpath($link);
 } #}}}
 
 sub htmllink ($$$;@) { #{{{
@@ -585,15 +602,15 @@ sub htmllink ($$$;@) { #{{{
                        return "<span class=\"createlink\"><a href=\"".
                                cgiurl(
                                        do => "create",
-                                       page => pagetitle(lc($link), 1),
+                                       page => lc($link),
                                        from => $lpage
                                ).
-                               "\">?</a>$linktext</span>"
+                               "\" rel=\"nofollow\">?</a>$linktext</span>"
                }
        }
        
        $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\" />";
@@ -631,8 +648,9 @@ sub userlink ($) { #{{{
        }
 } #}}}
 
-sub htmlize ($$$) { #{{{
+sub htmlize ($$$$) { #{{{
        my $page=shift;
+       my $destpage=shift;
        my $type=shift;
        my $content=shift;
        
@@ -651,6 +669,7 @@ sub htmlize ($$$) { #{{{
        run_hooks(sanitize => sub {
                $content=shift->(
                        page => $page,
+                       destpage => $destpage,
                        content => $content,
                );
        });
@@ -682,7 +701,7 @@ sub linkify ($$$) { #{{{
        return $content;
 } #}}}
 
-my %preprocessing;
+our %preprocessing;
 our $preprocess_preview=0;
 sub preprocess ($$$;$$) { #{{{
        my $page=shift; # the page the data comes from
@@ -1183,6 +1202,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;
@@ -1252,6 +1277,7 @@ sub pagespec_translate ($) { #{{{
                $code=0;
        }
 
+       no warnings;
        return eval 'sub { my $page=shift; '.$code.' }';
 } #}}}
 
@@ -1266,7 +1292,7 @@ sub pagespec_match ($$;@) { #{{{
        }
 
        my $sub=pagespec_translate($spec);
-       return IkiWiki::FailReason->new('syntax error') if $@;
+       return IkiWiki::FailReason->new("syntax error in pagespec \"$spec\"") if $@;
        return $sub->($page, @params);
 } #}}}
 
@@ -1276,6 +1302,13 @@ sub pagespec_valid ($) { #{{{
        my $sub=pagespec_translate($spec);
        return ! $@;
 } #}}}
+       
+sub glob2re ($) { #{{{
+       my $re=quotemeta(shift);
+       $re=~s/\\\*/.*/g;
+       $re=~s/\\\?/./g;
+       return $re;
+} #}}}
 
 package IkiWiki::FailReason;
 
@@ -1287,7 +1320,9 @@ use overload ( #{{{
 ); #}}}
 
 sub new { #{{{
-       return bless \$_[1], $_[0];
+       my $class = shift;
+       my $value = shift;
+       return bless \$value, $class;
 } #}}}
 
 package IkiWiki::SuccessReason;
@@ -1300,7 +1335,9 @@ use overload ( #{{{
 ); #}}}
 
 sub new { #{{{
-       return bless \$_[1], $_[0];
+       my $class = shift;
+       my $value = shift;
+       return bless \$value, $class;
 }; #}}}
 
 package IkiWiki::PageSpec;
@@ -1319,12 +1356,8 @@ sub match_glob ($$;@) { #{{{
                $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");
                }