Manual talk:Hooks/MediaWikiPerformAction

From MediaWiki.org
Jump to navigation Jump to search

Moved from manual page: the MediaWiki class is not passed by this hook; however to replace the MediaWiki::performActions() method, you need to be able to access it. This can be done by inserting: global $mediaWiki; as the first line in the hook and returning a value of "false" after execution of the hook is complete. $mediaWiki is a currently undocumented global class variable.

You don't need to specifically override the function in the MediaWiki class. If you look at MediaWiki::performAction, you'll see that if you do something in your hook and return false, none of the actual guts of performAction happens. That's how you override the function. You get all of the arguments that are passed to performAction in your hook so its basically like your hook is getting called instead of the normal performAction function. --Cneubauer 12:27, 22 May 2008 (UTC)
What about any values stored in $mediaWiki->params, like those passed through the URL via &action=? Don't you have to access those values via $mediaWiki->getVal('action')? Am I missing something here? If your hook is replacing the actual guts of performAction, how else to you access the 'action' parameter from the URL without access to the $mediaWiki object?--Hoggwild5 18:50, 30 June 2008 (UTC)
If you want to access $mediaWiki->params then accessing the global $mediaWiki object is fine, but you don't need to access that object to replace performAction. You can just register with the hook, do whatever you want, then return false. If you specifically want to get the action you can also access the $wgRequest global variable. Take a look at index.php line ~56 for an example. It would be nice for that hook to include the $mediaWiki object though so you could access the rest of the params. You could open a BugZilla request if you feel strongly about it. --Cneubauer 19:06, 30 June 2008 (UTC)
Sorry, you can access the request directly from the $request object passed to the hook instead of using the global $wgRequest. So you can do $request->getVal('action'); --Cneubauer 19:08, 30 June 2008 (UTC)
Cool! I did not know that. Thanks! I do think I'll follow your suggestion and open a Bugzilla request though...especially since the &action parameters have already been stored in $mediaWiki->params, along with some other globals, it seem counterintuitive to me to have to go get it again. :)--Hoggwild5 19:13, 30 June 2008 (UTC)

Note: Change for version 1.13alpha (r36831)[edit]

The MediaWikiPerformAction hook has a new parameter: $mwiki, which passes the $mediaWiki class. Thanks demon!--Hoggwild5 20:22, 1 July 2008 (UTC)