Hi Evan,
Great stuff. I had originally just been thinking about refactoring the
context setting into its own method such that it could be overridden by
subclassed skin allowing that skin to introduce it's own variables into the
context. This strategy is much more general and obvious.
I think I found a good point SkinTemplate's outputpage method for a set of
hooks.
---------------
First, right after the template if first initialized (around line 160), up
until the point right before execution.
$this->initPage( $out );
$tpl =& $this->setupTemplate( $this->template, 'skins' );
if (wfRunHooks('OutputPage', $tpl)) {
...
wfRunHooks('OutputPageComplete', $tpl);
}
// execute template
wfProfileIn( "$fname-execute" );
$res = $tpl->execute();
wfProfileOut( "$fname-execute" );
-----------
Where you might want to use them like this:
--------------------------
<?php
function doNothing(&$tpl) {
wfDebug("**** Entering doNothing\n");
return true;
}
function putWeatherInContext(&$tpl) {
wfDebug("**** Entering putWeatherInContext\n");
$tpl->set('weather', "Partly Cloudy");
return true;
}
function setupCustomOutput() {
global $wgHooks;
$wgHooks['OutputPage'][] = 'doNothing';
$wgHooks['OutputPageComplete'][] = 'putWeatherInContext';
}
?>
I have successfully been able to define and run my hooks, and I am sure they
are being called, but
I am having a little bit of trouble getting a reference to the template over
my methods.
To use the template so that I can write to it once I get it, I think I need
to have a reference, not a copy.
I am afraid that the references might be getting lost in the Hook.php,
either when getting the varible argument parameters using the func_get_args
method, or when calling the method using the call_user_fucn technique,
perhaps in both places.
http://us2.php.net/func_get_args (see fbeyer at clickhand dot de dot
noSpamPlease
19-Jan-2002 08:02 )
http://cppref.thomason.homeip.net/phpref/function.call-user-func.html
http://php.planetmirror.com/manual/en/language.references.pass.php (see ben
at mekhaye dot net
02-Sep-2004 07:27 )
I'll admit that my php is a bit rusty, and that I have gotten used to
languages where all objects are first class, but I think this might affect
situations other than mine.
Otherwise, one other comment. I wonder if it might make sense to have the
user defined data arguments and the hook parameters bundled in in a named
dictionary so that the method signatures would never need to change, even if
new parameters needed to be added.
the fixed api of all functions would be
myHookFunction ($dataArgsArray, $parameterArray)
Where the data array and the parameter array would contain all the values
you wanted passed through keyed by the parameter name. This "api" might
allow for more flexibility in the future.
I know this introduces even more deferencing, but it might be hard to
anticipate all the parameters that a hook might eventually need upfront.
I am not certain if packaging the data args and the hook args in
dictionaries will simplify the reference problem (I would hope that if you
manage to get a ref into the dict, it should still be one after its passed
to the hook method through call_user_func, but I am still experimenting with
this).
Anyway, I wanted to check in on this matter before I took this any further.
ps - it would be really cool if the new unittesting framework covered these
hooks. I am trying to think about how I might write up a test or two, maybe
using a specific set of hooks, which would imply that the overall framework
is working. Any ideas?
Thanks
Jonah