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