use Wikimedia\Rdbms\FakeResultWrapper;
use Wikimedia\Rdbms\IDatabase;
-class ContribsPager extends ReverseChronologicalPager {
+class ContribsPager extends RangeChronologicalPager {
public $mDefaultDirection = IndexPager::DIR_DESCENDING;
public $messages;
$this->newOnly = !empty( $options['newOnly'] );
$this->hideMinor = !empty( $options['hideMinor'] );
- $year = isset( $options['year'] ) ? $options['year'] : false;
- $month = isset( $options['month'] ) ? $options['month'] : false;
- $this->getDateCond( $year, $month );
+ // Date filtering: use timestamp if available
+ $startTimestamp = '';
+ $endTimestamp = '';
+ if ( $options['start'] ) {
+ $startTimestamp = $options['start'] . ' 00:00:00';
+ }
+ if ( $options['end'] ) {
+ $endTimestamp = $options['end'] . ' 23:59:59';
+ }
+ $this->getDateRangeCond( $startTimestamp, $endTimestamp );
// 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
* @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(
}
# Show user names for /newbies as there may be different users.
- # Note that we already excluded rows with hidden user names.
- if ( $this->contribs == 'newbie' ) {
+ # Note that only unprivileged users have rows with hidden user names excluded.
+ $userlink = '';
+ if ( $this->contribs == 'newbie' && !$rev->isDeleted( Revision::DELETED_USER ) ) {
$userlink = ' . . ' . $lang->getDirMark()
. Linker::userLink( $rev->getUser(), $rev->getUserText() );
$userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
- Linker::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
- } else {
- $userlink = '';
+ Linker::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
}
$flags = [];
}
// 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 = isset( $opts['start'] ) ? $opts['start'] : '';
+ $end = isset( $opts['end'] ) ? $opts['end'] : '';
+ $year = isset( $opts['year'] ) ? $opts['year'] : '';
+ $month = isset( $opts['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;
+ }
}