Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Enable Resource Loader Module to work with Mobile Frontend Extension

This tutorial is a solution of a basic problem which you may face when you want to go with MobileFrontend Extension for the first time. Mobile Frontend Extension is a good option to give your MediaWiki users a deal of data saving by providing lightweight interface on Mobile and tablets. This tutorial tells you how you can extend your extensions to work with the Mobile Frontend.


This tutorial is more or less like a solution of a problem, which you may face when the Mobile Frontend Extension is active. The MobileFrontend presents its whole new skin for mobile devices. So the Resource Loader module in its original form doesn’t work on the mobile skin. To overcome this problem Mobile frontend provides an addition to the original resource loader module. To know about Resource Loader please take a look at this tutorial.

The original way to create a resource loader module is shown in the following code snippet and is taken from the tutorial series on How to Develop Extension for Mediawiki

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$wgResourceModules['ext.DemoExtension'] = array(
"scripts"=>"resources/js/demo.js",
"styles"=>"resources/css/demo.css",
"dependencies"=>array("jquery"),
'localBasePath'=> __DIR__,
'remoteExtpath'=>'DemoExtension'
);
$wgResourceModules['ext.DemoExtension'] = array( "scripts"=>"resources/js/demo.js", "styles"=>"resources/css/demo.css", "dependencies"=>array("jquery"), 'localBasePath'=> __DIR__, 'remoteExtpath'=>'DemoExtension' );
$wgResourceModules['ext.DemoExtension'] = array(
	"scripts"=>"resources/js/demo.js",
	"styles"=>"resources/css/demo.css",
	"dependencies"=>array("jquery"),
	'localBasePath'=> __DIR__,
   'remoteExtpath'=>'DemoExtension'
);

Now we need to enable this Module to work with the Mobile Frontend extension, so we need to clone this for mobile, that doesn’t take much of doing,you only need to tell MediaWiki that this module is targeted for Mobile as in following code snippet.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$wgResourceModules['ext.DemoExtension.mobile'] = $wgResourceModules['ext.DemoExtension'] + array(
'targets' => 'mobile',
);
$wgResourceModules['ext.DemoExtension.mobile'] = $wgResourceModules['ext.DemoExtension'] + array( 'targets' => 'mobile', );
$wgResourceModules['ext.DemoExtension.mobile'] = $wgResourceModules['ext.DemoExtension'] + array(
	'targets' => 'mobile',
);

Now we have definition of module ready for mobile frontend so we need to set up a hook that will output this module on mobile frontend skin, for this there is a hook defined in MobileFrontend known as EnableMobileModules. we create a function which outputs the module and hook it using the mentioned hook.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function efEnableMobileModules( $out, $mode ) {
$name = 'ext.DemoExtension.mobile';
$out->addModules( $name );
return true;
}
function efEnableMobileModules( $out, $mode ) { $name = 'ext.DemoExtension.mobile'; $out->addModules( $name ); return true; }
function efEnableMobileModules( $out, $mode ) {
	$name = 'ext.DemoExtension.mobile';
	$out->addModules( $name );
	return true;
}

This function is to be defined in the body of your MediaWiki extension. and finally you hook this function to the EnableMobileModules.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$wgHooks['EnableMobileModules'][] = 'efEnableMobileModules';
$wgHooks['EnableMobileModules'][] = 'efEnableMobileModules';
$wgHooks['EnableMobileModules'][] = 'efEnableMobileModules';

Okay the Hook is set and you are good to go, now your extensions resource module is ready to work with the MobileFrontEnd extension. Hope you find this article helpful for any queries you can comment below or contact us using our contact page.

Buy Me A Coffee
If you find my content helpful, please consider supporting me!