jenkins-bot has submitted this change and it was merged.

Change subject: Real-time active editor metrics
......................................................................


Real-time active editor metrics

Whenever a non-bot user edits a mainspace page, enqueue a deferred update which
checks if the edit is the fifth such edit by this user this month. If it is,
then the user now counts as an "active editor", per the metric defined at
https://www.mediawiki.org/wiki/Analytics/Metric_definitions#Active_editor.
Log an event and increment a stat.

Depends on change I8c0a93713c1 in mediawiki/core.

Change-Id: I370589c77059a4ae5b8e607285cd95587e43d6b7
---
M WikimediaEvents.php
M WikimediaEventsHooks.php
2 files changed, 57 insertions(+), 0 deletions(-)

Approvals:
  Nuria: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/WikimediaEvents.php b/WikimediaEvents.php
index a68113c..0599de5 100644
--- a/WikimediaEvents.php
+++ b/WikimediaEvents.php
@@ -173,3 +173,4 @@
 $wgHooks['XAnalyticsSetHeader'][] = 'WikimediaEventsHooks::onXAnalyticsHeader';
 $wgHooks['SpecialSearchResults'][] = 
'WikimediaEventsHooks::onSpecialSearchResults';
 $wgHooks['UploadComplete'][] = 'WikimediaEventsHooks::onUploadComplete';
+$wgHooks['RevisionInsertComplete'][] = 
'WikimediaEventsHooks::onRevisionInsertComplete';
diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php
index bd71292..3e7e07d 100644
--- a/WikimediaEventsHooks.php
+++ b/WikimediaEventsHooks.php
@@ -112,6 +112,62 @@
        }
 
        /**
+        * Log and update statistics whenever an editor reaches the active 
editor
+        * threshold for this month.
+        *
+        * @see https://meta.wikimedia.org/wiki/Schema:EditorActivation
+        * @see 
https://www.mediawiki.org/wiki/Analytics/Metric_definitions#Active_editor
+        *
+        * @param Revision &$revision
+        * @param string $data
+        * @param array $flags
+        */
+       public static function onRevisionInsertComplete( &$revision, $data, 
$flags ) {
+               $context = RequestContext::getMain();
+               $user = $context->getUser();
+
+               // Anonymous users and bots don't count (sorry!)
+               if ( $user->isAnon() || $user->isAllowed( 'bot' ) ) {
+                       return;
+               }
+
+               // Only mainspace edits qualify
+               if ( !$revision->getTitle()->inNamespace( NS_MAIN ) ) {
+                       return;
+               }
+
+               // Check if this is the user's fifth mainspace edit this month.
+               // If it is, then this editor has just made the cut as an active
+               // editor for this wiki for this month.
+               DeferredUpdates::addCallableUpdate( function () use ( $context, 
$user ) {
+                       $db = wfGetDB( DB_MASTER );
+
+                       $since = date( 'Ym' ) . '00000000';
+                       $numMainspaceEditsThisMonth = $db->selectRowCount(
+                               array( 'revision', 'page' ),
+                               '1',
+                               array(
+                                       'rev_user'         => $user->getId(),
+                                       'rev_timestamp >= ' . $db->addQuotes( 
$db->timestamp( $since ) ),
+                                       'page_namespace'   => NS_MAIN,
+                               ),
+                               __FILE__ . ':' . __LINE__,
+                               array( 'LIMIT' => 6 ),
+                               array( 'page' => array( 'INNER JOIN', 'rev_page 
= page_id' ) )
+                       );
+
+                       if ( $numMainspaceEditsThisMonth === 5 ) {
+                               $month = date( 'm-Y' );
+                               $context->getStats()->increment( 
'editor.activation.' . $month );
+                               EventLogging::logEvent( 'EditorActivation', 
14208837, array(
+                                       'userId' => $user->getId(),
+                                       'month'  => $month,
+                               ) );
+                       }
+               } );
+       }
+
+       /**
         * Handler for UserSaveOptions hook.
         * @see http://www.mediawiki.org/wiki/Manual:Hooks/UserSaveOptions
         * @param User $user user whose options are being saved

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I370589c77059a4ae5b8e607285cd95587e43d6b7
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/WikimediaEvents
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Milimetric <[email protected]>
Gerrit-Reviewer: Nuria <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to