summaryrefslogtreecommitdiff
path: root/IkiWiki.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2008-12-26 16:08:33 -0500
committerJoey Hess <joey@gnu.kitenet.net>2008-12-26 16:09:23 -0500
commit7da319efc69089662f9635216bbcc48ca53fe606 (patch)
tree4e64e5fe5794544f8b6eae29d8b35504cea13e16 /IkiWiki.pm
parent9db06329c98e1a390bbb6323de02dc7e2f45f1f8 (diff)
inline: Run format hook first
inline has a format hook that is an optimisation hack. Until this hook runs, the inlined content is not present on the page. This can prevent other format hooks, that process that content, from acting on inlined content. In bug ##509710, we discovered this happened commonly for the embed plugin, but it could in theory happen for many other plugins (color, cutpaste, etc) that use format to fill in special html after sanitization. The ordering was essentially random (hash key order). That's kinda a good thing, because hooks should be independent of other hooks and able to run in any order. But for things like inline, that just doesn't work. To fix the immediate problem, let's make hooks able to be registered as running "first". There was already the ability to make them run "last". Now, this simple first/middle/last ordering is obviously not going to work if a lot of things need to run first, or last, since then we'll be back to being unable to specify ordering inside those sets. But before worrying about that too much, and considering dependency ordering, etc, observe how few plugins use last ordering: Exactly one needs it. And, so far, exactly one needs first ordering. So for now, KISS. Another implementation note: I could have sorted the plugins with first/last/middle as the primary key, and plugin name secondary, to get a guaranteed stable order. Instead, I chose to preserve hash order. Two opposing things pulled me toward that decision: 1. Since has order is randomish, it will ensure that no accidental ordering assumptions are made. 2. Assume for a minute that ordering matters a lot more than expected. Drastically changing the order a particular configuration uses could result in a lot of subtle bugs cropping up. (I hope this assumption is false, partly due to #1, but can't rule it out.)
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r--IkiWiki.pm16
1 files changed, 10 insertions, 6 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index cc1e89acc..54e00ec7b 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -1536,15 +1536,19 @@ sub run_hooks ($$) {
my $sub=shift;
if (exists $hooks{$type}) {
- my @deferred;
+ my (@first, @middle, @last);
foreach my $id (keys %{$hooks{$type}}) {
- if ($hooks{$type}{$id}{last}) {
- push @deferred, $id;
- next;
+ if ($hooks{$type}{$id}{first}) {
+ push @first, $id;
+ }
+ elsif ($hooks{$type}{$id}{last}) {
+ push @last, $id;
+ }
+ else {
+ push @middle, $id;
}
- $sub->($hooks{$type}{$id}{call});
}
- foreach my $id (@deferred) {
+ foreach my $id (@first, @middle, @last) {
$sub->($hooks{$type}{$id}{call});
}
}