]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
smiley: Generate links relative to the destpage. (Fixes a reversion from 2.41.)
[ikiwiki.git] / IkiWiki.pm
index d1b65cd5129365db7e5998da7627e08f5dd0ae7f..7d5668d74d6899f08019b964517223b693606db5 100644 (file)
@@ -103,6 +103,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,17 +288,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");
+       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;
 
@@ -536,7 +547,7 @@ sub urlto ($$) { #{{{
        my $from=shift;
 
        if (! length $to) {
-               return beautify_url(baseurl($from));
+               return beautify_url(baseurl($from)."index.$config{htmlext}");
        }
 
        if (! $destsources{$to}) {
@@ -587,7 +598,7 @@ sub htmllink ($$$;@) { #{{{
                                        page => pagetitle(lc($link), 1),
                                        from => $lpage
                                ).
-                               "\">?</a>$linktext</span>"
+                               "\" rel=\"nofollow\">?</a>$linktext</span>"
                }
        }
        
@@ -621,14 +632,18 @@ sub userlink ($) { #{{{
                return "<a href=\"$user\">$oiduser</a>";
        }
        else {
+               eval q{use CGI 'escapeHTML'};
+               error($@) if $@;
+
                return htmllink("", "", escapeHTML(
                        length $config{userdir} ? $config{userdir}."/".$user : $user
                ), noimageinline => 1);
        }
 } #}}}
 
-sub htmlize ($$$) { #{{{
+sub htmlize ($$$$) { #{{{
        my $page=shift;
+       my $destpage=shift;
        my $type=shift;
        my $content=shift;
        
@@ -647,6 +662,7 @@ sub htmlize ($$$) { #{{{
        run_hooks(sanitize => sub {
                $content=shift->(
                        page => $page,
+                       destpage => $destpage,
                        content => $content,
                );
        });
@@ -678,7 +694,7 @@ sub linkify ($$$) { #{{{
        return $content;
 } #}}}
 
-my %preprocessing;
+our %preprocessing;
 our $preprocess_preview=0;
 sub preprocess ($$$;$$) { #{{{
        my $page=shift; # the page the data comes from
@@ -1244,6 +1260,11 @@ sub pagespec_translate ($) { #{{{
                }
        }
 
+       if (! length $code) {
+               $code=0;
+       }
+
+       no warnings;
        return eval 'sub { my $page=shift; '.$code.' }';
 } #}}}
 
@@ -1258,7 +1279,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);
 } #}}}
 
@@ -1279,7 +1300,9 @@ use overload ( #{{{
 ); #}}}
 
 sub new { #{{{
-       return bless \$_[1], $_[0];
+       my $class = shift;
+       my $value = shift;
+       return bless \$value, $class;
 } #}}}
 
 package IkiWiki::SuccessReason;
@@ -1292,7 +1315,9 @@ use overload ( #{{{
 ); #}}}
 
 sub new { #{{{
-       return bless \$_[1], $_[0];
+       my $class = shift;
+       my $value = shift;
+       return bless \$value, $class;
 }; #}}}
 
 package IkiWiki::PageSpec;