2bfc923e3a9456091205daa69b0672ac6663d344
[lhc/web/wiklou.git] / includes / specials / pagers / ContribsPager.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Pager
20 */
21
22 /**
23 * Pager for Special:Contributions
24 * @ingroup Pager
25 */
26 use MediaWiki\MediaWikiServices;
27 use Wikimedia\Rdbms\IResultWrapper;
28 use Wikimedia\Rdbms\FakeResultWrapper;
29 use Wikimedia\Rdbms\IDatabase;
30
31 class ContribsPager extends RangeChronologicalPager {
32
33 public $mDefaultDirection = IndexPager::DIR_DESCENDING;
34 public $messages;
35 public $target;
36 public $namespace = '';
37 public $mDb;
38 public $preventClickjacking = false;
39
40 /** @var IDatabase */
41 public $mDbSecondary;
42
43 /**
44 * @var array
45 */
46 protected $mParentLens;
47
48 /**
49 * @var TemplateParser
50 */
51 protected $templateParser;
52
53 function __construct( IContextSource $context, array $options ) {
54 parent::__construct( $context );
55
56 $msgs = [
57 'diff',
58 'hist',
59 'pipe-separator',
60 'uctop'
61 ];
62
63 foreach ( $msgs as $msg ) {
64 $this->messages[$msg] = $this->msg( $msg )->escaped();
65 }
66
67 $this->target = $options['target'] ?? '';
68 $this->contribs = $options['contribs'] ?? 'users';
69 $this->namespace = $options['namespace'] ?? '';
70 $this->tagFilter = $options['tagfilter'] ?? false;
71 $this->nsInvert = $options['nsInvert'] ?? false;
72 $this->associated = $options['associated'] ?? false;
73
74 $this->deletedOnly = !empty( $options['deletedOnly'] );
75 $this->topOnly = !empty( $options['topOnly'] );
76 $this->newOnly = !empty( $options['newOnly'] );
77 $this->hideMinor = !empty( $options['hideMinor'] );
78
79 // Date filtering: use timestamp if available
80 $startTimestamp = '';
81 $endTimestamp = '';
82 if ( $options['start'] ) {
83 $startTimestamp = $options['start'] . ' 00:00:00';
84 }
85 if ( $options['end'] ) {
86 $endTimestamp = $options['end'] . ' 23:59:59';
87 }
88 $this->getDateRangeCond( $startTimestamp, $endTimestamp );
89
90 // Most of this code will use the 'contributions' group DB, which can map to replica DBs
91 // with extra user based indexes or partioning by user. The additional metadata
92 // queries should use a regular replica DB since the lookup pattern is not all by user.
93 $this->mDbSecondary = wfGetDB( DB_REPLICA ); // any random replica DB
94 $this->mDb = wfGetDB( DB_REPLICA, 'contributions' );
95 $this->templateParser = new TemplateParser();
96 }
97
98 function getDefaultQuery() {
99 $query = parent::getDefaultQuery();
100 $query['target'] = $this->target;
101
102 return $query;
103 }
104
105 /**
106 * This method basically executes the exact same code as the parent class, though with
107 * a hook added, to allow extensions to add additional queries.
108 *
109 * @param string $offset Index offset, inclusive
110 * @param int $limit Exact query limit
111 * @param bool $descending Query direction, false for ascending, true for descending
112 * @return IResultWrapper
113 */
114 function reallyDoQuery( $offset, $limit, $descending ) {
115 list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
116 $offset,
117 $limit,
118 $descending
119 );
120
121 /*
122 * This hook will allow extensions to add in additional queries, so they can get their data
123 * in My Contributions as well. Extensions should append their results to the $data array.
124 *
125 * Extension queries have to implement the navbar requirement as well. They should
126 * - have a column aliased as $pager->getIndexField()
127 * - have LIMIT set
128 * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
129 * - have the ORDER BY specified based upon the details provided by the navbar
130 *
131 * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
132 *
133 * &$data: an array of results of all contribs queries
134 * $pager: the ContribsPager object hooked into
135 * $offset: see phpdoc above
136 * $limit: see phpdoc above
137 * $descending: see phpdoc above
138 */
139 $data = [ $this->mDb->select(
140 $tables, $fields, $conds, $fname, $options, $join_conds
141 ) ];
142 Hooks::run(
143 'ContribsPager::reallyDoQuery',
144 [ &$data, $this, $offset, $limit, $descending ]
145 );
146
147 $result = [];
148
149 // loop all results and collect them in an array
150 foreach ( $data as $query ) {
151 foreach ( $query as $i => $row ) {
152 // use index column as key, allowing us to easily sort in PHP
153 $result[$row->{$this->getIndexField()} . "-$i"] = $row;
154 }
155 }
156
157 // sort results
158 if ( $descending ) {
159 ksort( $result );
160 } else {
161 krsort( $result );
162 }
163
164 // enforce limit
165 $result = array_slice( $result, 0, $limit );
166
167 // get rid of array keys
168 $result = array_values( $result );
169
170 return new FakeResultWrapper( $result );
171 }
172
173 function getQueryInfo() {
174 $revQuery = Revision::getQueryInfo( [ 'page', 'user' ] );
175 $queryInfo = [
176 'tables' => $revQuery['tables'],
177 'fields' => array_merge( $revQuery['fields'], [ 'page_is_new' ] ),
178 'conds' => [],
179 'options' => [],
180 'join_conds' => $revQuery['joins'],
181 ];
182
183 if ( $this->contribs == 'newbie' ) {
184 $max = $this->mDb->selectField( 'user', 'max(user_id)', '', __METHOD__ );
185 $queryInfo['conds'][] = $revQuery['fields']['rev_user'] . ' >' . (int)( $max - $max / 100 );
186 # ignore local groups with the bot right
187 # @todo FIXME: Global groups may have 'bot' rights
188 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
189 if ( count( $groupsWithBotPermission ) ) {
190 $queryInfo['tables'][] = 'user_groups';
191 $queryInfo['conds'][] = 'ug_group IS NULL';
192 $queryInfo['join_conds']['user_groups'] = [
193 'LEFT JOIN', [
194 'ug_user = ' . $revQuery['fields']['rev_user'],
195 'ug_group' => $groupsWithBotPermission,
196 'ug_expiry IS NULL OR ug_expiry >= ' .
197 $this->mDb->addQuotes( $this->mDb->timestamp() )
198 ]
199 ];
200 }
201 // (T140537) Disallow looking too far in the past for 'newbies' queries. If the user requested
202 // a timestamp offset far in the past such that there are no edits by users with user_ids in
203 // the range, we would end up scanning all revisions from that offset until start of time.
204 $queryInfo['conds'][] = 'rev_timestamp > ' .
205 $this->mDb->addQuotes( $this->mDb->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) );
206 } else {
207 $user = User::newFromName( $this->target, false );
208 $ipRangeConds = $user->isAnon() ? $this->getIpRangeConds( $this->mDb, $this->target ) : null;
209 if ( $ipRangeConds ) {
210 $queryInfo['tables'][] = 'ip_changes';
211 /**
212 * These aliases make `ORDER BY rev_timestamp, rev_id` from {@see getIndexField} and
213 * {@see getExtraSortFields} use the replicated `ipc_rev_timestamp` and `ipc_rev_id`
214 * columns from the `ip_changes` table, for more efficient queries.
215 * @see https://phabricator.wikimedia.org/T200259#4832318
216 */
217 $queryInfo['fields'] = array_merge(
218 [
219 'rev_timestamp' => 'ipc_rev_timestamp',
220 'rev_id' => 'ipc_rev_id',
221 ],
222 array_diff( $queryInfo['fields'], [
223 'rev_timestamp',
224 'rev_id',
225 ] )
226 );
227 $queryInfo['join_conds']['ip_changes'] = [
228 'LEFT JOIN', [ 'ipc_rev_id = rev_id' ]
229 ];
230 $queryInfo['conds'][] = $ipRangeConds;
231 } else {
232 // tables and joins are already handled by Revision::getQueryInfo()
233 $conds = ActorMigration::newMigration()->getWhere( $this->mDb, 'rev_user', $user );
234 $queryInfo['conds'][] = $conds['conds'];
235 // Force the appropriate index to avoid bad query plans (T189026)
236 if ( isset( $conds['orconds']['actor'] ) ) {
237 // @todo: This will need changing when revision_comment_temp goes away
238 $queryInfo['options']['USE INDEX']['temp_rev_user'] = 'actor_timestamp';
239 // Alias 'rev_timestamp' => 'revactor_timestamp' so "ORDER BY rev_timestamp" is interpreted to
240 // use revactor_timestamp instead.
241 $queryInfo['fields'] = array_merge(
242 array_diff( $queryInfo['fields'], [ 'rev_timestamp' ] ),
243 [ 'rev_timestamp' => 'revactor_timestamp' ]
244 );
245 } else {
246 $queryInfo['options']['USE INDEX']['revision'] =
247 isset( $conds['orconds']['userid'] ) ? 'user_timestamp' : 'usertext_timestamp';
248 }
249 }
250 }
251
252 if ( $this->deletedOnly ) {
253 $queryInfo['conds'][] = 'rev_deleted != 0';
254 }
255
256 if ( $this->topOnly ) {
257 $queryInfo['conds'][] = 'rev_id = page_latest';
258 }
259
260 if ( $this->newOnly ) {
261 $queryInfo['conds'][] = 'rev_parent_id = 0';
262 }
263
264 if ( $this->hideMinor ) {
265 $queryInfo['conds'][] = 'rev_minor_edit = 0';
266 }
267
268 $user = $this->getUser();
269 $queryInfo['conds'] = array_merge( $queryInfo['conds'], $this->getNamespaceCond() );
270
271 // Paranoia: avoid brute force searches (T19342)
272 if ( !$user->isAllowed( 'deletedhistory' ) ) {
273 $queryInfo['conds'][] = $this->mDb->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0';
274 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
275 $queryInfo['conds'][] = $this->mDb->bitAnd( 'rev_deleted', Revision::SUPPRESSED_USER ) .
276 ' != ' . Revision::SUPPRESSED_USER;
277 }
278
279 // For IPv6, we use ipc_rev_timestamp on ip_changes as the index field,
280 // which will be referenced when parsing the results of a query.
281 if ( self::isQueryableRange( $this->target ) ) {
282 $queryInfo['fields'][] = 'ipc_rev_timestamp';
283 }
284
285 ChangeTags::modifyDisplayQuery(
286 $queryInfo['tables'],
287 $queryInfo['fields'],
288 $queryInfo['conds'],
289 $queryInfo['join_conds'],
290 $queryInfo['options'],
291 $this->tagFilter
292 );
293
294 // Avoid PHP 7.1 warning from passing $this by reference
295 $pager = $this;
296 Hooks::run( 'ContribsPager::getQueryInfo', [ &$pager, &$queryInfo ] );
297
298 return $queryInfo;
299 }
300
301 function getNamespaceCond() {
302 if ( $this->namespace !== '' ) {
303 $selectedNS = $this->mDb->addQuotes( $this->namespace );
304 $eq_op = $this->nsInvert ? '!=' : '=';
305 $bool_op = $this->nsInvert ? 'AND' : 'OR';
306
307 if ( !$this->associated ) {
308 return [ "page_namespace $eq_op $selectedNS" ];
309 }
310
311 $associatedNS = $this->mDb->addQuotes(
312 MWNamespace::getAssociated( $this->namespace )
313 );
314
315 return [
316 "page_namespace $eq_op $selectedNS " .
317 $bool_op .
318 " page_namespace $eq_op $associatedNS"
319 ];
320 }
321
322 return [];
323 }
324
325 /**
326 * Get SQL conditions for an IP range, if applicable
327 * @param IDatabase $db
328 * @param string $ip The IP address or CIDR
329 * @return string|false SQL for valid IP ranges, false if invalid
330 */
331 private function getIpRangeConds( $db, $ip ) {
332 // First make sure it is a valid range and they are not outside the CIDR limit
333 if ( !$this->isQueryableRange( $ip ) ) {
334 return false;
335 }
336
337 list( $start, $end ) = IP::parseRange( $ip );
338
339 return 'ipc_hex BETWEEN ' . $db->addQuotes( $start ) . ' AND ' . $db->addQuotes( $end );
340 }
341
342 /**
343 * Is the given IP a range and within the CIDR limit?
344 *
345 * @param string $ipRange
346 * @return bool True if it is valid
347 * @since 1.30
348 */
349 public function isQueryableRange( $ipRange ) {
350 $limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' );
351
352 $bits = IP::parseCIDR( $ipRange )[1];
353 if (
354 ( $bits === false ) ||
355 ( IP::isIPv4( $ipRange ) && $bits < $limits['IPv4'] ) ||
356 ( IP::isIPv6( $ipRange ) && $bits < $limits['IPv6'] )
357 ) {
358 return false;
359 }
360
361 return true;
362 }
363
364 /**
365 * @return string
366 */
367 public function getIndexField() {
368 // Note this is run via parent::__construct() *before* $this->target is set!
369 return 'rev_timestamp';
370 }
371
372 /**
373 * @return string[]
374 */
375 protected function getExtraSortFields() {
376 // Note this is run via parent::__construct() *before* $this->target is set!
377 return [ 'rev_id' ];
378 }
379
380 function doBatchLookups() {
381 # Do a link batch query
382 $this->mResult->seek( 0 );
383 $parentRevIds = [];
384 $this->mParentLens = [];
385 $batch = new LinkBatch();
386 $isIpRange = $this->isQueryableRange( $this->target );
387 # Give some pointers to make (last) links
388 foreach ( $this->mResult as $row ) {
389 if ( isset( $row->rev_parent_id ) && $row->rev_parent_id ) {
390 $parentRevIds[] = $row->rev_parent_id;
391 }
392 if ( isset( $row->rev_id ) ) {
393 $this->mParentLens[$row->rev_id] = $row->rev_len;
394 if ( $this->contribs === 'newbie' ) { // multiple users
395 $batch->add( NS_USER, $row->user_name );
396 $batch->add( NS_USER_TALK, $row->user_name );
397 } elseif ( $isIpRange ) {
398 // If this is an IP range, batch the IP's talk page
399 $batch->add( NS_USER_TALK, $row->rev_user_text );
400 }
401 $batch->add( $row->page_namespace, $row->page_title );
402 }
403 }
404 # Fetch rev_len for revisions not already scanned above
405 $this->mParentLens += Revision::getParentLengths(
406 $this->mDbSecondary,
407 array_diff( $parentRevIds, array_keys( $this->mParentLens ) )
408 );
409 $batch->execute();
410 $this->mResult->seek( 0 );
411 }
412
413 /**
414 * @return string
415 */
416 function getStartBody() {
417 return "<ul class=\"mw-contributions-list\">\n";
418 }
419
420 /**
421 * @return string
422 */
423 function getEndBody() {
424 return "</ul>\n";
425 }
426
427 /**
428 * Check whether the revision associated is valid for formatting. If has no associated revision
429 * id then null is returned.
430 *
431 * @param object $row
432 * @param Title|null $title
433 * @return Revision|null
434 */
435 public function tryToCreateValidRevision( $row, $title = null ) {
436 /*
437 * There may be more than just revision rows. To make sure that we'll only be processing
438 * revisions here, let's _try_ to build a revision out of our row (without displaying
439 * notices though) and then trying to grab data from the built object. If we succeed,
440 * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
441 * to extensions to subscribe to the hook to parse the row.
442 */
443 Wikimedia\suppressWarnings();
444 try {
445 $rev = new Revision( $row, 0, $title );
446 $validRevision = (bool)$rev->getId();
447 } catch ( Exception $e ) {
448 $validRevision = false;
449 }
450 Wikimedia\restoreWarnings();
451 return $validRevision ? $rev : null;
452 }
453
454 /**
455 * Generates each row in the contributions list.
456 *
457 * Contributions which are marked "top" are currently on top of the history.
458 * For these contributions, a [rollback] link is shown for users with roll-
459 * back privileges. The rollback link restores the most recent version that
460 * was not written by the target user.
461 *
462 * @todo This would probably look a lot nicer in a table.
463 * @param object $row
464 * @return string
465 */
466 function formatRow( $row ) {
467 $ret = '';
468 $classes = [];
469 $attribs = [];
470
471 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
472
473 $page = null;
474 // Create a title for the revision if possible
475 // Rows from the hook may not include title information
476 if ( isset( $row->page_namespace ) && isset( $row->page_title ) ) {
477 $page = Title::newFromRow( $row );
478 }
479 $rev = $this->tryToCreateValidRevision( $row, $page );
480 if ( $rev ) {
481 $attribs['data-mw-revid'] = $rev->getId();
482
483 $link = $linkRenderer->makeLink(
484 $page,
485 $page->getPrefixedText(),
486 [ 'class' => 'mw-contributions-title' ],
487 $page->isRedirect() ? [ 'redirect' => 'no' ] : []
488 );
489 # Mark current revisions
490 $topmarktext = '';
491 $user = $this->getUser();
492
493 if ( $row->rev_id === $row->page_latest ) {
494 $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
495 $classes[] = 'mw-contributions-current';
496 # Add rollback link
497 if ( !$row->page_is_new && $page->quickUserCan( 'rollback', $user )
498 && $page->quickUserCan( 'edit', $user )
499 ) {
500 $this->preventClickjacking();
501 $topmarktext .= ' ' . Linker::generateRollback( $rev, $this->getContext() );
502 }
503 }
504 # Is there a visible previous revision?
505 if ( $rev->userCan( Revision::DELETED_TEXT, $user ) && $rev->getParentId() !== 0 ) {
506 $difftext = $linkRenderer->makeKnownLink(
507 $page,
508 new HtmlArmor( $this->messages['diff'] ),
509 [ 'class' => 'mw-changeslist-diff' ],
510 [
511 'diff' => 'prev',
512 'oldid' => $row->rev_id
513 ]
514 );
515 } else {
516 $difftext = $this->messages['diff'];
517 }
518 $histlink = $linkRenderer->makeKnownLink(
519 $page,
520 new HtmlArmor( $this->messages['hist'] ),
521 [ 'class' => 'mw-changeslist-history' ],
522 [ 'action' => 'history' ]
523 );
524
525 if ( $row->rev_parent_id === null ) {
526 // For some reason rev_parent_id isn't populated for this row.
527 // Its rumoured this is true on wikipedia for some revisions (T36922).
528 // Next best thing is to have the total number of bytes.
529 $chardiff = ' <span class="mw-changeslist-separator"></span> ';
530 $chardiff .= Linker::formatRevisionSize( $row->rev_len );
531 $chardiff .= ' <span class="mw-changeslist-separator"></span> ';
532 } else {
533 $parentLen = 0;
534 if ( isset( $this->mParentLens[$row->rev_parent_id] ) ) {
535 $parentLen = $this->mParentLens[$row->rev_parent_id];
536 }
537
538 $chardiff = ' <span class="mw-changeslist-separator"></span> ';
539 $chardiff .= ChangesList::showCharacterDifference(
540 $parentLen,
541 $row->rev_len,
542 $this->getContext()
543 );
544 $chardiff .= ' <span class="mw-changeslist-separator"></span> ';
545 }
546
547 $lang = $this->getLanguage();
548 $comment = $lang->getDirMark() . Linker::revComment( $rev, false, true, false );
549 $date = $lang->userTimeAndDate( $row->rev_timestamp, $user );
550 if ( $rev->userCan( Revision::DELETED_TEXT, $user ) ) {
551 $d = $linkRenderer->makeKnownLink(
552 $page,
553 $date,
554 [ 'class' => 'mw-changeslist-date' ],
555 [ 'oldid' => intval( $row->rev_id ) ]
556 );
557 } else {
558 $d = htmlspecialchars( $date );
559 }
560 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
561 $d = '<span class="history-deleted">' . $d . '</span>';
562 }
563
564 # Show user names for /newbies as there may be different users.
565 # Note that only unprivileged users have rows with hidden user names excluded.
566 # When querying for an IP range, we want to always show user and user talk links.
567 $userlink = '';
568 if ( ( $this->contribs == 'newbie' && !$rev->isDeleted( Revision::DELETED_USER ) )
569 || $this->isQueryableRange( $this->target ) ) {
570 $userlink = ' <span class="mw-changeslist-separator"></span> '
571 . $lang->getDirMark()
572 . Linker::userLink( $rev->getUser(), $rev->getUserText() );
573 $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
574 Linker::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
575 }
576
577 $flags = [];
578 if ( $rev->getParentId() === 0 ) {
579 $flags[] = ChangesList::flag( 'newpage' );
580 }
581
582 if ( $rev->isMinor() ) {
583 $flags[] = ChangesList::flag( 'minor' );
584 }
585
586 $del = Linker::getRevDeleteLink( $user, $rev, $page );
587 if ( $del !== '' ) {
588 $del .= ' ';
589 }
590
591 // While it might be tempting to use a list here
592 // this would result in clutter and slows down navigating the content
593 // in assistive technology.
594 // See https://phabricator.wikimedia.org/T205581#4734812
595 $diffHistLinks = Html::rawElement( 'span',
596 [ 'class' => 'mw-changeslist-links' ],
597 // The spans are needed to ensure the dividing '|' elements are not
598 // themselves styled as links.
599 Html::rawElement( 'span', [], $difftext ) .
600 ' ' . // Space needed for separating two words.
601 Html::rawElement( 'span', [], $histlink )
602 );
603
604 # Tags, if any.
605 list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
606 $row->ts_tags,
607 'contributions',
608 $this->getContext()
609 );
610 $classes = array_merge( $classes, $newClasses );
611
612 Hooks::run( 'SpecialContributions::formatRow::flags', [ $this->getContext(), $row, &$flags ] );
613
614 $templateParams = [
615 'del' => $del,
616 'timestamp' => $d,
617 'diffHistLinks' => $diffHistLinks,
618 'charDifference' => $chardiff,
619 'flags' => $flags,
620 'articleLink' => $link,
621 'userlink' => $userlink,
622 'logText' => $comment,
623 'topmarktext' => $topmarktext,
624 'tagSummary' => $tagSummary,
625 ];
626
627 # Denote if username is redacted for this edit
628 if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
629 $templateParams['rev-deleted-user-contribs'] =
630 $this->msg( 'rev-deleted-user-contribs' )->escaped();
631 }
632
633 $ret = $this->templateParser->processTemplate(
634 'SpecialContributionsLine',
635 $templateParams
636 );
637 }
638
639 // Let extensions add data
640 Hooks::run( 'ContributionsLineEnding', [ $this, &$ret, $row, &$classes, &$attribs ] );
641 $attribs = array_filter( $attribs,
642 [ Sanitizer::class, 'isReservedDataAttribute' ],
643 ARRAY_FILTER_USE_KEY
644 );
645
646 // TODO: Handle exceptions in the catch block above. Do any extensions rely on
647 // receiving empty rows?
648
649 if ( $classes === [] && $attribs === [] && $ret === '' ) {
650 wfDebug( "Dropping Special:Contribution row that could not be formatted\n" );
651 return "<!-- Could not format Special:Contribution row. -->\n";
652 }
653 $attribs['class'] = $classes;
654
655 // FIXME: The signature of the ContributionsLineEnding hook makes it
656 // very awkward to move this LI wrapper into the template.
657 return Html::rawElement( 'li', $attribs, $ret ) . "\n";
658 }
659
660 /**
661 * Overwrite Pager function and return a helpful comment
662 * @return string
663 */
664 function getSqlComment() {
665 if ( $this->namespace || $this->deletedOnly ) {
666 // potentially slow, see CR r58153
667 return 'contributions page filtered for namespace or RevisionDeleted edits';
668 } else {
669 return 'contributions page unfiltered';
670 }
671 }
672
673 protected function preventClickjacking() {
674 $this->preventClickjacking = true;
675 }
676
677 /**
678 * @return bool
679 */
680 public function getPreventClickjacking() {
681 return $this->preventClickjacking;
682 }
683
684 /**
685 * Set up date filter options, given request data.
686 *
687 * @param array $opts Options array
688 * @return array Options array with processed start and end date filter options
689 */
690 public static function processDateFilter( array $opts ) {
691 $start = $opts['start'] ?? '';
692 $end = $opts['end'] ?? '';
693 $year = $opts['year'] ?? '';
694 $month = $opts['month'] ?? '';
695
696 if ( $start !== '' && $end !== '' && $start > $end ) {
697 $temp = $start;
698 $start = $end;
699 $end = $temp;
700 }
701
702 // If year/month legacy filtering options are set, convert them to display the new stamp
703 if ( $year !== '' || $month !== '' ) {
704 // Reuse getDateCond logic, but subtract a day because
705 // the endpoints of our date range appear inclusive
706 // but the internal end offsets are always exclusive
707 $legacyTimestamp = ReverseChronologicalPager::getOffsetDate( $year, $month );
708 $legacyDateTime = new DateTime( $legacyTimestamp->getTimestamp( TS_ISO_8601 ) );
709 $legacyDateTime = $legacyDateTime->modify( '-1 day' );
710
711 // Clear the new timestamp range options if used and
712 // replace with the converted legacy timestamp
713 $start = '';
714 $end = $legacyDateTime->format( 'Y-m-d' );
715 }
716
717 $opts['start'] = $start;
718 $opts['end'] = $end;
719
720 return $opts;
721 }
722 }