X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/11ff91a6ed7ca42336587d1320ea7fa6e23abaaf..dd74a51c96d4cdee2bfc741e5aec0a378e2c644f:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index 991ff9ecb..560647e06 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -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 " "create", page => $link, from => $page). + cgiurl(do => "create", page => lc($link), from => $page). "\">?$linktext" } @@ -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 ($$) { #{{{ @@ -571,12 +586,12 @@ sub match_glob ($$) { #{{{ $glob=~s/\\\*/.*/g; $glob=~s/\\\?/./g; - return $page=~/^$glob$/; + return $page=~/^$glob$/i; } #}}} 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,27 +601,43 @@ sub match_link ($$) { #{{{ } #}}} sub match_backlink ($$) { #{{{ + match_link(pop, pop); +} #}}} + +sub match_created_before ($$) { #{{{ my $page=shift; - my $linkto=shift; + my $testpage=shift; - my $links = $links{$linkto} or return undef; - foreach my $p (@$links) { - return 1 if lc $p eq $page; + 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; } - 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