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