From 2fcd5d7909401e1fec9856999ba439eed4d01561 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 13 May 2015 12:30:21 -0700 Subject: [PATCH] registration: Fix having multiple callbacks for a single hook Bug: T98975 Change-Id: I40ff36090d18344fabdb018519209671b7883fa1 --- includes/registration/ExtensionProcessor.php | 6 ++++-- .../registration/ExtensionProcessorTest.php | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index 4b9a7546a0..23a2993ec9 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -152,8 +152,10 @@ class ExtensionProcessor implements Processor { protected function extractHooks( array $info ) { if ( isset( $info['Hooks'] ) ) { - foreach ( $info['Hooks'] as $name => $callable ) { - $this->globals['wgHooks'][$name][] = $callable; + foreach ( $info['Hooks'] as $name => $value ) { + foreach ( (array)$value as $callback ) { + $this->globals['wgHooks'][$name][] = $callback; + } } $this->processed[] = 'Hooks'; } diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php b/tests/phpunit/includes/registration/ExtensionProcessorTest.php index b95316c20b..d47ffa9461 100644 --- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php +++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php @@ -36,6 +36,10 @@ class ExtensionProcessorTest extends MediaWikiTestCase { } public static function provideRegisterHooks() { + // Format: + // Current $wgHooks + // Content in extension.json + // Expected value of $wgHooks return array( // No hooks array( @@ -64,6 +68,22 @@ class ExtensionProcessorTest extends MediaWikiTestCase { 'FooBaz' => array( 'FooBazCallback' ), ), ), + // Callbacks for FooBaz wrapped in an array + array( + array(), + array( 'Hooks' => array( 'FooBaz' => array( 'Callback1' ) ) ) + self::$default, + array( + 'FooBaz' => array( 'Callback1' ), + ), + ), + // Multiple callbacks for FooBaz hook + array( + array(), + array( 'Hooks' => array( 'FooBaz' => array( 'Callback1', 'Callback2' ) ) ) + self::$default, + array( + 'FooBaz' => array( 'Callback1', 'Callback2' ), + ), + ), ); } -- 2.20.1