-sub preprocess ($$;$) { #{{{
- my $page=shift;
- my $content=shift;
- my $onlystrip=shift || 0; # strip directives without processing
-
- my $handle=sub {
- my $escape=shift;
- my $command=shift;
- my $params=shift;
- if (length $escape) {
- return "[[$command $params]]";
- }
- elsif ($onlystrip) {
- return "";
- }
- elsif (exists $hooks{preprocess}{$command}) {
- # Note: preserve order of params, some plugins may
- # consider it significant.
- my @params;
- while ($params =~ /(?:(\w+)=)?(?:"([^"]+)"|(\S+))(?:\s+|$)/g) {
- if (defined $1) {
- push @params, $1, (defined $2 ? $2 : $3);
- }
- else {
- push @params, (defined $2 ? $2 : $3), '';
- }
- }
- return $hooks{preprocess}{$command}{call}->(@params, page => $page);
- }
- else {
- return "[[$command not processed]]";
- }
- };
-
- $content =~ s{(\\?)$config{wiki_processor_regexp}}{$handle->($1, $2, $3)}eg;
- return $content;
-} #}}}
-
-sub add_depends ($$) { #{{{
- my $page=shift;
- my $globlist=shift;
-
- if (! exists $depends{$page}) {
- $depends{$page}=$globlist;
- }
- else {
- $depends{$page}=globlist_merge($depends{$page}, $globlist);
- }
-} # }}}
-
-sub globlist_merge ($$) { #{{{
- my $a=shift;
- my $b=shift;
-
- my $ret="";
- # Only add negated globs if they are not matched by the other globlist.
- foreach my $i ((map { [ $a, $_ ] } split(" ", $b)),
- (map { [ $b, $_ ] } split(" ", $a))) {
- if ($i->[1]=~/^!(.*)/) {
- if (! globlist_match($1, $i->[0])) {
- $ret.=" ".$i->[1];
- }
- }
- else {
- $ret.=" ".$i->[1];
- }
- }
-
- return $ret;
-} #}}}
-