Legoktm has uploaded a new change for review.

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

Change subject: Move BeforePageDisplay hook to separate class
......................................................................

Move BeforePageDisplay hook to separate class

Change-Id: Iddbf2f330b753ca721f9964ccd15e550d2b4a501
---
A XAnalytics.class.php
M XAnalytics.php
2 files changed, 34 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/XAnalytics 
refs/changes/99/202799/1

diff --git a/XAnalytics.class.php b/XAnalytics.class.php
new file mode 100644
index 0000000..46df7cb
--- /dev/null
+++ b/XAnalytics.class.php
@@ -0,0 +1,29 @@
+<?php
+
+class XAnalytics {
+       /**
+        * Set X-Analytics header before the output buffer is flushed.
+        *
+        * The PHP output buffer is flushed from multiple places in the 
MediaWiki
+        * codebase (and the codebase of MediaWiki extensions), making it 
difficult to
+        * ensure that the header is reliably injected into every response 
generated by
+        * MediaWiki. This should be fixed. The output buffer of normal page 
view
+        * responses is done in one place, however, so for that use-case, the 
code is
+        * reliable.
+        *
+        * X-Analytics items can be declared by hooking into 
'XAnalyticsSetHeader'.
+        *
+        * @see https://wikitech.wikimedia.org/wiki/X-Analytics
+        */
+       public static function onBeforePageDisplay( OutputPage &$out, Skin 
&$skin ) {
+               $response = $out->getRequest()->response();
+               $currentHeader = $response->getHeader( 'X-Analytics' );
+               parse_str( preg_replace( '/; */', '&', $currentHeader ), 
$headerItems );
+               Hooks::run( 'XAnalyticsSetHeader', array( $out, &$headerItems ) 
);
+
+               if ( count( $headerItems ) ) {
+                       $headerValue = http_build_query( $headerItems, null, 
';' );
+                       $response->header( 'X-Analytics: ' . $headerValue, true 
);
+               }
+       }
+}
diff --git a/XAnalytics.php b/XAnalytics.php
index 1856335..73c769d 100644
--- a/XAnalytics.php
+++ b/XAnalytics.php
@@ -21,31 +21,10 @@
 
 $wgMessagesDirs['XAnalytics'] = __DIR__ . '/i18n';
 
+// Autoload
+
+$wgAutoloadClasses['XAnalytics'] = __DIR__ . '/XAnalytics.class.php';
+
 // Hooks
 
-/**
- * Set X-Analytics header before the output buffer is flushed.
- *
- * The PHP output buffer is flushed from multiple places in the MediaWiki
- * codebase (and the codebase of MediaWiki extensions), making it difficult to
- * ensure that the header is reliably injected into every response generated by
- * MediaWiki. This should be fixed. The output buffer of normal page view
- * responses is done in one place, however, so for that use-case, the code is
- * reliable.
- *
- * X-Analytics items can be declared by adding items to the configuration
- * variable $wgXAnalyticsHeaderItems.
- *
- * @see https://wikitech.wikimedia.org/wiki/X-Analytics
- */
-$wgHooks['BeforePageDisplay'][] = function ( OutputPage &$out, Skin &$skin ) {
-       $response = $out->getRequest()->response();
-       $currentHeader = $response->getHeader( 'X-Analytics' );
-       parse_str( preg_replace( '/; */', '&', $currentHeader ), $headerItems );
-       wfRunHooks( 'XAnalyticsSetHeader', array( $out, &$headerItems ) );
-
-       if ( count( $headerItems ) ) {
-               $headerValue = http_build_query( $headerItems, null, ';' );
-               $response->header( 'X-Analytics: ' . $headerValue, true );
-       }
-};
+$wgHooks['BeforePageDisplay'][] = 'XAnalytics::onBeforePageDisplay';

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iddbf2f330b753ca721f9964ccd15e550d2b4a501
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/XAnalytics
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

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

Reply via email to