On Wed, 03 Apr 2013 18:51:54 -0700, Jeroen De Dauw jeroendedauw@gmail.com wrote:
Hey,
I'm curious what the list thinks of deprecating and eventually removing the Hooks class.
I see no reason to get rid of the hooks class. We use static classes other places in core. And there's no reason to revert to hideous functions like we had before. There's enough code logic there to justify packaging it into a static class.
Interfaces like these have really slow uptake because extensions always wait a long time to pick them up because using them fundamentally means dropping compatibility with a version of MW earlier than the one it was introduced in.
Hooks was only added in 1.18 and extensions have a habit of retaining compatibility for old versions of MediaWiki for a significant time even after we make that version EOL. It's not unexpected to see extensions not using the interface yet.
Quite frankly: Hooks::register( 'BeforePageDisplay', 'MyExt::pageDisplay' );
Is quite nicer than the backcompat: $wgHooks['BeforePageDisplay'][] = 'MyExt::pageDisplay';
In the event of a global typo it'll error out instead of silently not working. The argument structure is cleaner and you can't inadvertently break everything by forgetting to add the "[]" which to the casual extension author may not be totally apparent. Oh... ;) and no spending hours trying to find out why your hook isn't being called cause you moved your hook call to an extension function so you could vary by user config but forgot to add `global $wgHooks;` to your function. If in the future we require core and extensions to register the hooks they call it also leaves the possibility of warning extension authors when they typo a hook name, with a proper trace where they made the mistake.
And it gives us room to consider the possibility of doing something like turning: Hooks::register( 'BeforePageDisplay', array( 'MyExt::pageDisplay', $data ) );
Into just: Hooks::register( 'BeforePageDisplay', 'MyExt::pageDisplay', $data );
""Used to supersede $wgHooks, because globals are EVIL.""
I personally find the comment hilarious and hope you see why when looking at the "class". Looks like usage in core and extensions is not to extensive, so switching to something more sane seems quite feasible.
Btw, I hope you're not finding the comment funny by misreading "Used" as "In the past" when it's actually the action "to use".
Cheers
-- Jeroen De Dauw http://www.bn2vs.com Don't panic. Don't be evil.