[MediaWiki-commits] [Gerrit] mediawiki...PageViewInfo[master]: Add PageViewService to make the extension non-Wikimedia-spec...

2017-02-17 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/320324 )

Change subject: Add PageViewService to make the extension non-Wikimedia-specific
..


Add PageViewService to make the extension non-Wikimedia-specific

Change-Id: I0ef75e0b94994270992ef07a1698c99820ff7ff3
Depends-On: I3835b054ceac0fa0bcd58b41efa6bf78a0fafae7
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Hooks.php
A includes/PageViewService.php
A includes/ServiceWiring.php
A includes/WikimediaPageViewService.php
A tests/phpunit/ServiceWiringTest.php
A tests/phpunit/WikimediaPageViewServiceTest.php
A tests/smoke/WikimediaPageViewServiceSmokeTest.php
10 files changed, 1,083 insertions(+), 60 deletions(-)

Approvals:
  jenkins-bot: Verified
  Anomie: Looks good to me, approved



diff --git a/extension.json b/extension.json
index 2e8961a..8a24ff3 100644
--- a/extension.json
+++ b/extension.json
@@ -12,7 +12,9 @@
]
},
"AutoloadClasses": {
-   "MediaWiki\\Extensions\\PageViewInfo\\Hooks": 
"includes/Hooks.php"
+   "MediaWiki\\Extensions\\PageViewInfo\\Hooks": 
"includes/Hooks.php",
+   "MediaWiki\\Extensions\\PageViewInfo\\PageViewService": 
"includes/PageViewService.php",
+   
"MediaWiki\\Extensions\\PageViewInfo\\WikimediaPageViewService": 
"includes/WikimediaPageViewService.php"
},
"MessagesDirs": {
"PageViewInfo": [
@@ -38,9 +40,16 @@
"localBasePath": "resources",
"remoteExtPath": "PageViewInfo/resources"
},
+   "ConfigRegistry": {
+   "PageViewInfo": "GlobalVarConfig::newInstance"
+   },
+   "ServiceWiringFiles": [
+   "includes/ServiceWiring.php"
+   ],
"config": {
-   "PageViewInfoEndpoint": 
"https://wikimedia.org/api/rest_v1/metrics/pageviews;,
-   "PageViewInfoDomain": false
+   "PageViewInfoWikimediaEndpoint": 
"https://wikimedia.org/api/rest_v1;,
+   "PageViewInfoWikimediaDomain": false,
+   "PageViewInfoWikimediaRequestLimit": 5
},
"manifest_version": 1
 }
diff --git a/i18n/en.json b/i18n/en.json
index 7a2174f..339d0b0 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -7,5 +7,6 @@
"pvi-desc": "Adds page view information to the info action",
"pvi-month-count": "Page views in the past 30 days",
"pvi-close": "Close",
-   "pvi-range": "$1 - $2"
+   "pvi-range": "$1 - $2",
+   "pvi-invalidresponse": "Invalid response"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 85b449e..ba260de 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -8,5 +8,6 @@
"pvi-desc": 
"{{desc|name=PageViewInfo|url=https://www.mediawiki.org/wiki/Extension:PageViewInfo}};,
"pvi-month-count": "Label for table cell containing page views in past 
30 days",
"pvi-close": "Text on button to close a dialog\n{{Identical|Close}}",
-   "pvi-range": "Title of dialog, which is the date range the graph is 
for. $1 is the starting date, $2 is the ending date."
+   "pvi-range": "Title of dialog, which is the date range the graph is 
for. $1 is the starting date, $2 is the ending date.",
+   "pvi-invalidresponse": "Error message when the REST API response data 
does not have the expected structure."
 }
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 5302afd..e94ac8c 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -5,8 +5,8 @@
 use IContextSource;
 use FormatJson;
 use Html;
-use MWHttpRequest;
-use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
+use ObjectCache;
 use Title;
 
 class Hooks {
@@ -17,15 +17,18 @@
 */
public static function onInfoAction( IContextSource $ctx, array 
&$pageInfo ) {
$views = self::getMonthViews( $ctx->getTitle() );
-   if ( $views === false ) {
+   if ( !$views ) {
return;
}
-   $count = 0;
-   foreach ( $views['items'] as $item ) {
-   $count += $item['views'];
-   }
+
+   $total = array_sum( $views );
+   reset( $views );
+   $start = self::toYmdHis( key( $views ) );
+   end( $views );
+   $end = self::toYmdHis( key( $views ) );
+
$lang = $ctx->getLanguage();
-   $formatted = $lang->formatNum( $count );
+   $formatted = $lang->formatNum( $total );
$pageInfo['header-basic'][] = [
$ctx->msg( 'pvi-month-count' ),
Html::element( 'div', [ 'class' => 'mw-pvi-month' ], 
$formatted )
@@ -35,73 +38,64 @@
file_get_contents( __DIR__ . '/../graphs/month.json' ),
true
);
-   

[MediaWiki-commits] [Gerrit] mediawiki...PageViewInfo[master]: Add PageViewService to make the extension non-Wikimedia-spec...

2016-11-07 Thread Code Review
Gergő Tisza has uploaded a new change for review.

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

Change subject: Add PageViewService to make the extension non-Wikimedia-specific
..

Add PageViewService to make the extension non-Wikimedia-specific

Change-Id: I0ef75e0b94994270992ef07a1698c99820ff7ff3
Depends-On: I3835b054ceac0fa0bcd58b41efa6bf78a0fafae7
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Hooks.php
A includes/PageViewService.php
A includes/ServiceWiring.php
A includes/WikimediaPageViewService.php
A tests/phpunit/ServiceWiringTest.php
A tests/phpunit/WikimediaPageViewServiceTest.php
A tests/smoke/WikimediaPageViewServiceSmokeTest.php
10 files changed, 1,083 insertions(+), 60 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageViewInfo 
refs/changes/24/320324/1

diff --git a/extension.json b/extension.json
index 2e8961a..8a24ff3 100644
--- a/extension.json
+++ b/extension.json
@@ -12,7 +12,9 @@
]
},
"AutoloadClasses": {
-   "MediaWiki\\Extensions\\PageViewInfo\\Hooks": 
"includes/Hooks.php"
+   "MediaWiki\\Extensions\\PageViewInfo\\Hooks": 
"includes/Hooks.php",
+   "MediaWiki\\Extensions\\PageViewInfo\\PageViewService": 
"includes/PageViewService.php",
+   
"MediaWiki\\Extensions\\PageViewInfo\\WikimediaPageViewService": 
"includes/WikimediaPageViewService.php"
},
"MessagesDirs": {
"PageViewInfo": [
@@ -38,9 +40,16 @@
"localBasePath": "resources",
"remoteExtPath": "PageViewInfo/resources"
},
+   "ConfigRegistry": {
+   "PageViewInfo": "GlobalVarConfig::newInstance"
+   },
+   "ServiceWiringFiles": [
+   "includes/ServiceWiring.php"
+   ],
"config": {
-   "PageViewInfoEndpoint": 
"https://wikimedia.org/api/rest_v1/metrics/pageviews;,
-   "PageViewInfoDomain": false
+   "PageViewInfoWikimediaEndpoint": 
"https://wikimedia.org/api/rest_v1;,
+   "PageViewInfoWikimediaDomain": false,
+   "PageViewInfoWikimediaRequestLimit": 5
},
"manifest_version": 1
 }
diff --git a/i18n/en.json b/i18n/en.json
index 7a2174f..339d0b0 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -7,5 +7,6 @@
"pvi-desc": "Adds page view information to the info action",
"pvi-month-count": "Page views in the past 30 days",
"pvi-close": "Close",
-   "pvi-range": "$1 - $2"
+   "pvi-range": "$1 - $2",
+   "pvi-invalidresponse": "Invalid response"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 85b449e..ba260de 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -8,5 +8,6 @@
"pvi-desc": 
"{{desc|name=PageViewInfo|url=https://www.mediawiki.org/wiki/Extension:PageViewInfo}};,
"pvi-month-count": "Label for table cell containing page views in past 
30 days",
"pvi-close": "Text on button to close a dialog\n{{Identical|Close}}",
-   "pvi-range": "Title of dialog, which is the date range the graph is 
for. $1 is the starting date, $2 is the ending date."
+   "pvi-range": "Title of dialog, which is the date range the graph is 
for. $1 is the starting date, $2 is the ending date.",
+   "pvi-invalidresponse": "Error message when the REST API response data 
does not have the expected structure."
 }
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 5302afd..e94ac8c 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -5,8 +5,8 @@
 use IContextSource;
 use FormatJson;
 use Html;
-use MWHttpRequest;
-use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
+use ObjectCache;
 use Title;
 
 class Hooks {
@@ -17,15 +17,18 @@
 */
public static function onInfoAction( IContextSource $ctx, array 
&$pageInfo ) {
$views = self::getMonthViews( $ctx->getTitle() );
-   if ( $views === false ) {
+   if ( !$views ) {
return;
}
-   $count = 0;
-   foreach ( $views['items'] as $item ) {
-   $count += $item['views'];
-   }
+
+   $total = array_sum( $views );
+   reset( $views );
+   $start = self::toYmdHis( key( $views ) );
+   end( $views );
+   $end = self::toYmdHis( key( $views ) );
+
$lang = $ctx->getLanguage();
-   $formatted = $lang->formatNum( $count );
+   $formatted = $lang->formatNum( $total );
$pageInfo['header-basic'][] = [
$ctx->msg( 'pvi-month-count' ),
Html::element( 'div', [ 'class' => 'mw-pvi-month' ], 
$formatted )
@@ -35,73 +38,64 @@
file_get_contents( __DIR__ . '/../graphs/month.json' ),
true
);
-