Sn1per has uploaded a new change for review.

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

Change subject: [WIP] Use PHP DateInputWidget in Contribs
......................................................................

[WIP] Use PHP DateInputWidget in Contribs

Working prototype.
This change essentially adds filtering-by-day to Special:Contribs.

* Add DateInputWidget to Special:Contributions
* Add getDateCondWithDateString as a version of getDateCond that takes a
  date string as the offset
* Use getDateCondWithDateString with DateInputWidget value

Bug: T120733
Change-Id: Id15f2b2ce2954fe98dfbbb7b0e86c0e4e5713f5e
---
M includes/pager/ReverseChronologicalPager.php
M includes/specials/SpecialContributions.php
M includes/specials/pagers/ContribsPager.php
M resources/Resources.php
A resources/src/mediawiki.special/mediawiki.special.contributions.js
5 files changed, 56 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/74/316574/1

diff --git a/includes/pager/ReverseChronologicalPager.php 
b/includes/pager/ReverseChronologicalPager.php
index 4895b4f..05e7a63 100644
--- a/includes/pager/ReverseChronologicalPager.php
+++ b/includes/pager/ReverseChronologicalPager.php
@@ -153,4 +153,22 @@
                $this->mOffset = $this->mDb->timestamp( 
$timestamp->getTimestamp() );
                return $this->mOffset;
        }
+
+       /**
+        * Set and return the mOffset timestamp using a timestamp such that we 
can get all revisions
+        * with a timestamp up to the specified parameters.
+        * @param string $stamp Timestamp specified by user
+        * @return string|null Timestamp or null if year and month are 
false/invalid
+        */
+       function getDateCondWithDateString( $stamp ) {
+               $date = new DateTime( $stamp );
+
+               // We want the next day
+               $date = $date->modify( '+1 day' );
+               $timestamp = new MWTimestamp( $date->getTimestamp() );
+               $timestamp->setTimezone( $this->getConfig()->get( 
'Localtimezone' ) );
+
+               $this->mOffset = $this->mDb->timestamp( 
$timestamp->getTimestamp() );
+               return $this->mOffset;
+       }
 }
diff --git a/includes/specials/SpecialContributions.php 
b/includes/specials/SpecialContributions.php
index 0858b18..9e7c5ef 100644
--- a/includes/specials/SpecialContributions.php
+++ b/includes/specials/SpecialContributions.php
@@ -41,7 +41,9 @@
                        'mediawiki.special',
                        'mediawiki.special.changeslist',
                ] );
+               $out->addModules( 'mediawiki.special.contributions' );
                $this->addHelpLink( 'Help:User contributions' );
+               $out->enableOOUI();
 
                $this->opts = [];
                $request = $this->getRequest();
@@ -134,6 +136,8 @@
                        $this->opts['month'] = $request->getIntOrNull( 'month' 
);
                }
 
+               $this->opts['offset'] = $request->getVal( 'offset' );
+
                $feedType = $request->getVal( 'feed' );
 
                $feedParams = [
@@ -192,6 +196,7 @@
                                'tagfilter' => $this->opts['tagfilter'],
                                'year' => $this->opts['year'],
                                'month' => $this->opts['month'],
+                               'offset' => $this->opts['offset'],
                                'deletedOnly' => $this->opts['deletedOnly'],
                                'topOnly' => $this->opts['topOnly'],
                                'newOnly' => $this->opts['newOnly'],
@@ -440,6 +445,10 @@
                        $this->opts['month'] = '';
                }
 
+               if ( !isset( $this->opts['offset'] ) ) {
+                       $this->opts['offset'] = '';
+               }
+
                if ( $this->opts['contribs'] == 'newbie' ) {
                        $this->opts['target'] = '';
                }
@@ -478,6 +487,7 @@
                        'contribs',
                        'year',
                        'month',
+                       'offset',
                        'topOnly',
                        'newOnly',
                        'hideMinor',
@@ -669,7 +679,13 @@
                        $namespaceSelection .
                        $filterSelection .
                        $extraOptions .
-                       $dateSelectionAndSubmit,
+                       $dateSelectionAndSubmit .
+                       new \Mediawiki\Widget\DateInputWidget( [
+                               'infusable' => true,
+                           'id' => 'mw-date-offset',
+                           'name' => 'offset',
+                           'value' => $this->opts['offset'],
+                       ] ),
                        [ 'class' => 'mw-contributions-table' ]
                );
 
diff --git a/includes/specials/pagers/ContribsPager.php 
b/includes/specials/pagers/ContribsPager.php
index a145e45..fe56763 100644
--- a/includes/specials/pagers/ContribsPager.php
+++ b/includes/specials/pagers/ContribsPager.php
@@ -66,9 +66,16 @@
                $this->newOnly = !empty( $options['newOnly'] );
                $this->hideMinor = !empty( $options['hideMinor'] );
 
+               // Date filtering: use timestamp if available
+               $this->offset = isset( $options['offset'] ) ? 
$options['offset'] : false;
                $year = isset( $options['year'] ) ? $options['year'] : false;
                $month = isset( $options['month'] ) ? $options['month'] : false;
-               $this->getDateCond( $year, $month );
+
+               if ( $this->offset ) {
+                       $this->getDateCondWithDateString( $this->offset );
+               } else {
+                       $this->getDateCond( $year, $month );
+               }
 
                // Most of this code will use the 'contributions' group DB, 
which can map to replica DBs
                // with extra user based indexes or partioning by user. The 
additional metadata
diff --git a/resources/Resources.php b/resources/Resources.php
index 2e4a15d..c83200d 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -1902,6 +1902,13 @@
                'position' => 'top',
                'styles' => 
'resources/src/mediawiki.special/mediawiki.special.comparepages.styles.less',
        ],
+       'mediawiki.special.contributions' => [
+               'scripts' => 
'resources/src/mediawiki.special/mediawiki.special.contributions.js',
+               'dependencies' => [
+                       'mediawiki.widgets.DateInputWidget',
+                       'mediawiki.jqueryMsg',
+               ]
+       ],
        'mediawiki.special.edittags' => [
                'scripts' => 
'resources/src/mediawiki.special/mediawiki.special.edittags.js',
                'dependencies' => [
diff --git a/resources/src/mediawiki.special/mediawiki.special.contributions.js 
b/resources/src/mediawiki.special/mediawiki.special.contributions.js
new file mode 100644
index 0000000..1aa9b86
--- /dev/null
+++ b/resources/src/mediawiki.special/mediawiki.special.contributions.js
@@ -0,0 +1,6 @@
+/*jshint -W024*/
+( function ( mw, $ ) {
+       $( function() {
+               mw.widgets.DateInputWidget.static.infuse( 'mw-date-offset' );
+       } );
+}( mediaWiki, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id15f2b2ce2954fe98dfbbb7b0e86c0e4e5713f5e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Sn1per <geof...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to