X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fspecials%2Fpagers%2FContribsPager.php;h=6bd7eb0e9fdb50ad830db38014eb8038bfa59fb8;hp=11336251ec6479094d0c21c083db8957b3cd74d5;hb=f7e1770fb832aa77bf4e16ce8cc815f2b24dd10d;hpb=6fbafe5494440f5c37686b250ed759f6a96271b9 diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index 11336251ec..6bd7eb0e9f 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -28,7 +28,7 @@ use Wikimedia\Rdbms\ResultWrapper; use Wikimedia\Rdbms\FakeResultWrapper; use Wikimedia\Rdbms\IDatabase; -class ContribsPager extends ReverseChronologicalPager { +class ContribsPager extends RangeChronologicalPager { public $mDefaultDirection = IndexPager::DIR_DESCENDING; public $messages; @@ -45,6 +45,11 @@ class ContribsPager extends ReverseChronologicalPager { */ protected $mParentLens; + /** + * @var TemplateParser + */ + protected $templateParser; + function __construct( IContextSource $context, array $options ) { parent::__construct( $context ); @@ -71,15 +76,23 @@ class ContribsPager extends ReverseChronologicalPager { $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 // queries should use a regular replica DB since the lookup pattern is not all by user. $this->mDbSecondary = wfGetDB( DB_REPLICA ); // any random replica DB $this->mDb = wfGetDB( DB_REPLICA, 'contributions' ); + $this->templateParser = new TemplateParser(); } function getDefaultQuery() { @@ -228,10 +241,8 @@ class ContribsPager extends ReverseChronologicalPager { 'LEFT JOIN', [ 'ug_user = rev_user', 'ug_group' => $groupsWithBotPermission, - $this->getConfig()->get( 'DisableUserGroupExpiry' ) ? - '1' : - 'ug_expiry IS NULL OR ug_expiry >= ' . - $this->mDb->addQuotes( $this->mDb->timestamp() ) + 'ug_expiry IS NULL OR ug_expiry >= ' . + $this->mDb->addQuotes( $this->mDb->timestamp() ) ] ]; } @@ -354,9 +365,9 @@ class ContribsPager extends ReverseChronologicalPager { * @return string */ function formatRow( $row ) { - $ret = ''; $classes = []; + $attribs = []; $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); @@ -377,7 +388,7 @@ class ContribsPager extends ReverseChronologicalPager { MediaWiki\restoreWarnings(); if ( $validRevision ) { - $classes = []; + $attribs['data-mw-revid'] = $rev->getId(); $page = Title::newFromRow( $row ); $link = $linkRenderer->makeLink( @@ -461,14 +472,13 @@ class ContribsPager extends ReverseChronologicalPager { } # 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 = []; @@ -518,27 +528,28 @@ class ContribsPager extends ReverseChronologicalPager { $this->msg( 'rev-deleted-user-contribs' )->escaped(); } - $templateParser = new TemplateParser(); - $ret = $templateParser->processTemplate( + $ret = $this->templateParser->processTemplate( 'SpecialContributionsLine', $templateParams ); } // 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"; } /** @@ -564,4 +575,43 @@ class ContribsPager extends ReverseChronologicalPager { 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; + } }