Skip to content

Instantly share code, notes, and snippets.

@atdt
Last active March 12, 2021 13:24
Show Gist options
  • Save atdt/4652474 to your computer and use it in GitHub Desktop.
Save atdt/4652474 to your computer and use it in GitHub Desktop.
Loading EventLogging modules conditionally.
<?php
// MyExtension.php
$wgHooks[ 'ResourceLoaderRegisterModules' ][] = function ( ResourceLoader &$resourceLoader ) {
/** @var array: list of modules that ext.myExtension.core depends on. **/
$moduleDependencies = array( /* ... */ );
// If EventLogging is present, declare the schema module
// and add it to the array of dependencies.
if ( class_exists( 'ResourceLoaderSchemaModule' ) ) ) {
$resourceLoader->register( "schema.MyExtension", array(
'class' => 'ResourceLoaderSchemaModule',
'schema' => 'MyExtension',
'revision' => 4948295
);
$moduleDependencies[] = "schema.MyExtension";
}
$resourceLoader->register( "ext.myExtension.core", array(
'scripts' => 'modules/ext.myExtension.js',
'dependencies' => $moduleDependencies,
'localBasePath' => __DIR__,
'remoteExtPath' => 'MyExtension'
) );
return true;
};
var logEvent = mw.eventLog ? mw.eventLog.logEvent : function () {};
@Nikerabbit
Copy link

You are missing [] form line 4. On line 11 there is extra ), On line 26 missing ) and after that missing "return true".

@atdt
Copy link
Author

atdt commented Jul 9, 2013

Eep. Fixed.

@prtksxna
Copy link

I think there still is an extra ) on L11. There needs to be , at the end of L15/25 and another ) on L16.

@legoktm
Copy link

legoktm commented Jun 2, 2015

This should be updated to use the EventLoggingRegisterSchemas hook and maybe moved to a wiki somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment