From: Brad Jorsch Date: Wed, 27 Feb 2019 20:51:38 +0000 (-0500) Subject: API: Use log context for api-feature-usage log X-Git-Tag: 1.34.0-rc.0~2704^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=commitdiff_plain;h=6a28fb3ace9add5b49dce4e45bba164c029e4e02;p=lhc%2Fweb%2Fwiklou.git API: Use log context for api-feature-usage log The text message is deprecated. Bug: T217162 Change-Id: Ie891257140ea19369e10b2e91463a1fb4aa5d233 --- diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33 index 4a923c52b4..515407771f 100644 --- a/RELEASE-NOTES-1.33 +++ b/RELEASE-NOTES-1.33 @@ -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 diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 4898385cfc..53c0a0b0bd 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -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 ); } /**@}*/