jenkins-bot has submitted this change and it was merged.
Change subject: registration: Allow string value for Hooks
......................................................................
registration: Allow string value for Hooks
Instead of forcing an object even for single-hook-listeners, allow
string values, too (one hook listener for one hook, only). Also:
use it as default for the conversion script, if only one listener
is added to a hook (which is usually the case). This leads into a
much cleaner output of the Hooks section of extension.json.
Bug: T133628
Change-Id: Ie9e54f0931c41706eb8d82d00256698992ec41cc
---
M docs/extension.schema.json
M includes/registration/ExtensionProcessor.php
M maintenance/convertExtensionToRegistration.php
M tests/phpunit/includes/registration/ExtensionProcessorTest.php
4 files changed, 18 insertions(+), 5 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/extension.schema.json b/docs/extension.schema.json
old mode 100644
new mode 100755
index 3c2c057..ed3eaa9
--- a/docs/extension.schema.json
+++ b/docs/extension.schema.json
@@ -684,7 +684,7 @@
"type": "object"
},
"Hooks": {
- "type": "object",
+ "type": [ "string", "object" ],
"description": "Hooks this extension uses (mapping of
hook name to callback)"
},
"JobClasses": {
diff --git a/includes/registration/ExtensionProcessor.php
b/includes/registration/ExtensionProcessor.php
old mode 100644
new mode 100755
index f977124..415e664
--- a/includes/registration/ExtensionProcessor.php
+++ b/includes/registration/ExtensionProcessor.php
@@ -209,8 +209,12 @@
protected function extractHooks( array $info ) {
if ( isset( $info['Hooks'] ) ) {
foreach ( $info['Hooks'] as $name => $value ) {
- foreach ( (array)$value as $callback ) {
- $this->globals['wgHooks'][$name][] =
$callback;
+ if ( is_array( $value ) ) {
+ foreach ( $value as $callback ) {
+
$this->globals['wgHooks'][$name][] = $callback;
+ }
+ } else {
+ $this->globals['wgHooks'][$name][] =
$value;
}
}
}
diff --git a/maintenance/convertExtensionToRegistration.php
b/maintenance/convertExtensionToRegistration.php
old mode 100644
new mode 100755
index 8993146..f9dd58c
--- a/maintenance/convertExtensionToRegistration.php
+++ b/maintenance/convertExtensionToRegistration.php
@@ -216,7 +216,7 @@
}
public function handleHooks( $realName, $value ) {
- foreach ( $value as $hookName => $handlers ) {
+ foreach ( $value as $hookName => &$handlers ) {
foreach ( $handlers as $func ) {
if ( $func instanceof Closure ) {
$this->error( "Error: Closures cannot
be converted to JSON. " .
@@ -230,6 +230,9 @@
);
}
}
+ if ( count( $handlers ) === 1 ) {
+ $handlers = $handlers[0];
+ }
}
$this->json[$realName] = $value;
}
diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php
b/tests/phpunit/includes/registration/ExtensionProcessorTest.php
index 27c0c60..0120d79 100644
--- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php
+++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php
@@ -50,7 +50,7 @@
self::$default,
$merge,
],
- // No current hooks, adding one for "FooBaz"
+ // No current hooks, adding one for "FooBaz" in string
format
[
[],
[ 'Hooks' => [ 'FooBaz' => 'FooBazCallback' ] ]
+ self::$default,
@@ -62,6 +62,12 @@
[ 'Hooks' => [ 'FooBaz' => 'FooBazCallback' ] ]
+ self::$default,
[ 'FooBaz' => [ 'PriorCallback',
'FooBazCallback' ] ] + $merge,
],
+ // No current hooks, adding one for "FooBaz" in verbose
array format
+ [
+ [],
+ [ 'Hooks' => [ 'FooBaz' => [ 'FooBazCallback' ]
] ] + self::$default,
+ [ 'FooBaz' => [ 'FooBazCallback' ] ] + $merge,
+ ],
// Hook for "BarBaz", adding one for "FooBaz"
[
[ 'BarBaz' => [ 'BarBazCallback' ] ],
--
To view, visit https://gerrit.wikimedia.org/r/286241
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie9e54f0931c41706eb8d82d00256698992ec41cc
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits