Special:Contribs: Ensure 'start' and 'end' are never undefined
[lhc/web/wiklou.git] / includes / specials / SpecialContributions.php
index cc399b6..1b14fcb 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\Widget\DateInputWidget;
+
 /**
  * Special:Contributions, show user contributions in a paged list
  *
@@ -40,7 +42,7 @@ class SpecialContributions extends IncludableSpecialPage {
                $out->addModuleStyles( [
                        'mediawiki.special',
                        'mediawiki.special.changeslist',
-                       'mediawiki.widgets.DateInputWidget',
+                       'mediawiki.widgets.DateInputWidget.styles',
                ] );
                $out->addModules( 'mediawiki.special.contributions' );
                $this->addHelpLink( 'Help:User contributions' );
@@ -129,17 +131,14 @@ class SpecialContributions extends IncludableSpecialPage {
 
                $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
                # Offset overrides year/month selection
-               if ( $skip ) {
-                       $this->opts['year'] = '';
-                       $this->opts['month'] = '';
-               } else {
+               if ( !$skip ) {
                        $this->opts['year'] = $request->getVal( 'year' );
                        $this->opts['month'] = $request->getVal( 'month' );
 
                        $this->opts['start'] = $request->getVal( 'start' );
                        $this->opts['end'] = $request->getVal( 'end' );
-                       $this->opts = SpecialContributions::processDateFilter( $this->opts );
                }
+               $this->opts = ContribsPager::processDateFilter( $this->opts );
 
                $feedType = $request->getVal( 'feed' );
 
@@ -327,7 +326,6 @@ class SpecialContributions extends IncludableSpecialPage {
         * @return array
         */
        public static function getUserLinks( SpecialPage $sp, User $target ) {
-
                $id = $target->getId();
                $username = $target->getName();
                $userpage = $target->getUserPage();
@@ -665,7 +663,7 @@ class SpecialContributions extends IncludableSpecialPage {
                        'div',
                        [],
                        Xml::label( wfMessage( 'date-range-from' )->text(), 'mw-date-start' ) . ' ' .
-                       new \Mediawiki\Widget\DateInputWidget( [
+                       new DateInputWidget( [
                                'infusable' => true,
                                'id' => 'mw-date-start',
                                'name' => 'start',
@@ -673,7 +671,7 @@ class SpecialContributions extends IncludableSpecialPage {
                                'longDisplayFormat' => true,
                        ] ) . '<br>' .
                        Xml::label( wfMessage( 'date-range-to' )->text(), 'mw-date-end' ) . ' ' .
-                       new \Mediawiki\Widget\DateInputWidget( [
+                       new DateInputWidget( [
                                'infusable' => true,
                                'id' => 'mw-date-end',
                                'name' => 'end',
@@ -728,46 +726,6 @@ class SpecialContributions extends IncludableSpecialPage {
                return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
        }
 
-       /**
-        * Set up date filter options, given request data.
-        *
-        * @param array $opts Options array
-        * @return array Options array with processed start and end date filter options
-        */
-       public static function processDateFilter( $opts ) {
-               $start = $opts['start'] ?: '';
-               $end = $opts['end'] ?: '';
-               $year = $opts['year'] ?: '';
-               $month = $opts['month'] ?: '';
-
-               if ( $start !== '' && $end !== '' &&
-                       $start > $end
-               ) {
-                       $temp = $start;
-                       $start = $end;
-                       $end = $temp;
-               }
-
-               // If year/month legacy filtering options are set, convert them to display the new stamp
-               if ( $year !== '' || $month !== '' ) {
-                       // Reuse getDateCond logic, but subtract a day because
-                       // the endpoints of our date range appear inclusive
-                       // but the internal end offsets are always exclusive
-                       $legacyTimestamp = ReverseChronologicalPager::getOffsetDate( $year, $month );
-                       $legacyDateTime = new DateTime( $legacyTimestamp->getTimestamp( TS_ISO_8601 ) );
-                       $legacyDateTime = $legacyDateTime->modify( '-1 day' );
-
-                       // Clear the new timestamp range options if used and
-                       // replace with the converted legacy timestamp
-                       $start = '';
-                       $end = $legacyDateTime->format( 'Y-m-d' );
-               }
-
-               $opts['start'] = $start;
-               $opts['end'] = $end;
-               return $opts;
-       }
-
        protected function getGroupName() {
                return 'users';
        }