Last modified: 2007-02-05 19:10:54 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T10822, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 8822 - wfRunHooks does not handle "null" return code correctly.
wfRunHooks does not handle "null" return code correctly.
Status: RESOLVED INVALID
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.9.x
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-01-29 16:21 UTC by Jean-Lou Dupont
Modified: 2007-02-05 19:10 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Jean-Lou Dupont 2007-01-29 16:21:06 UTC
I've been having problems with "UserCan" extensions. Digging in the SVN (and my
install v1.8.2), I have found that the "null" return code from an extension
(i.e. continue processing) is not handled correctly. The code below is from the
phase 3 SVN and shows the line "if (!$retval)" whereas both "false" and "null"
return codes are handled the same way.

From http://www.mediawiki.org/wiki/Manual:MediaWiki_hooks/userCan:
"if null is returned then the other things in the hook chain are checked, the
result is still undetermined
   if true is returned then can the user do want he want to do, the result is true
   if false is returned then the evaluation is aborted and the result is false
"

Code snippet from Hooks.php
---------------------------

        /* Call the hook. */
        wfProfileIn( $func );
        $retval = call_user_func_array( $callback, $hook_args );
        wfProfileOut( $func );

        /* String return is an error; false return means stop processing. */

        if (is_string($retval)) {
            global $wgOut;
            $wgOut->showFatalError($retval);
            return false;
        } else if (!$retval) {
            return false;
        }
    }

    return true;
Comment 1 Brion Vibber 2007-02-02 18:53:58 UTC
Only true and false are valid return values for hooks, not null.
Comment 2 Jean-Lou Dupont 2007-02-05 11:16:34 UTC
Then how do you chain extensions that hook themselves on the same trigger point
as so they do not step on each others toes too much?

A "null" return value would at least enable another state "undetermined" and
this would be helpful.
Comment 3 Brion Vibber 2007-02-05 18:57:27 UTC
True means "keep running down the chain",
false means "cancel further processing".

A hook isn't really appropriate for returning a yes/no _answer_, but modifying a
passed-by-reference parameter is used for such things.
Comment 4 Jean-Lou Dupont 2007-02-05 19:10:54 UTC
I see what you mean: the 'userCan' hook chain call in Title.php captures your
point. 
I'll update the documentation on Mediawiki.org.

Thanks for your time.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links