From 7386f10df3c8ae1215f381d4ff110126eae86c44 Mon Sep 17 00:00:00 2001 From: Prateek Saxena Date: Thu, 27 Feb 2014 13:39:34 +0530 Subject: [PATCH] Make EventLogging a soft dependency Based on https://gist.github.com/atdt/4652474 Bug: 61880 Change-Id: Ief5ce7eef43ffe4612541627dff2b0fc75b696ab --- Popups.php | 56 +++++++++++++++++++++--------------- resources/ext.popups.core.js | 1 + 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Popups.php b/Popups.php index b23f162f5..5650fa426 100644 --- a/Popups.php +++ b/Popups.php @@ -33,8 +33,33 @@ $wgExtensionCredits['betafeatures'][] = array( $localBasePath = dirname( __DIR__ ) . '/Popups'; $remoteExtPath = 'Popups'; -$wgResourceModules = array_merge( $wgResourceModules, array( - 'ext.popups' => array( +$wgAutoloadClasses['PopupsHooks'] = __DIR__ . '/Popups.hooks.php'; +$wgExtensionMessagesFiles['Popups'] = __DIR__ . '/Popups.i18n.php'; + +$wgHooks['GetBetaFeaturePreferences'][] = 'PopupsHooks::getPreferences'; +$wgHooks['BeforePageDisplay'][] = 'PopupsHooks::onBeforePageDisplay'; + +$wgHooks[ 'ResourceLoaderRegisterModules' ][] = function ( ResourceLoader &$resourceLoader ) { + + $moduleDependencies = array( + 'mediawiki.api', + 'mediawiki.jqueryMsg', + 'moment', + ); + + // If EventLogging is present, declare the schema module + // and add it to the array of dependencies. + if ( class_exists( 'ResourceLoaderSchemaModule' ) ) { + $resourceLoader->register( "schema.Popups", array( + 'class' => 'ResourceLoaderSchemaModule', + 'schema' => 'Popups', + 'revision' => 7536956, + ) ); + + $moduleDependencies[] = "schema.Popups"; + } + + $resourceLoader->register( "ext.popups", array( 'scripts' => array( 'resources/ext.popups.core.js', ), @@ -42,28 +67,13 @@ $wgResourceModules = array_merge( $wgResourceModules, array( 'resources/ext.popups.core.less', 'resources/ext.popups.animation.less', ), - 'dependencies' => array( - 'mediawiki.api', - 'mediawiki.jqueryMsg', - 'moment', - ), + 'dependencies' => $moduleDependencies, 'messages' => array( 'popups-last-edited', 'popups-redirects', ), - 'remoteExtPath' => $remoteExtPath, - 'localBasePath' => $localBasePath, - ), - - 'schema.Popups' => array( - 'class' => 'ResourceLoaderSchemaModule', - 'schema' => 'Popups', - 'revision' => 7536956, - ), -) ); - -$wgAutoloadClasses['PopupsHooks'] = __DIR__ . '/Popups.hooks.php'; -$wgExtensionMessagesFiles['Popups'] = __DIR__ . '/Popups.i18n.php'; - -$wgHooks['GetBetaFeaturePreferences'][] = 'PopupsHooks::getPreferences'; -$wgHooks['BeforePageDisplay'][] = 'PopupsHooks::onBeforePageDisplay'; + 'remoteExtPath' => 'Popups', + 'localBasePath' => dirname( __DIR__ ) . '/Popups', + ) ); + return true; +}; diff --git a/resources/ext.popups.core.js b/resources/ext.popups.core.js index 250051866..c35ae1182 100644 --- a/resources/ext.popups.core.js +++ b/resources/ext.popups.core.js @@ -355,6 +355,7 @@ setTimeout( dfd.reject, 1000 ); elTime = elDuration = elAction = undefined; } + var logEvent = mw.eventLog ? mw.eventLog.logEvent : function () {}; /** * @method getSessionId