MediaWiki master
MergeHistoryPager.php
Go to the documentation of this file.
1<?php
9
24use Wikimedia\Timestamp\TimestampFormat as TS;
25
30
32 public $mGroupByDate = true;
33
34 private int $articleID;
35
37 public array $prevId;
38
39 public function __construct(
40 IContextSource $context,
41 LinkRenderer $linkRenderer,
42 private readonly LinkBatchFactory $linkBatchFactory,
43 IConnectionProvider $dbProvider,
44 private readonly RevisionStore $revisionStore,
45 private readonly CommentFormatter $commentFormatter,
46 private readonly ChangeTagsStore $changeTagsStore,
47 private readonly ChangeTagsFormatter $changeTagsFormatter,
48 public array $mConds,
50 PageIdentity $dest,
51 private readonly string $mergePointTimestamp,
52 private readonly string $mergePointTimestampOld,
53 ) {
54 $this->articleID = $source->getId();
55
56 $dbr = $dbProvider->getReplicaDatabase();
57
58 // Set database before parent constructor to avoid setting it there
59 $this->mDb = $dbr;
60 parent::__construct( $context, $linkRenderer );
61 }
62
64 protected function doBatchLookups() {
65 # Do a link batch query
66 $this->mResult->seek( 0 );
67 $batch = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
68 # Give some pointers to make (last) links
69 $this->prevId = [];
70 $rev_id = null;
71 foreach ( $this->mResult as $row ) {
72 $batch->addUser( new UserIdentityValue( (int)$row->rev_user, $row->rev_user_text ) );
73
74 if ( $rev_id !== null ) {
75 if ( $rev_id > $row->rev_id ) {
76 $this->prevId[$rev_id] = $row->rev_id;
77 } elseif ( $rev_id < $row->rev_id ) {
78 $this->prevId[$row->rev_id] = $rev_id;
79 }
80 }
81
82 $rev_id = $row->rev_id;
83 }
84
85 $batch->execute();
86 $this->mResult->seek( 0 );
87 }
88
92 protected function getStartBody() {
93 return "<section id='mw-mergehistory-list' class='mw-pager-body'>\n";
94 }
95
99 protected function getEndBody() {
100 return "</section>\n";
101 }
102
104 public function formatRow( $row ) {
105 $revRecord = $this->revisionStore->newRevisionFromRow( $row );
106
107 $linkRenderer = $this->getLinkRenderer();
108
109 $stxt = '';
110 $last = $this->msg( 'last' )->escaped();
111
112 $ts = wfTimestamp( TS::MW, $row->rev_timestamp );
113 $tsWithId = $ts . "|" . $row->rev_id;
114 $oldCheckBox = Html::radio(
115 'mergepointold',
116 $this->mergePointTimestampOld === $tsWithId,
117 [ 'value' => $tsWithId ]
118 );
119 $newCheckBox = Html::radio(
120 'mergepoint',
121 $this->mergePointTimestamp === $ts || $this->mergePointTimestamp === $tsWithId,
122 [ 'value' => $tsWithId ]
123 );
124 $cbs = $oldCheckBox . $newCheckBox;
125
126 $user = $this->getUser();
127
128 $pageLink = $linkRenderer->makeKnownLink(
129 $revRecord->getPageAsLinkTarget(),
130 $this->getLanguage()->userTimeAndDate( $ts, $user ),
131 [],
132 [ 'oldid' => $revRecord->getId() ]
133 );
134 if ( $revRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
135 $class = Linker::getRevisionDeletedClass( $revRecord );
136 $pageLink = '<span class=" ' . $class . '">' . $pageLink . '</span>';
137 }
138
139 # Last link
140 if ( !$revRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
141 $last = $this->msg( 'last' )->escaped();
142 } elseif ( isset( $this->prevId[$row->rev_id] ) ) {
143 $last = $linkRenderer->makeKnownLink(
144 $revRecord->getPageAsLinkTarget(),
145 $this->msg( 'last' )->text(),
146 [],
147 [
148 'diff' => $row->rev_id,
149 'oldid' => $this->prevId[$row->rev_id]
150 ]
151 );
152 }
153
154 $userLink = Linker::revUserTools( $revRecord );
155
156 $size = $row->rev_len;
157 if ( $size !== null ) {
158 $stxt = Linker::formatRevisionSize( $size );
159 }
160 $comment = $this->commentFormatter->formatRevision( $revRecord, $user );
161
162 // Tags, if any.
163 [ $tagSummary, $classes ] = $this->changeTagsFormatter->formatTagsAsSummaryList(
164 $row->ts_tags,
165 $this->getContext(),
166 $this->getAuthority()
167 );
168
169 return Html::rawElement( 'li', $classes,
170 $this->msg( 'mergehistory-revisionrow' )
171 ->rawParams( $cbs, $last, $pageLink, $userLink, $stxt, $comment, $tagSummary )->escaped() );
172 }
173
175 public function getQueryInfo() {
176 $dbr = $this->getDatabase();
177 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $dbr )
178 ->joinComment()
179 ->joinPage()
180 ->joinUser()
181 ->where( $this->mConds )
182 ->andWhere( [
183 'rev_page' => $this->articleID,
184 ] );
185 $this->changeTagsStore
186 ->addTagsToDisplayQuery( $queryBuilder, 'revision', $this->getAuthority() );
187
188 return $queryBuilder->getQueryInfo( 'join_conds' );
189 }
190
192 public function getIndexField() {
193 return [ [ 'rev_timestamp', 'rev_id' ] ];
194 }
195}
196
197// @codeCoverageIgnoreStart
202class_alias( MergeHistoryPager::class, 'MergeHistoryPager' );
203
205class_alias( MergeHistoryPager::class, 'MediaWiki\\Pager\\MergeHistoryPager' );
206// @codeCoverageIgnoreEnd
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
Formats change tags for display in HTML and use filter dropdown menus.
Read-write access to the change_tags table.
This is the main service interface for converting single-line comments from various DB comment fields...
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition Linker.php:48
Factory for LinkBatch objects to batch query page metadata.
getDatabase()
Get the Database object in use.
IndexPager with a formatted navigation bar.
Page revision base class.
Service for looking up page revisions.
doBatchLookups()
Called from getBody(), before getStartBody() is called and after doQuery() was called....
__construct(IContextSource $context, LinkRenderer $linkRenderer, private readonly LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, private readonly RevisionStore $revisionStore, private readonly CommentFormatter $commentFormatter, private readonly ChangeTagsStore $changeTagsStore, private readonly ChangeTagsFormatter $changeTagsFormatter, public array $mConds, PageIdentity $source, PageIdentity $dest, private readonly string $mergePointTimestamp, private readonly string $mergePointTimestampOld,)
getStartBody()
Hook into getBody(), allows text to be inserted at the start.This will be called even if there are no...
getQueryInfo()
Provides all parameters needed for the main paged query.It returns an associative array with the foll...
getIndexField()
Returns the name of the index field.If the pager supports multiple orders, it may return an array of ...
formatRow( $row)
Returns an HTML string representing the result row $row.Rows will be concatenated and returned by get...
getEndBody()
Hook into getBody() for the end of the list.to overridestring
Value object representing a user's identity.
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing an editable wiki page.
Provide primary and replica IDatabase connections.
getReplicaDatabase(string|false $domain=false, $group=null)
Get connection to a replica database.
$source