MediaWiki master
MergeHistoryPager.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Pager;
23
37
42
44 public $mGroupByDate = true;
45
46 public array $mConds;
47 private int $articleID;
48 private string $maxTimestamp;
49 private int $maxRevId;
50 private string $mergePointTimestamp;
51
53 public array $prevId;
54
55 private LinkBatchFactory $linkBatchFactory;
56 private RevisionStore $revisionStore;
57 private CommentFormatter $commentFormatter;
58 private ChangeTagsStore $changeTagsStore;
59
60 public function __construct(
61 IContextSource $context,
62 LinkRenderer $linkRenderer,
63 LinkBatchFactory $linkBatchFactory,
64 IConnectionProvider $dbProvider,
65 RevisionStore $revisionStore,
66 CommentFormatter $commentFormatter,
67 ChangeTagsStore $changeTagsStore,
68 array $conds,
70 PageIdentity $dest,
71 string $mergePointTimestamp
72 ) {
73 $this->mConds = $conds;
74 $this->articleID = $source->getId();
75
76 $dbr = $dbProvider->getReplicaDatabase();
77 $maxtimestamp = $dbr->newSelectQueryBuilder()
78 ->select( 'MIN(rev_timestamp)' )
79 ->from( 'revision' )
80 ->where( [ 'rev_page' => $dest->getId() ] )
81 ->caller( __METHOD__ )->fetchField();
82 $maxRevId = $dbr->newSelectQueryBuilder()
83 ->select( "MIN(rev_id)" )
84 ->from( 'revision' )
85 ->where( [ 'rev_page' => $dest->getId() ] )
86 ->where( [ 'rev_timestamp' => $maxtimestamp ] )
87 ->caller( __METHOD__ )->fetchField();
88 $this->maxTimestamp = $maxtimestamp;
89 $this->maxRevId = (int)$maxRevId;
90 $this->mergePointTimestamp = $mergePointTimestamp;
91
92 // Set database before parent constructor to avoid setting it there
93 $this->mDb = $dbr;
94 parent::__construct( $context, $linkRenderer );
95 $this->linkBatchFactory = $linkBatchFactory;
96 $this->revisionStore = $revisionStore;
97 $this->commentFormatter = $commentFormatter;
98 $this->changeTagsStore = $changeTagsStore;
99 }
100
101 protected function doBatchLookups() {
102 # Do a link batch query
103 $this->mResult->seek( 0 );
104 $batch = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
105 # Give some pointers to make (last) links
106 $this->prevId = [];
107 $rev_id = null;
108 foreach ( $this->mResult as $row ) {
109 $batch->addUser( new UserIdentityValue( (int)$row->rev_user, $row->rev_user_text ) );
110
111 if ( $rev_id !== null ) {
112 if ( $rev_id > $row->rev_id ) {
113 $this->prevId[$rev_id] = $row->rev_id;
114 } elseif ( $rev_id < $row->rev_id ) {
115 $this->prevId[$row->rev_id] = $rev_id;
116 }
117 }
118
119 $rev_id = $row->rev_id;
120 }
121
122 $batch->execute();
123 $this->mResult->seek( 0 );
124 }
125
129 protected function getStartBody() {
130 return "<section class='mw-pager-body'>\n";
131 }
132
136 protected function getEndBody() {
137 return "</section>\n";
138 }
139
140 public function formatRow( $row ) {
141 $revRecord = $this->revisionStore->newRevisionFromRow( $row );
142
143 $linkRenderer = $this->getLinkRenderer();
144
145 $stxt = '';
146 $last = $this->msg( 'last' )->escaped();
147
148 $ts = wfTimestamp( TS_MW, $row->rev_timestamp );
149 $tsWithId = $ts . "|" . $row->rev_id;
150 $checkBox = Html::radio(
151 'mergepoint',
152 $this->mergePointTimestamp === $ts || $this->mergePointTimestamp === $tsWithId,
153 [ 'value' => $tsWithId ]
154 );
155
156 $user = $this->getUser();
157
158 $pageLink = $linkRenderer->makeKnownLink(
159 $revRecord->getPageAsLinkTarget(),
160 $this->getLanguage()->userTimeAndDate( $ts, $user ),
161 [],
162 [ 'oldid' => $revRecord->getId() ]
163 );
164 if ( $revRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
165 $class = Linker::getRevisionDeletedClass( $revRecord );
166 $pageLink = '<span class=" ' . $class . '">' . $pageLink . '</span>';
167 }
168
169 # Last link
170 if ( !$revRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
171 $last = $this->msg( 'last' )->escaped();
172 } elseif ( isset( $this->prevId[$row->rev_id] ) ) {
173 $last = $linkRenderer->makeKnownLink(
174 $revRecord->getPageAsLinkTarget(),
175 $this->msg( 'last' )->text(),
176 [],
177 [
178 'diff' => $row->rev_id,
179 'oldid' => $this->prevId[$row->rev_id]
180 ]
181 );
182 }
183
184 $userLink = Linker::revUserTools( $revRecord );
185
186 $size = $row->rev_len;
187 if ( $size !== null ) {
188 $stxt = Linker::formatRevisionSize( $size );
189 }
190 $comment = $this->commentFormatter->formatRevision( $revRecord, $user );
191
192 // Tags, if any.
193 [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
194 $row->ts_tags,
195 'mergehistory',
196 $this->getContext()
197 );
198
199 return Html::rawElement( 'li', $classes,
200 $this->msg( 'mergehistory-revisionrow' )
201 ->rawParams( $checkBox, $last, $pageLink, $userLink, $stxt, $comment, $tagSummary )->escaped() );
202 }
203
204 public function getQueryInfo() {
205 $dbr = $this->getDatabase();
206 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $dbr )
207 ->joinComment()
208 ->joinPage()
209 ->joinUser()
210 ->where( $this->mConds )
211 ->andWhere( [
212 'rev_page' => $this->articleID,
213 $dbr->buildComparison( "<",
214 [
215 "rev_timestamp" => $this->maxTimestamp,
216 "rev_id" => $this->maxRevId
217 ]
218 )
219 ] );
220 $this->changeTagsStore->modifyDisplayQueryBuilder( $queryBuilder, 'revision' );
221
222 return $queryBuilder->getQueryInfo( 'join_conds' );
223 }
224
225 public function getIndexField() {
226 return [ [ 'rev_timestamp', 'rev_id' ] ];
227 }
228}
229
234class_alias( MergeHistoryPager::class, 'MergeHistoryPager' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Read-write access to the change_tags table.
Recent changes tagging.
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:57
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition Linker.php:61
getDatabase()
Get the Database object in use.
formatRow( $row)
Returns an HTML string representing the result row $row.
getQueryInfo()
Provides all parameters needed for the main paged query.
__construct(IContextSource $context, LinkRenderer $linkRenderer, LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, RevisionStore $revisionStore, CommentFormatter $commentFormatter, ChangeTagsStore $changeTagsStore, array $conds, PageIdentity $source, PageIdentity $dest, string $mergePointTimestamp)
doBatchLookups()
Called from getBody(), before getStartBody() is called and after doQuery() was called.
getEndBody()
Hook into getBody() for the end of the list.to overridestring
getIndexField()
Returns the name of the index field.
getStartBody()
Hook into getBody(), allows text to be inserted at the start.This will be called even if there are no...
IndexPager with a formatted navigation bar.
Page revision base class.
Service for looking up page revisions.
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.
getId( $wikiId=self::LOCAL)
Returns the page ID.
Provide primary and replica IDatabase connections.
getReplicaDatabase( $domain=false, $group=null)
Get connection to a replica database.
$source