Amire80 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/108342


Change subject: Add basic EventLogging support
......................................................................

Add basic EventLogging support

Change-Id: I3e2bab216edca9d6f56fde18c1f1d7044c2fae58
---
A ContentTranslation.hooks.php
M ContentTranslation.php
M Resources.php
A modules/eventlogging/ext.cx.eventlogging.js
M modules/translation/ext.cx.publish.js
5 files changed, 161 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/42/108342/1

diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php
new file mode 100644
index 0000000..63682ef
--- /dev/null
+++ b/ContentTranslation.hooks.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Hooks for ContentTranslation extension.
+ *
+ * @file
+ * @ingroup Extensions
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+
+class ContentTranslationHooks {
+       /**
+        * @param OutputPage $out
+        * @param Skin $skin
+        * @return bool
+        * Hook: BeforePageDisplay
+        */
+       public static function addModules( $out, $skin ) {
+               global $wgContentTranslationEventLogging;
+
+               // If EventLogging integration is enabled, load the schema 
module
+               // and the event logging functions module
+               if ( $wgContentTranslationEventLogging ) {
+                       $out->addModules( array(
+                               'schema.ContentTranslation',
+                               'ext.cx.eventlogging',
+                       ) );
+               }
+
+               return true;
+       }
+}
diff --git a/ContentTranslation.php b/ContentTranslation.php
index 0099f12..47ba0db 100644
--- a/ContentTranslation.php
+++ b/ContentTranslation.php
@@ -52,3 +52,40 @@
 
 // API modules
 $GLOBALS['wgAPIModules']['cxpublish'] = 'ApiContentTranslationPublish';
+
+// Hooks
+$GLOBALS['wgHooks']['BeforePageDisplay'][] = 
'ContentTranslationHooks::addModules';
+
+$GLOBALS['wgExtensionFunctions'][] = function () {
+       global $wgResourceModules, $wgContentTranslationEventLogging;
+
+       // If EventLogging integration is enabled, first ensure that the
+       // EventLogging extension is present, then declare the schema module.
+       // If it is not present, emit a warning and disable logging.
+       if ( $wgContentTranslationEventLogging ) {
+               if ( class_exists( 'ResourceLoaderSchemaModule' ) ) {
+                       /// @see 
https://meta.wikimedia.org/wiki/Schema:ContentTranslation
+                       $wgResourceModules[ 'schema.ContentTranslation' ] = 
array(
+                               'class'  => 'ResourceLoaderSchemaModule',
+                               'schema' => 'ContentTranslation',
+                               'revision' => 7146627,
+                       );
+               } else {
+                       wfWarn(
+                               'ContentTranslation is configured to use 
EventLogging, ' .
+                               'but the extension is is not available. ' .
+                               'Disabling $wgContentTranslationEventLogging.'
+                       );
+                       $wgContentTranslationEventLogging = false;
+               }
+       }
+
+       return true;
+};
+
+// Globals for this extension
+/**
+ * Whether to use EventLogging.
+ * The EventLogging extension must be installed if this option is enabled.
+ */
+$GLOBALS['wgContentTranslationEventLogging'] = false;
diff --git a/Resources.php b/Resources.php
index c10a664..ce99bd5 100644
--- a/Resources.php
+++ b/Resources.php
@@ -101,3 +101,8 @@
                'cx-publish-page-error'
        ),
 ) + $resourcePaths;
+
+$wgResourceModules['ext.cx.eventlogging'] = array(
+       'scripts' => 'eventlogging/ext.cx.eventlogging.js',
+       'dependencies' => 'schema.ContentTranslation',
+) + $resourcePaths;
diff --git a/modules/eventlogging/ext.cx.eventlogging.js 
b/modules/eventlogging/ext.cx.eventlogging.js
new file mode 100644
index 0000000..b56a072
--- /dev/null
+++ b/modules/eventlogging/ext.cx.eventlogging.js
@@ -0,0 +1,83 @@
+/**
+ * ContentTranslation event logging.
+ * Uses the EventLogging extension, if it's available, to log events.
+ *
+ * @file
+ * @ingroup Extensions
+ * @copyright See AUTHORS.txt
+ * @license GPL-2.0+
+ */
+
+( function ( $, mw ) {
+       'use strict';
+
+       /**
+        * ContentTranslation event logger
+        */
+       function ContentTranslationEventLogging() {
+               this.logEventQueue = $.Callbacks( 'memory once' );
+               this.init();
+               this.listen();
+       }
+
+       ContentTranslationEventLogging.prototype = {
+               init: function () {
+                       var eventLogging = this;
+
+                       // Set event defaults and make the
+                       mw.eventLog.setDefaults( 'ContentTranslation', {
+                               version: 1,
+                               token: mw.user.id()
+                       } );
+
+                       eventLogging.logEventQueue.fire();
+               },
+
+               /**
+                * Local wrapper for 'mw.eventLog.logEvent'
+                *
+                * @param {Object} event Event action and optional fields
+                * @return {jQuery.Promise} jQuery Promise object for the 
logging call
+                */
+               log: function ( event ) {
+                       // We need to create our own deferred for two reasons:
+                       //  - logEvent might not be executed immediately
+                       //  - we cannot reject a promise returned by it
+                       // So we proxy the original promises status updates.
+                       var deferred = $.Deferred();
+
+                       this.logEventQueue.add( function () {
+                               mw.eventLog.logEvent( 'ContentTranslation', 
event )
+                                       .done( deferred.resolve )
+                                       .fail( deferred.reject );
+                       } );
+
+                       return deferred.promise();
+               },
+
+               /**
+                * Listen for event logging
+                */
+               listen: function () {
+                       // Register handlers for event logging triggers
+                       mw.hook( 'mw.cx.translatedPageCreated' ).add(
+                               $.proxy( this.translatedPageCreated, this )
+                       );
+               },
+
+               /**
+                * Log creation of translated page
+                * @param {string} targetLanguage Target language code
+                */
+               translatedPageCreated: function ( targetLanguage ) {
+                       mw.log( 'eventlogging! translatedPageCreated!' ); // XXX
+                       this.log( {
+                               action: 'create-translated-page',
+                               targetLanguage: targetLanguage
+                       } );
+               }
+       };
+
+       mw.cx = mw.cx || {};
+       mw.cx.eventlogging = new ContentTranslationEventLogging();
+}( jQuery, mediaWiki ) );
diff --git a/modules/translation/ext.cx.publish.js 
b/modules/translation/ext.cx.publish.js
index 8b352a3..bbd6cd1 100644
--- a/modules/translation/ext.cx.publish.js
+++ b/modules/translation/ext.cx.publish.js
@@ -25,8 +25,12 @@
                translatedTitle = 'User:' + mw.user.getName() + '/' + 
translatedTitle;
                publishTranslation( translatedTitle, translatedContent, 
sourceTitle )
                        .done( function () {
+
                                mw.notify( $( '<p>' ).html( mw.message( 
'cx-publish-page',
                                        mw.util.getUrl( translatedTitle ), 
translatedTitle ).parse() ) );
+                               mw.hook( 'mw.cx.translatedPageCreated' ).fire(
+                                       $( '.cx-column--translation' ).prop( 
'lang' )
+                               );
                        } ).fail( function () {
                                mw.notify( mw.msg( 'cx-publish-page-error' ) );
                        } );

-- 
To view, visit https://gerrit.wikimedia.org/r/108342
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e2bab216edca9d6f56fde18c1f1d7044c2fae58
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Amire80 <amir.ahar...@mail.huji.ac.il>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to