Add block notice stats on EditPage.
authorDayllan Maza <dmaza@wikimedia.org>
Thu, 8 Nov 2018 04:03:53 +0000 (23:03 -0500)
committerDayllan Maza <dmaza@wikimedia.org>
Wed, 28 Nov 2018 05:51:37 +0000 (00:51 -0500)
Monitoring block notices is behind $wgEnableBlockNoticeStats config
flag which is set to false by default.

The reason behind this metric is to get an idea on how
frequently blocked users attempt to edit a page. Similar tracking
is being added to MobileFrontend and VisualEditor.

Bug: T201718
Change-Id: I6bd1c95548616677e1f72ba6bcfc6f2b551c1ca6

includes/DefaultSettings.php
includes/EditPage.php

index 2d1681c..d05867f 100644 (file)
@@ -9055,6 +9055,16 @@ $wgTagStatisticsNewTable = false;
  */
 $wgEnablePartialBlocks = false;
 
+/**
+ * Enable stats monitoring when Block Notices are displayed in different places around core
+ * and extensions.
+ *
+ * @since 1.34
+ * @deprecated 1.34
+ * @var bool
+ */
+$wgEnableBlockNoticeStats = false;
+
 /**
  * For really cool vim folding this needs to be at the end:
  * vim: foldmarker=@{,@} foldmethod=marker
index 0f7d9a7..6b4325e 100644 (file)
@@ -619,14 +619,23 @@ class EditPage {
                if ( $permErrors ) {
                        wfDebug( __METHOD__ . ": User can't edit\n" );
 
-                       // track block with a cookie if it doesn't exists already
-                       $this->context->getUser()->trackBlockWithCookie();
+                       if ( $this->context->getUser()->getBlock() ) {
+                               // track block with a cookie if it doesn't exists already
+                               $this->context->getUser()->trackBlockWithCookie();
+
+                               // Auto-block user's IP if the account was "hard" blocked
+                               if ( !wfReadOnly() ) {
+                                       DeferredUpdates::addCallableUpdate( function () {
+                                               $this->context->getUser()->spreadAnyEditBlock();
+                                       } );
+                               }
 
-                       // Auto-block user's IP if the account was "hard" blocked
-                       if ( !wfReadOnly() ) {
-                               DeferredUpdates::addCallableUpdate( function () {
-                                       $this->context->getUser()->spreadAnyEditBlock();
-                               } );
+                               $config = $this->context->getConfig();
+                               if ( $config->get( 'EnableBlockNoticeStats' ) ) {
+                                       $wiki = $config->get( 'DBname' );
+                                       $statsd = MediaWikiServices::getInstance()->getStatsdDataFactory();
+                                       $statsd->increment( 'BlockNotices.' . $wiki . '.WikitextEditor.shown' );
+                               }
                        }
                        $this->displayPermissionsError( $permErrors );