MediaWiki master
MergeHistoryPager.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Pager;
23
24use ChangeTags;
37
42
43 public $mGroupByDate = true;
44
46 public $mConds;
47
49 private $articleID;
50
52 private $maxTimestamp;
53
55 private $maxRevId;
56
58 private $mergePointTimestamp;
59
61 public $prevId;
62
63 private LinkBatchFactory $linkBatchFactory;
64 private RevisionStore $revisionStore;
65 private CommentFormatter $commentFormatter;
66
79 public function __construct(
80 IContextSource $context,
81 LinkRenderer $linkRenderer,
82 LinkBatchFactory $linkBatchFactory,
83 IConnectionProvider $dbProvider,
84 RevisionStore $revisionStore,
85 CommentFormatter $commentFormatter,
86 $conds,
88 PageIdentity $dest,
89 $mergePointTimestamp
90 ) {
91 $this->mConds = $conds;
92 $this->articleID = $source->getId();
93
94 $dbr = $dbProvider->getReplicaDatabase();
95 $maxtimestamp = $dbr->newSelectQueryBuilder()
96 ->select( 'MIN(rev_timestamp)' )
97 ->from( 'revision' )
98 ->where( [ 'rev_page' => $dest->getId() ] )
99 ->caller( __METHOD__ )->fetchField();
100 $maxRevId = $dbr->newSelectQueryBuilder()
101 ->select( "MIN(rev_id)" )
102 ->from( 'revision' )
103 ->where( [ 'rev_page' => $dest->getId() ] )
104 ->where( [ 'rev_timestamp' => $maxtimestamp ] )
105 ->caller( __METHOD__ )->fetchField();
106 $this->maxTimestamp = $maxtimestamp;
107 $this->maxRevId = $maxRevId;
108 $this->mergePointTimestamp = $mergePointTimestamp;
109
110 // Set database before parent constructor to avoid setting it there
111 $this->mDb = $dbr;
112 parent::__construct( $context, $linkRenderer );
113 $this->linkBatchFactory = $linkBatchFactory;
114 $this->revisionStore = $revisionStore;
115 $this->commentFormatter = $commentFormatter;
116 }
117
118 protected function doBatchLookups() {
119 # Do a link batch query
120 $this->mResult->seek( 0 );
121 $batch = $this->linkBatchFactory->newLinkBatch();
122 # Give some pointers to make (last) links
123 $this->prevId = [];
124 $rev_id = null;
125 foreach ( $this->mResult as $row ) {
126 $batch->add( NS_USER, $row->rev_user_text );
127 $batch->add( NS_USER_TALK, $row->rev_user_text );
128
129 if ( isset( $rev_id ) ) {
130 if ( $rev_id > $row->rev_id ) {
131 $this->prevId[$rev_id] = $row->rev_id;
132 } elseif ( $rev_id < $row->rev_id ) {
133 $this->prevId[$row->rev_id] = $rev_id;
134 }
135 }
136
137 $rev_id = $row->rev_id;
138 }
139
140 $batch->execute();
141 $this->mResult->seek( 0 );
142 }
143
147 protected function getStartBody() {
148 return "<section class='mw-pager-body'>\n";
149 }
150
154 protected function getEndBody() {
155 return "</section>\n";
156 }
157
158 public function formatRow( $row ) {
159 $revRecord = $this->revisionStore->newRevisionFromRow( $row );
160
161 $linkRenderer = $this->getLinkRenderer();
162
163 $stxt = '';
164 $last = $this->msg( 'last' )->escaped();
165
166 $ts = wfTimestamp( TS_MW, $row->rev_timestamp );
167 $tsWithId = $ts . "|" . $row->rev_id;
168 $checkBox = Xml::radio(
169 'mergepoint', $tsWithId,
170 $this->mergePointTimestamp === $ts || $this->mergePointTimestamp === $tsWithId
171 );
172
173 $user = $this->getUser();
174
175 $pageLink = $linkRenderer->makeKnownLink(
176 $revRecord->getPageAsLinkTarget(),
177 $this->getLanguage()->userTimeAndDate( $ts, $user ),
178 [],
179 [ 'oldid' => $revRecord->getId() ]
180 );
181 if ( $revRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
182 $class = Linker::getRevisionDeletedClass( $revRecord );
183 $pageLink = '<span class=" ' . $class . '">' . $pageLink . '</span>';
184 }
185
186 # Last link
187 if ( !$revRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
188 $last = $this->msg( 'last' )->escaped();
189 } elseif ( isset( $this->prevId[$row->rev_id] ) ) {
190 $last = $linkRenderer->makeKnownLink(
191 $revRecord->getPageAsLinkTarget(),
192 $this->msg( 'last' )->text(),
193 [],
194 [
195 'diff' => $row->rev_id,
196 'oldid' => $this->prevId[$row->rev_id]
197 ]
198 );
199 }
200
201 $userLink = Linker::revUserTools( $revRecord );
202
203 $size = $row->rev_len;
204 if ( $size !== null ) {
205 $stxt = Linker::formatRevisionSize( $size );
206 }
207 $comment = $this->commentFormatter->formatRevision( $revRecord, $user );
208
209 // Tags, if any.
210 [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
211 $row->ts_tags,
212 'mergehistory',
213 $this->getContext()
214 );
215
216 return Html::rawElement( 'li', $classes,
217 $this->msg( 'mergehistory-revisionrow' )
218 ->rawParams( $checkBox, $last, $pageLink, $userLink, $stxt, $comment, $tagSummary )->escaped() );
219 }
220
221 public function getQueryInfo() {
222 $dbr = $this->getDatabase();
223 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $dbr )
224 ->joinComment()
225 ->joinPage()
226 ->joinUser()
227 ->where( $this->mConds )
228 ->andWhere( [
229 'rev_page' => $this->articleID,
230 $dbr->buildComparison( "<",
231 [
232 "rev_timestamp" => $this->maxTimestamp,
233 "rev_id" => $this->maxRevId
234 ]
235 )
236 ] );
237 MediaWikiServices::getInstance()->getChangeTagsStore()->modifyDisplayQueryBuilder( $queryBuilder, 'revision' );
238
239 return $queryBuilder->getQueryInfo( 'join_conds' );
240 }
241
242 public function getIndexField() {
243 return [ [ 'rev_timestamp', 'rev_id' ] ];
244 }
245}
246
251class_alias( MergeHistoryPager::class, 'MergeHistoryPager' );
const NS_USER
Definition Defines.php:67
const NS_USER_TALK
Definition Defines.php:68
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static formatSummaryRow( $tags, $unused, MessageLocalizer $localizer=null)
Creates HTML for the given tags.
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:56
static radio( $name, $checked=false, array $attribs=[])
Convenience function to produce a radio button (input element with type=radio)
Definition Html.php:799
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition Linker.php:63
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
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.
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
__construct(IContextSource $context, LinkRenderer $linkRenderer, LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, RevisionStore $revisionStore, CommentFormatter $commentFormatter, $conds, PageIdentity $source, PageIdentity $dest, $mergePointTimestamp)
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.
Module of static functions for generating XML.
Definition Xml.php:37
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