Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/286241

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
3 files changed, 11 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/41/286241/1

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;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/286241
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie9e54f0931c41706eb8d82d00256698992ec41cc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to