EditPage: Factor stats collection into private methods
authoraddshore <addshorewiki@gmail.com>
Thu, 26 Jan 2017 18:42:21 +0000 (19:42 +0100)
committeraddshore <addshorewiki@gmail.com>
Thu, 26 Jan 2017 18:47:26 +0000 (19:47 +0100)
Change-Id: Iad54ee22584077c6a7be6f2b050c3c4686b408c4

includes/EditPage.php

index e070ca3..5193860 100644 (file)
@@ -3543,15 +3543,7 @@ HTML
                // Avoid PHP 7.1 warning of passing $this by reference
                $editPage = $this;
                if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$editPage, &$wgOut ] ) ) {
-                       $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
-                       $stats->increment( 'edit.failures.conflict' );
-                       // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics
-                       if (
-                               $this->mTitle->getNamespace() >= NS_MAIN &&
-                               $this->mTitle->getNamespace() <= NS_CATEGORY_TALK
-                       ) {
-                               $stats->increment( 'edit.failures.conflict.byNamespaceId.' . $this->mTitle->getNamespace() );
-                       }
+                       $this->incrementConflictStats();
 
                        $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
 
@@ -3571,6 +3563,18 @@ HTML
                }
        }
 
+       private function incrementConflictStats() {
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+               $stats->increment( 'edit.failures.conflict' );
+               // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics
+               if (
+                       $this->mTitle->getNamespace() >= NS_MAIN &&
+                       $this->mTitle->getNamespace() <= NS_CATEGORY_TALK
+               ) {
+                       $stats->increment( 'edit.failures.conflict.byNamespaceId.' . $this->mTitle->getNamespace() );
+               }
+       }
+
        /**
         * @return string
         */
@@ -3683,8 +3687,6 @@ HTML
                global $wgOut, $wgRawHtml, $wgLang;
                global $wgAllowUserCss, $wgAllowUserJs;
 
-               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
-
                if ( $wgRawHtml && !$this->mTokenOk ) {
                        // Could be an offsite preview attempt. This is very unsafe if
                        // HTML is enabled, as it could be an attack.
@@ -3697,7 +3699,7 @@ HTML
                                        $this->context->msg( 'session_fail_preview_html' )->text() . "</div>",
                                        true, /* interface */true );
                        }
-                       $stats->increment( 'edit.failures.session_loss' );
+                       $this->incrementEditFailureStats( 'session_loss' );
                        return $parsedNote;
                }
 
@@ -3721,15 +3723,15 @@ HTML
                        if ( $this->mTriedSave && !$this->mTokenOk ) {
                                if ( $this->mTokenOkExceptSuffix ) {
                                        $note = $this->context->msg( 'token_suffix_mismatch' )->plain();
-                                       $stats->increment( 'edit.failures.bad_token' );
+                                       $this->incrementEditFailureStats( 'bad_token' );
                                } else {
                                        $note = $this->context->msg( 'session_fail_preview' )->plain();
-                                       $stats->increment( 'edit.failures.session_loss' );
+                                       $this->incrementEditFailureStats( 'session_loss' );
                                }
                        } elseif ( $this->incompleteForm ) {
                                $note = $this->context->msg( 'edit_form_incomplete' )->plain();
                                if ( $this->mTriedSave ) {
-                                       $stats->increment( 'edit.failures.incomplete_form' );
+                                       $this->incrementEditFailureStats( 'incomplete_form' );
                                }
                        } else {
                                $note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing;
@@ -3817,6 +3819,11 @@ HTML
                return $previewhead . $previewHTML . $this->previewTextAfterContent;
        }
 
+       private function incrementEditFailureStats( $failureType ) {
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+               $stats->increment( 'edit.failures.' . $failureType );
+       }
+
        /**
         * Get parser options for a preview
         * @return ParserOptions