Template talk:MediaWikiHook/Archive 1
This page is an archive. Do not edit the contents of this page. Please direct any additional comments to the current talk page. |
Template:MediaWikiHook enhancements
- Default name: Defaulted name to subpage - e.g. Manual:Hooks/foobar defaults to foobar.
- 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
- 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.
- Added link to list of extensions using the hook:
- 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
- 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#Hooks grouped by function. 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#Categorization --Cneubauer 14:22, 22 February 2008 (UTC)
- Does this syntax look right?
{{#if:{{{function|}}}|[[Category:{{{function}}} hooks]]|}}
--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)
Hooks with "::" in their names
For hooks with "::" in their name (some were introduced in 1.19), this template will generate failing php code. You can't have "::" as part of a function name, so the "::" should probably be replaced by an empty string or underscore. I don't see any advantage in using "::" in a hook name anyhow, "_" seems more appropriate but I guess that's another story. --Danwe (talk) 13:19, 29 June 2012 (UTC)
- bump. maybe add a warning saying that this function name is not valid — MIRROR (talk) 06:37, 26 February 2013 (UTC)
Forthcoming hooks
What about forthcoming hooks, such as User:Leucosticte/Hooks/PageContentSaveRevision? Those shouldn't be in any categories. I'd change the template, but it looks pretty complicated. Leucosticte (talk) 03:26, 29 January 2014 (UTC)
Public static functions
Should it be listed like this:
public static function onTitleMoveComplete( Title &$title, Title &$newtitle, User &$user, $oldid, $newid, $reason ) { ... }
I.e. with those Titles in there? Leucosticte (talk) 22:40, 7 September 2014 (UTC)
Syntax highlighting
I've BOLDly added syntax highlighting capabilities to the template (and also fixed an alignment issue). Enjoy! --Ricordisamoa 05:08, 18 October 2014 (UTC)
Translation?
Could someone please mark the current changes for translation? Thanks! Sam Wilson 05:40, 10 October 2017 (UTC)