Ori.livneh has uploaded a new change for review.

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


Change subject: Allow explicit & implicit null returns from hook handlers
......................................................................

Allow explicit & implicit null returns from hook handlers

Most hook handlers are written with the intent of complementing or augmenting
core functionality rather than vetoing it, making it quite natural for a
developer to forget that the caller is waiting for permission to proceed. The
potential for confusion is magnified by the fact that DOM event handlers and
jQuery event handlers are not required to return an explicit value for the
handled event to continue propagating.

This change tolerates null return values (both implicit and explicit -- that
is, both 'return null' and no return statement at all) from hook handlers. To
abort processing, a hook function must return an explicit false or an error
string.

This change should not break any existing hook functions, as returning null is
currently an error.

Bug: 50134
Change-Id: I11deb2117ff9233c77868470f50e0d8f74053545
---
M RELEASE-NOTES-1.22
M includes/Hooks.php
2 files changed, 6 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/28/70328/1

diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22
index 2aee6e4..6da9cb6 100644
--- a/RELEASE-NOTES-1.22
+++ b/RELEASE-NOTES-1.22
@@ -256,6 +256,9 @@
   will no longer be output and OutputPage::addKeyword no longer exists.
 * Methods Title::userCanEditCssSubpage and Title::userCanEditJsSubpage,
   deprecated since 1.19, have been removed.
+* (bug 50134) Hook functions are no longer required to return a value. When a
+  hook function does not return a value (or return an explicit null),
+  processing continues.
 
 == Compatibility ==
 
diff --git a/includes/Hooks.php b/includes/Hooks.php
index ed8b3ed..04b36d0 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -126,6 +126,8 @@
         * @param array $args  Array of parameters passed to hook functions
         * @return bool True if no handler aborted the hook
         *
+        * @since 1.22 A hook function is not required to return a value for
+        *   processing to continue.
         * @throws MWException
         * @throws FatalError
         */
@@ -210,14 +212,7 @@
                                        'Detected bug in an extension! ' .
                                        "Hook $func has invalid call signature; 
" . $badhookmsg
                                );
-                       } elseif ( $retval === null ) {
-                               // Null was returned. Error.
-                               throw new MWException(
-                                       'Detected bug in an extension! ' .
-                                       "Hook $func failed to return a value; " 
.
-                                       'should return true to continue hook 
processing or false to abort.'
-                               );
-                       } elseif ( !$retval ) {
+                       } elseif ( $retval === false ) {
                                wfProfileOut( 'hook: ' . $event );
                                // False was returned. Stop processing, but no 
error.
                                return false;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I11deb2117ff9233c77868470f50e0d8f74053545
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to