I have a few KB worth JS which I add in the skin when the user is logged in.
I'd like to add that code to MediaWiki:Common.js. Can I use ResourceLoader so it is only applied to logged in users?
I have a few KB worth JS which I add in the skin when the user is logged in.
I'd like to add that code to MediaWiki:Common.js. Can I use ResourceLoader so it is only applied to logged in users?
Hello,
sure. Just create a new ResourceLoader module and add a function to the hook BeforePageDisplay and add the module only, if the user is logged in, example:
$wgResourceModules['zzz.custom.js'] = array(
'scripts' => array(
// path to the script
),
'dependencies' => array(
// if you have any
),
'localBasePath' => __DIR__,
'remoteExtPath' => '/'
);
$wgHooks['BeforePageDisplay'][] = 'onBeforePageDisplay';
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
$user = $out->getUser();
if ( $user->isLoggedIn() ) {
$out->addModules( 'zzz.custom.js' );
}
}
You can use MediaWiki:Group-user.js, which will apply to logged in users only.
Will be this loaded for every logged in user, or just for those, who are in the group users?
Didn't know Manual:User group CSS and Javascript. Thanks!
Florianschmidtwelzow, I'll keep that noted. I'm new to RL and this is some basic example how to use it.