Merge remote branch 'davrieb/autotag' into autotag
[ikiwiki.git] / IkiWiki.pm
index 74d452c502955993635d665ceaaa6f9ac4751b45..2f26a16ce5b361480d3e1b56e425f27020dd6f6c 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 %typedlinks %oldtypedlinks};
+           %forcerebuild %loaded_plugins %typedlinks %oldtypedlinks
+           %autofiles %del_hash};
 
 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 ngettext urlto targetpage
                 add_underlay pagetitle titlepage linkpage newpagefile
-                inject add_link
+                inject add_link add_autofile
                  %config %links %pagestate %wikistate %renderedfiles
                  %pagesources %destsources %typedlinks);
 our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
@@ -440,10 +441,9 @@ sub getsetup () {
                safe => 0,
                rebuild => 0,
        },
-       getctime => {
+       gettime => {
                type => "internal",
-               default => 0,
-               description => "running in getctime mode",
+               description => "running in gettime mode",
                safe => 0,
                rebuild => 0,
        },
@@ -1512,6 +1512,7 @@ sub loadindex () {
                        open ($in, "<", "$config{wikistatedir}/indexdb") || return;
                }
                else {
+                       $config{gettime}=1; # first build
                        return;
                }
        }
@@ -1790,6 +1791,10 @@ sub rcs_getctime ($) {
        $hooks{rcs}{rcs_getctime}{call}->(@_);
 }
 
+sub rcs_getmtime ($) {
+       $hooks{rcs}{rcs_getmtime}{call}->(@_);
+}
+
 sub rcs_receive () {
        $hooks{rcs}{rcs_receive}{call}->();
 }
@@ -2016,6 +2021,30 @@ sub sortspec_translate ($$) {
        return eval 'sub { '.$code.' }';
 }
 
+sub add_autofile ($$) {
+       my $autofile=shift;
+       my $plugin=shift;
+
+       if (srcfile($autofile, 1)) {
+               return 0;
+       }
+
+       my ($file, $page) = verify_src_file("$config{srcdir}/$autofile", $config{srcdir});
+
+       if ((!defined $file) ||
+       (exists $pagestate{$page}{$plugin}{autofile_deleted})) {
+               return 0;
+       }
+
+       if (exists $del_hash{$file}) {
+               $pagestate{$page}{$plugin}{autofile_deleted}=1;
+               return 0;
+       }
+
+       $autofiles{$file}=$plugin;
+       return 1;
+}
+
 sub pagespec_translate ($) {
        my $spec=shift;
 
@@ -2102,6 +2131,8 @@ sub pagespec_match_list ($$;@) {
        my $sub=pagespec_translate($pagespec);
        error "syntax error in pagespec \"$pagespec\""
                if ! defined $sub;
+       my $sort=sortspec_translate($params{sort}, $params{reverse})
+               if defined $params{sort};
 
        my @candidates;
        if (exists $params{list}) {
@@ -2115,21 +2146,18 @@ sub pagespec_match_list ($$;@) {
                        : keys %pagesources;
        }
        
+       # clear params, remainder is passed to pagespec
+       $depends{$page}{$pagespec} |= ($params{deptype} || $DEPEND_CONTENT);
        my $num=$params{num};
-       my $sort=$params{sort};
-       my $reverse=$params{reverse};
+       delete @params{qw{num deptype reverse sort filter list}};
+       
        # when only the top matches will be returned, it's efficient to
        # sort before matching to pagespec,
        if (defined $num && defined $sort) {
                @candidates=IkiWiki::SortSpec::sort_pages(
-                       $sort, $reverse, @candidates);
+                       $sort, @candidates);
        }
        
-       $depends{$page}{$pagespec} |= ($params{deptype} || $DEPEND_CONTENT);
-       
-       # clear params, remainder is passed to pagespec
-       delete @params{qw{num deptype reverse sort filter list}};
-       
        my @matches;
        my $firstfail;
        my $count=0;
@@ -2155,7 +2183,7 @@ sub pagespec_match_list ($$;@) {
        # sort after matching
        if (! defined $num && defined $sort) {
                return IkiWiki::SortSpec::sort_pages(
-                       $sort, $reverse, @matches);
+                       $sort, @matches);
        }
        else {
                return @matches;
@@ -2452,7 +2480,7 @@ package IkiWiki::SortSpec;
 # This is in the SortSpec namespace so that the $a and $b that sort() uses
 # are easily available in this namespace, for cmp functions to use them.
 sub sort_pages {
-       my $f=IkiWiki::sortspec_translate(shift, shift);
+       my $f=shift;
        sort $f @_
 }