[MW]$wgExtensionFunctions : Run a function when an extension is evoked

Working further with making the BounceHandler extension more production friendly – we came up with a scenario in which I wanted some of the extension global variables to take values from a MediaWiki global variable. It would’ve looked like $myExtensionGlobal = $mwGlobal – which looks weird.
Thanks to Hoo( WMDE ), I got introduced to $wgExtensionFunctions[] [1]

You need to run a function once your extension gets loaded. In my case, I want to check if $wgFoo ( which defaults to null ) was set in the original myExtension.php and if not – set it to the MW global – $wgBar
in your myExtension.php

$wgFoo = null;
$wgExtensionFunctions[] = function() {
	global $wgBar;
	$wgFoo = $wgFoo ? : $wgBar;

This would introduce a nameless function which would do our required manipulations.
You can even make it a named function as in :

$wgExtensionFunctions[] = "myFunction";
function myFunction() {
         // Code your task

Hope it help someone ! Happy Hacking 🙂
[1] https://www.mediawiki.org/wiki/Manual:$wgExtensionFunctions

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s