]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
Revert "Make srcfile() return undef, if the file isn't there."
[ikiwiki.git] / IkiWiki.pm
index cd93fe969de8a38b4356ad041ba7c1cf6de3b801..90e623330af4d760a9f941f14d04cf61b415b4c8 100644 (file)
@@ -14,7 +14,8 @@ use open qw{:utf8 :std};
 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
            %pagestate %wikistate %renderedfiles %oldrenderedfiles
            %pagesources %destsources %depends %depends_simple %hooks
-           %forcerebuild %loaded_plugins};
+           %forcerebuild %loaded_plugins @autofiles %dellinks
+           %delrenderedfiles};
 
 use Exporter q{import};
 our @EXPORT = qw(hook debug error template htmlpage deptype
@@ -22,7 +23,7 @@ our @EXPORT = qw(hook debug error template htmlpage deptype
                 htmllink readfile writefile pagetype srcfile pagename
                 displaytime will_render gettext urlto targetpage
                 add_underlay pagetitle titlepage linkpage newpagefile
-                inject add_link
+                inject add_link add_autofile
                  %config %links %pagestate %wikistate %renderedfiles
                  %pagesources %destsources);
 our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
@@ -881,7 +882,7 @@ sub bestlink ($$) {
                $l.="/" if length $l;
                $l.=$link;
 
-               if (exists $links{$l}) {
+               if (exists $pagesources{$l}) {
                        return $l;
                }
                elsif (exists $pagecase{lc $l}) {
@@ -891,7 +892,7 @@ sub bestlink ($$) {
 
        if (length $config{userdir}) {
                my $l = "$config{userdir}/".lc($link);
-               if (exists $links{$l}) {
+               if (exists $pagesources{$l}) {
                        return $l;
                }
                elsif (exists $pagecase{lc $l}) {
@@ -1081,11 +1082,10 @@ sub htmllink ($$$;@) {
        }
 
        my @attrs;
-       if (defined $opts{rel}) {
-               push @attrs, ' rel="'.$opts{rel}.'"';
-       }
-       if (defined $opts{class}) {
-               push @attrs, ' class="'.$opts{class}.'"';
+       foreach my $attr (qw{rel class title}) {
+               if (defined $opts{$attr}) {
+                       push @attrs, " $attr=\"$opts{$attr}\"";
+               }
        }
 
        return "<a href=\"$bestlink\"@attrs>$linktext</a>";
@@ -1408,7 +1408,7 @@ sub check_content (@) {
                my %old=map { $_ => 1 }
                        split("\n", readfile(srcfile($pagesources{$params{page}})));
                foreach my $line (split("\n", $params{content})) {
-                       push @diff, $line if ! exists $old{$_};
+                       push @diff, $line if ! exists $old{$line};
                }
                $params{diff}=join("\n", @diff);
        }
@@ -1896,6 +1896,14 @@ sub add_link ($$) {
                unless grep { $_ eq $link } @{$links{$page}};
 }
 
+sub add_autofile ($) {
+       my $addfile=shift;
+       my ($file,$page) = verify_src_file($addfile,$config{srcdir});
+       if ($page) {
+               push @autofiles, $file;
+       }
+}
+
 sub pagespec_translate ($) {
        my $spec=shift;
 
@@ -2071,7 +2079,7 @@ use overload (
        '""'    => sub { $_[0][0] },
        '0+'    => sub { 0 },
        '!'     => sub { bless $_[0], 'IkiWiki::SuccessReason'},
-       '&'     => sub { $_[0]->merge_influences($_[1]); $_[0] },
+       '&'     => sub { $_[0]->merge_influences($_[1], 1); $_[0] },
        '|'     => sub { $_[1]->merge_influences($_[0]); $_[1] },
        fallback => 1,
 );
@@ -2084,7 +2092,7 @@ use overload (
        '""'    => sub { $_[0][0] },
        '0+'    => sub { 1 },
        '!'     => sub { bless $_[0], 'IkiWiki::FailReason'},
-       '&'     => sub { $_[1]->merge_influences($_[0]); $_[1] },
+       '&'     => sub { $_[1]->merge_influences($_[0], 1); $_[1] },
        '|'     => sub { $_[0]->merge_influences($_[1]); $_[0] },
        fallback => 1,
 );
@@ -2110,8 +2118,17 @@ sub influences_static {
 sub merge_influences {
        my $this=shift;
        my $other=shift;
-       foreach my $influence (keys %{$other->[1]}) {
-               $this->[1]{$influence} |= $other->[1]{$influence};
+       my $anded=shift;
+
+       if (! $anded || (($this || %{$this->[1]}) &&
+                       ($other || %{$other->[1]}))) {
+               foreach my $influence (keys %{$other->[1]}) {
+                       $this->[1]{$influence} |= $other->[1]{$influence};
+               }
+       }
+       else {
+               # influence blocker
+               $this->[1]={};
        }
 }
 
@@ -2168,7 +2185,7 @@ sub match_link ($$;@) {
        my $from=exists $params{location} ? $params{location} : '';
 
        my $links = $IkiWiki::links{$page};
-       return IkiWiki::FailReason->new("$page has no links")
+       return IkiWiki::FailReason->new("$page has no links", "" => 1)
                unless $links && @{$links};
        my $bestlink = IkiWiki::bestlink($from, $link);
        foreach my $p (@{$links}) {