From: DannyS712 Date: Mon, 19 Aug 2019 07:01:43 +0000 (+0000) Subject: hooks.txt: Convert docs to modern extension registration style X-Git-Tag: 1.34.0-rc.0~666^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/%22%20.%20generer_url_entite%28%24id_rubrique%2C?a=commitdiff_plain;h=b01fbfeb40aa045a53cc38e3b57a5a6ebfced3ac;p=lhc%2Fweb%2Fwiklou.git hooks.txt: Convert docs to modern extension registration style This changes the examples in hooks.txt from using the old format of manually entering additions into `wgHooks` to instead use the new `"Hooks“: {}` object format. Bug: T230397 Change-Id: I48a9986e4243eb933088d36b4bb095b345ab62fd --- diff --git a/docs/hooks.txt b/docs/hooks.txt index d832012df5..6207b12e2b 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -91,23 +91,29 @@ title-reversing if-blocks spread all over the codebase in showAnArticle, deleteAnArticle, exportArticle, etc., we can concentrate it all in an extension file: - function reverseArticleTitle( $article ) { + function onArticleShow( &$article ) { # ... } - function reverseForExport( $article ) { + function onArticleDelete( &$article ) { # ... } -The setup function for the extension just has to add its hook functions to the -appropriate events: - - setupTitleReversingExtension() { - global $wgHooks; + function onArticleExport( &$article ) { + # ... + } - $wgHooks['ArticleShow'][] = 'reverseArticleTitle'; - $wgHooks['ArticleDelete'][] = 'reverseArticleTitle'; - $wgHooks['ArticleExport'][] = 'reverseForExport'; +General practice is to have a dedicated file for functions activated by hooks, +which functions named 'onHookName'. In the example above, the file +'ReverseHooks.php' includes the functions that should be activated by the +'ArticleShow', 'ArticleDelete', and 'ArticleExport' hooks. The 'extension.json' +file with the extension's registration just has to add its hook functions +to the appropriate events: + + "Hooks": { + "ArticleShow": "ReverseHooks:onArticleShow", + "ArticleDelete": "ReverseHooks::onArticleDelete", + "ArticleExport": "ReverseHooks::onArticleExport" } Having all this code related to the title-reversion option in one place means