Merge "Add 3D filetype for STL files"
[lhc/web/wiklou.git] / includes / specials / pagers / ContribsPager.php
index e690a3f..6bd7eb0 100644 (file)
@@ -365,9 +365,9 @@ class ContribsPager extends RangeChronologicalPager {
         * @return string
         */
        function formatRow( $row ) {
-
                $ret = '';
                $classes = [];
+               $attribs = [];
 
                $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
 
@@ -388,7 +388,7 @@ class ContribsPager extends RangeChronologicalPager {
                MediaWiki\restoreWarnings();
 
                if ( $validRevision ) {
-                       $classes = [];
+                       $attribs['data-mw-revid'] = $rev->getId();
 
                        $page = Title::newFromRow( $row );
                        $link = $linkRenderer->makeLink(
@@ -535,19 +535,21 @@ class ContribsPager extends RangeChronologicalPager {
                }
 
                // Let extensions add data
-               Hooks::run( 'ContributionsLineEnding', [ $this, &$ret, $row, &$classes ] );
+               Hooks::run( 'ContributionsLineEnding', [ $this, &$ret, $row, &$classes, &$attribs ] );
+               $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
 
                // TODO: Handle exceptions in the catch block above.  Do any extensions rely on
                // receiving empty rows?
 
-               if ( $classes === [] && $ret === '' ) {
+               if ( $classes === [] && $attribs === [] && $ret === '' ) {
                        wfDebug( "Dropping Special:Contribution row that could not be formatted\n" );
                        return "<!-- Could not format Special:Contribution row. -->\n";
                }
+               $attribs['class'] = $classes;
 
                // FIXME: The signature of the ContributionsLineEnding hook makes it
                // very awkward to move this LI wrapper into the template.
-               return Html::rawElement( 'li', [ 'class' => $classes ], $ret ) . "\n";
+               return Html::rawElement( 'li', $attribs, $ret ) . "\n";
        }
 
        /**
@@ -573,4 +575,43 @@ class ContribsPager extends RangeChronologicalPager {
        public function getPreventClickjacking() {
                return $this->preventClickjacking;
        }
+
+       /**
+        * 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;
+       }
 }