Jump to content

Manual talk:Hooks/ParserGetVariableValueSwitch

Add topic
From mediawiki.org
Latest comment: 12 years ago by Danwe in topic Hook execution question

Hook execution question[edit]

I am using Mediawiki 1.11.1 and I have a problem with the following sentences in the text:

Otherwise it does nothing and returns false. Returning false tells MediaWiki to go onto the remaining hooks assigned to ParserGetVariableValueSwitch in hopes of finding a value for the magic word id.

From the tests that I have performed it seems instead that if there are several hooks the execution of the hooks is interrupted as soon as one of them returns false. It is when a hook returns true that the execution continues to the next hook. Is it an error in the text or have I misunderstood something? — Tommy Ekola 12:06, 26 February 2008 (UTC)Reply

When returning false wfRunHooks() will abort and won't call any other functions registered for the hook. BUT in Parser::getVariableValue() where the hook is being called you find the lines
$ret = null;
if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) ) {
    return $ret;
} else {
    return null;
so only if true was returned, any value is assigned to the variables value. I consider this a bug. if ( wfRunHooks ... should be if ( ! wfRunHooks. Then we could return false to signal that a value has been found (and improve performance!) by returning false. Though, all extensions doing so would break compatibility with MW versions before the bugfix (of course except this worked with any old MW versions, I discovered this in MW 1.17).
Conclusion: Always return true unless the bug is being fixed and you only want to develop for MW in the version of that bugfix and later. --Danwe 16:43, 8 November 2011 (UTC)Reply
Also see task T14837 --Danwe 17:01, 8 November 2011 (UTC)Reply

return Links[edit]

Hi, when I do something like $ret='<div style="border:1px solid black">txt</div>'; a box is rendered. When I return $ret='<a href="http://mysite/index.htm">Index</a>'; no link is rendered, but the HTML code is shown. Is it possible to generate a link with this technique? -- Bardnet 11:58, 28 May 2008 (UTC)Reply