jenkins-bot has submitted this change and it was merged.

Change subject: Use ProcessDialog to add close button and title
......................................................................


Use ProcessDialog to add close button and title

Use OO.ui.ProcessDialog instead of a plain OO.ui.Dialog so we can have a
close button and a title.

The title is the date range of when the data is from, so adjust the
backend code to make it available for the frontend.

Bug: T127280
Change-Id: I3becf2d6da45106fc26c4321dc8b64e7e508b510
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/PageViewInfo.hooks.php
M resources/ext.wmpageviewinfo.js
5 files changed, 62 insertions(+), 28 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  Siebrand: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index 5c2401e..4f4e85a 100644
--- a/extension.json
+++ b/extension.json
@@ -22,6 +22,10 @@
                        "scripts": [
                                "ext.wmpageviewinfo.js"
                        ],
+                       "messages": [
+                               "wmpvi-close",
+                               "wmpvi-range"
+                       ],
                        "dependencies": [
                                "ext.graph.vega2",
                                "oojs-ui"
diff --git a/i18n/en.json b/i18n/en.json
index 9f38894..3ff6365 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -5,5 +5,7 @@
                ]
        },
        "wmpvi-desc": "Adds page view information to the info action",
-       "wmpvi-month-count": "Page views in the past 30 days"
+       "wmpvi-month-count": "Page views in the past 30 days",
+       "wmpvi-close": "Close",
+       "wmpvi-range": "$1 - $2"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index f80f22e..4634ad3 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -5,5 +5,7 @@
                ]
        },
        "wmpvi-desc": 
"{{desc|name=WikimediaPageViewInfo|url=https://www.mediawiki.org/wiki/Extension:WikimediaPageViewInfo}}";,
-       "wmpvi-month-count": "Label for table cell containing page views in 
past 30 days"
+       "wmpvi-month-count": "Label for table cell containing page views in 
past 30 days",
+       "wmpvi-close": "Text on button to close a dialog",
+       "wmpvi-range": "Title of dialog, which is the date range the graph is 
for. $1 is the starting date, $2 is the ending date."
 }
diff --git a/includes/PageViewInfo.hooks.php b/includes/PageViewInfo.hooks.php
index 6c8d9d3..5726e0e 100644
--- a/includes/PageViewInfo.hooks.php
+++ b/includes/PageViewInfo.hooks.php
@@ -23,7 +23,8 @@
                foreach ( $views['items'] as $item ) {
                        $count += $item['views'];
                }
-               $formatted = $ctx->getLanguage()->formatNum( $count );
+               $lang = $ctx->getLanguage();
+               $formatted = $lang->formatNum( $count );
                $pageInfo['header-basic'][] = array(
                        $ctx->msg( 'wmpvi-month-count' ),
                        Html::element( 'div', array( 'class' => 
'mw-wmpvi-month' ), $formatted )
@@ -36,16 +37,25 @@
                $info['data'][0]['values'] = $views['items'];
 
                $ctx->getOutput()->addModules( 'ext.wmpageviewinfo' );
+               // Ymd -> YmdHis
+               $plus = '000000';
+               $user = $ctx->getUser();
                $ctx->getOutput()->addJsConfigVars( array(
-                       'wgWMPageViewInfo' => $info,
+                       'wgWMPageViewInfo' => array(
+                               'graph' => $info,
+                               'start' => $lang->userDate( $views['start'] . 
$plus, $user ),
+                               'end' => $lang->userDate( $views['end'] . 
$plus, $user ),
+                       ),
                ) );
        }
 
        /**
         * @param Title $title
+        * @param string $startDate Ymd format
+        * @param string $endDate Ymd format
         * @return string
         */
-       protected static function buildApiUrl( Title $title ) {
+       protected static function buildApiUrl( Title $title, $startDate, 
$endDate ) {
                global $wgPageViewInfoEndpoint, $wgPageViewInfoDomain, 
$wgServerName;
                if ( $wgPageViewInfoDomain ) {
                        $serverName = $wgPageViewInfoDomain;
@@ -53,21 +63,22 @@
                        $serverName = $wgServerName;
                }
                $encodedTitle = wfUrlencode( $title->getPrefixedDBkey() );
-               $today = date( 'Ymd' );
-               $lastMonth = date( 'Ymd', time() - ( 60 * 60 * 24 * 30 ) );
                return "$wgPageViewInfoEndpoint/per-article/$serverName"
-                       . 
"/all-access/user/$encodedTitle/daily/$lastMonth/$today";
+                       . 
"/all-access/user/$encodedTitle/daily/$startDate/$endDate";
        }
 
        protected static function getMonthViews( Title $title ) {
                global $wgMemc;
-               $url = self::buildApiUrl( $title );
-               $key = wfMemcKey( 'pvi', 'month2', md5( 
$title->getPrefixedText() ) );
+
+               $key = wfMemcKey( 'pvi', 'month', md5( 
$title->getPrefixedText() ) );
                $data = $wgMemc->get( $key );
                if ( $data ) {
                        return $data;
                }
 
+               $today = date( 'Ymd' );
+               $lastMonth = date( 'Ymd', time() - ( 60 * 60 * 24 * 30 ) );
+               $url = self::buildApiUrl( $title, $lastMonth, $today );
                $req = Http::get(
                        $url,
                        array( 'timeout' => 10 ),
@@ -79,6 +90,10 @@
                }
 
                $data = FormatJson::decode( $req, true );
+               // Add our start/end periods
+               $data['start'] = $lastMonth;
+               $data['end'] = $today;
+
                // Cache for an hour
                $wgMemc->set( $key, $data, 60 * 60 );
 
diff --git a/resources/ext.wmpageviewinfo.js b/resources/ext.wmpageviewinfo.js
index a901271..7dcc955 100644
--- a/resources/ext.wmpageviewinfo.js
+++ b/resources/ext.wmpageviewinfo.js
@@ -1,36 +1,47 @@
 ( function ( $, mw ) {
        $( function () {
                var $count = $( '.mw-wmpvi-month' ),
-                       count = $count.text();
+                       count = $count.text(),
+                       info = mw.config.get( 'wgWMPageViewInfo' );
 
                // Turn it into an <a> tag so it's obvious you can click on it
                $count.html( mw.html.element( 'a', { href: '#' }, count ) );
 
                $count.click( function ( e ) {
-                       var myDialog, windowManager;
+                       var dialog, windowManager;
                        e.preventDefault();
-
-                       // A simple dialog window.
-                       function MyDialog( config ) {
-                               MyDialog.parent.call( this, config );
+                       function MyProcessDialog( config ) {
+                               MyProcessDialog.parent.call( this, config );
                        }
-                       OO.inheritClass( MyDialog, OO.ui.Dialog );
-                       MyDialog.prototype.initialize = function () {
-                               var def = mw.config.get( 'wgWMPageViewInfo' );
-                               MyDialog.parent.prototype.initialize.call( this 
);
+                       OO.inheritClass( MyProcessDialog, OO.ui.ProcessDialog );
+
+                       MyProcessDialog.static.title = mw.msg( 'wmpvi-range', 
info.start, info.end );
+                       MyProcessDialog.static.actions = [
+                               { label: mw.msg( 'wmpvi-close' ), flags: 'safe' 
}
+                       ];
+
+                       MyProcessDialog.prototype.initialize = function () {
+                               
MyProcessDialog.parent.prototype.initialize.apply( this, arguments );
                                this.content = new OO.ui.PanelLayout( { padded: 
true, expanded: false } );
                                this.$body.append( this.content.$element );
-                               mw.drawVegaGraph( this.content.$element[ 0 ], 
def );
+                               mw.drawVegaGraph( this.content.$element[ 0 ], 
info.graph );
                        };
-                       myDialog = new MyDialog( {
-                               size: 'large'
-                       } );
-                       // Create and append a window manager, which opens and 
closes the window.
+                       MyProcessDialog.prototype.getActionProcess = function ( 
action ) {
+                               var dialog = this;
+                               if ( action ) {
+                                       return new OO.ui.Process( function () {
+                                               dialog.close( { action: action 
} );
+                                       } );
+                               }
+                               return 
MyProcessDialog.parent.prototype.getActionProcess.call( this, action );
+                       };
+
                        windowManager = new OO.ui.WindowManager();
                        $( 'body' ).append( windowManager.$element );
-                       windowManager.addWindows( [ myDialog ] );
-                       // Open the window!
-                       windowManager.openWindow( myDialog );
+
+                       dialog = new MyProcessDialog( { size: 'large' } );
+                       windowManager.addWindows( [ dialog ] );
+                       windowManager.openWindow( dialog );
                } );
 
        } );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3becf2d6da45106fc26c4321dc8b64e7e508b510
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/WikimediaPageViewInfo
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to