]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
web commit by neal: Note how wiki links related to file names.
[ikiwiki.git] / IkiWiki.pm
index cadbfd67f676114309845ef568783384fa057360..560647e067f224bd62d2c9cd49b9c17359933b9f 100644 (file)
@@ -10,12 +10,13 @@ use open qw{:utf8 :std};
 # Optimisation.
 use Memoize;
 memoize("abs2rel");
+memoize("pagespec_translate");
 
-use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
+use vars qw{%config %links %oldlinks %oldpagemtime %pagectime %pagecase
             %renderedfiles %pagesources %depends %hooks %forcerebuild};
 
 sub defaultconfig () { #{{{
-       wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$|\.rss$)},
+       wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.x?html?$|\.rss$)},
        wiki_link_regexp => qr/\[\[(?:([^\]\|]+)\|)?([^\s\]]+)\]\]/,
        wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]*)\]\]/,
        wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
@@ -237,7 +238,7 @@ sub bestlink ($$) { #{{{
        # goes down the directory tree to the base looking for matching
        # pages.
        my $page=shift;
-       my $link=lc(shift);
+       my $link=shift;
        
        my $cwd=$page;
        do {
@@ -246,9 +247,11 @@ sub bestlink ($$) { #{{{
                $l.=$link;
 
                if (exists $links{$l}) {
-                       #debug("for $page, \"$link\", use $l");
                        return $l;
                }
+               elsif (exists $pagecase{lc $l}) {
+                       return $pagecase{lc $l};
+               }
        } while $cwd=~s!/?[^/]+$!!;
 
        #print STDERR "warning: page $page, broken link: $link\n";
@@ -332,7 +335,7 @@ sub htmllink ($$$;$$$) { #{{{
        }
        if (! grep { $_ eq $bestlink } values %renderedfiles) {
                return "<span><a href=\"".
-                       cgiurl(do => "create", page => $link, from => $page).
+                       cgiurl(do => "create", page => lc($link), from => $page).
                        "\">?</a>$linktext</span>"
        }
        
@@ -394,6 +397,7 @@ sub loadindex () { #{{{
                        $links{$page}=[@{$items{link}}];
                        $depends{$page}=$items{depends}[0] if exists $items{depends};
                        $renderedfiles{$page}=$items{dest}[0];
+                       $pagecase{lc $page}=$page;
                }
                $pagectime{$page}=$items{ctime}[0];
        }
@@ -431,7 +435,10 @@ sub template_params (@) { #{{{
                        my $text_ref = shift;
                        $$text_ref=&Encode::decode_utf8($$text_ref);
                },
-               filename => "$config{templatedir}/$filename", @_;
+               filename => "$config{templatedir}/$filename",
+               loop_context_vars => 1,
+               die_on_bad_params => 0,
+               @_;
 } #}}}
 
 sub template ($;@) { #{{{
@@ -529,8 +536,9 @@ sub pagespec_merge ($$) { #{{{
        return "($a) or ($b)";
 } #}}}
 
-sub pagespec_match ($$) { #{{{
-       my $page=shift;
+sub pagespec_translate ($) { #{{{
+       # This assumes that $page is in scope in the function
+       # that evalulates the translated pagespec code.
        my $spec=shift;
 
        # Support for old-style GlobLists.
@@ -551,7 +559,7 @@ sub pagespec_match ($$) { #{{{
                elsif ($word eq "(" || $word eq ")" || $word eq "!") {
                        $code.=" ".$word;
                }
-               elsif ($word =~ /^(link|backlink|creation_month|creation_year|creation_day)\((.+)\)$/) {
+               elsif ($word =~ /^(link|backlink|created_before|created_after|creation_month|creation_year|creation_day)\((.+)\)$/) {
                        $code.=" match_$1(\$page, ".safequote($2).")";
                }
                else {
@@ -559,7 +567,14 @@ sub pagespec_match ($$) { #{{{
                }
        }
 
-       return eval $code;
+       return $code;
+} #}}}
+
+sub pagespec_match ($$) { #{{{
+       my $page=shift;
+       my $spec=shift;
+
+       return eval pagespec_translate($spec);
 } #}}}
 
 sub match_glob ($$) { #{{{
@@ -576,7 +591,7 @@ sub match_glob ($$) { #{{{
 
 sub match_link ($$) { #{{{
        my $page=shift;
-       my $link=shift;
+       my $link=lc(shift);
 
        my $links = $links{$page} or return undef;
        foreach my $p (@$links) {
@@ -586,20 +601,43 @@ sub match_link ($$) { #{{{
 } #}}}
 
 sub match_backlink ($$) { #{{{
-       match_link(reverse @_);
+       match_link(pop, pop);
+} #}}}
+
+sub match_created_before ($$) { #{{{
+       my $page=shift;
+       my $testpage=shift;
+
+       if (exists $pagectime{$testpage}) {
+               return $pagectime{$page} < $pagectime{$testpage};
+       }
+       else {
+               return 0;
+       }
+} #}}}
+
+sub match_created_after ($$) { #{{{
+       my $page=shift;
+       my $testpage=shift;
+
+       if (exists $pagectime{$testpage}) {
+               return $pagectime{$page} > $pagectime{$testpage};
+       }
+       else {
+               return 0;
+       }
 } #}}}
 
 sub match_creation_day ($$) { #{{{
-       return if (gmtime($pagectime{shift()}))[3] == shift;
+       return ((gmtime($pagectime{shift()}))[3] == shift);
 } #}}}
 
 sub match_creation_month ($$) { #{{{
-       return if (gmtime($pagectime{shift()}))[4] + 1 == shift;
+       return ((gmtime($pagectime{shift()}))[4] + 1 == shift);
 } #}}}
 
 sub match_creation_year ($$) { #{{{
-       return if (gmtime($pagectime{shift()}))[5] + 1900 == shift;
+       return ((gmtime($pagectime{shift()}))[5] + 1900 == shift);
 } #}}}
 
-
 1