X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2Fpagers%2FContribsPager.php;h=6bd7eb0e9fdb50ad830db38014eb8038bfa59fb8;hb=12601ff7d2796752404bfb331fccc41083d31f9f;hp=e690a3f45dbb0bded16838c8346c9b7badf54005;hpb=e166ba2abd240abed62b4f93bd9c9d4eeb72fa64;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index e690a3f45d..6bd7eb0e9f 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -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 "\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; + } }