* @return string
*/
function formatRow( $row ) {
-
$ret = '';
$classes = [];
+ $attribs = [];
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
MediaWiki\restoreWarnings();
if ( $validRevision ) {
- $classes = [];
+ $attribs['data-mw-revid'] = $rev->getId();
$page = Title::newFromRow( $row );
$link = $linkRenderer->makeLink(
}
// 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";
}
/**
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;
+ }
}