Template talk:MediaWikiHook/Archive 1

Template:MediaWikiHook enhancements
Egfrank 10:49, 10 September 2007 (UTC)
 * 1) Default name: Defaulted name to subpage - e.g. Manual:Hooks/foobar defaults to foobar.
 * 2) Default version: Defaulted missing and blank versions to ??? and placed them into a category so that they can be cleaned up and assigned to their starting version
 * 3) Nocats mode: Added a way to suppress categories so that the template image can be inserted on pages without adding all the categories normally added by the template. It works like Template:Extensions - just set the templatemode parameter to nocats.  For an example, see the wiki text for Template:MediaWikiHook/Doc.
 * 4) Added link to list of extensions using the hook:
 * 5) Clarified message associated with Manual:Hooks: Old message made it sound like one was getting more information on the hook itself rather than on attaching the hook
 * 6) Separate doc page: Teased apart documentation and code - documentation is now on MediaWikiHook/Doc

Suggestion for Function Parameter
Hi, I suggest adding a new template parameter called function. This would correspond to the functions listed in Manual:Hooks. After each hook has a function filled in, we can get rid of the tables on Manual:Hooks and instead generate them dynamically with DPL or a bot (like Extension Matrix). See also, the discussion here: Manual talk:Hooks --Cneubauer 14:22, 22 February 2008 (UTC)


 * Does this syntax look right?    --Cneubauer 20:09, 6 March 2008 (UTC)

Marking obsolete hooks
I think we should add an optional parameter for the last version of MediaWiki that this hook existed in so it would be easier to mark obsolete hooks. Something like lastversion=. --Cneubauer 13:31, 12 June 2008 (UTC)

Hooks classes
See also Thread:Project_talk:Support_desk/Hooks_Definitions_are_confusing_to_me

The sample shown here is the function definition, not the class definition. Therefor the class is not included each time, because an extension only needs one hooks class.

So assuming you have a basic extensions skeleton like this:

-- ./extensions/FooBar/FooBar.php $dir = dirname( __FILE__ );

$wgAutoloadClasses['FooBarHooks'] = dirname( __FILE__ ). '/FooBar.hooks.php'; $wgExtensionMessagesFiles['FooBar'] = $dir. '/FooBar.i18n.php';

$wgHooks['GetPreferences'][] = 'FooBarHooks::onGetPreferences';

-- ./extensions/FooBar/FooBar.hooks.php

class FooBarHooks {

public static function onGetPreferences( $user, &$defaultPreferences ) { /* .. */   } }

-- ./extensions/FooBar/FooBar.i8n.php

$messages = array;

The "Function definition" goes into FooBarHooks, and the "Attach hook" goes into the main "FooBar" file. Krinkle (talk) 04:28, 3 May 2012 (UTC)