API: Use log context for api-feature-usage log
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 27 Feb 2019 20:51:38 +0000 (15:51 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 27 Feb 2019 22:06:02 +0000 (17:06 -0500)
The text message is deprecated.

Bug: T217162
Change-Id: Ie891257140ea19369e10b2e91463a1fb4aa5d233

RELEASE-NOTES-1.33
includes/api/ApiBase.php

index 4a923c5..5154077 100644 (file)
@@ -122,6 +122,8 @@ production.
   passed a bad code.
 * ApiBase::checkTitleUserPermissions() now takes an options array as its third
   parameter. Passing a User object or null is deprecated.
+* The api-feature-usage log channel now has log context. The text message is
+  deprecated and will be removed in the future.
 
 === Languages updated in 1.33 ===
 MediaWiki supports over 350 languages. Many localisations are updated regularly.
@@ -321,6 +323,8 @@ because of Phabricator reports.
   Block::isCreateAccountBlocked and Block::isUsertalkEditAllowed to get and set
   block properties; use Block::appliesToRight and Block::appliesToUsertalk to
   check block behaviour.
+* The api-feature-usage log channel now has log context. The text message is
+  deprecated and will be removed in the future.
 
 === Other changes in 1.33 ===
 * (T201747) Html::openElement() warns if given an element name with a space
index 4898385..53c0a0b 100644 (file)
@@ -2223,12 +2223,23 @@ abstract class ApiBase extends ContextSource {
         */
        public function logFeatureUsage( $feature ) {
                $request = $this->getRequest();
-               $s = '"' . addslashes( $feature ) . '"' .
-                       ' "' . wfUrlencode( str_replace( ' ', '_', $this->getUser()->getName() ) ) . '"' .
-                       ' "' . $request->getIP() . '"' .
-                       ' "' . addslashes( $request->getHeader( 'Referer' ) ) . '"' .
-                       ' "' . addslashes( $this->getMain()->getUserAgent() ) . '"';
-               wfDebugLog( 'api-feature-usage', $s, 'private' );
+               $ctx = [
+                       'feature' => $feature,
+                       // Spaces to underscores in 'username' for historical reasons.
+                       'username' => str_replace( ' ', '_', $this->getUser()->getName() ),
+                       'ip' => $request->getIP(),
+                       'referer' => (string)$request->getHeader( 'Referer' ),
+                       'agent' => $this->getMain()->getUserAgent(),
+               ];
+
+               // Text string is deprecated. Remove (or replace with just $feature) in MW 1.34.
+               $s = '"' . addslashes( $ctx['feature'] ) . '"' .
+                       ' "' . wfUrlencode( $ctx['username'] ) . '"' .
+                       ' "' . $ctx['ip'] . '"' .
+                       ' "' . addslashes( $ctx['referer'] ) . '"' .
+                       ' "' . addslashes( $ctx['agent'] ) . '"';
+
+               wfDebugLog( 'api-feature-usage', $s, 'private', $ctx );
        }
 
        /**@}*/