MediaWiki REL1_41
MergeHistoryPager.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Pager;
23
24use ChangeTags;
36use Xml;
37
42
43 public $mGroupByDate = true;
44
46 public $mConds;
47
49 private $articleID;
50
52 private $maxTimestamp;
53
55 private $mergePointTimestamp;
56
58 public $prevId;
59
60 private LinkBatchFactory $linkBatchFactory;
61 private RevisionStore $revisionStore;
62 private CommentFormatter $commentFormatter;
63
76 public function __construct(
77 IContextSource $context,
78 LinkRenderer $linkRenderer,
79 LinkBatchFactory $linkBatchFactory,
80 IConnectionProvider $dbProvider,
81 RevisionStore $revisionStore,
82 CommentFormatter $commentFormatter,
83 $conds,
85 PageIdentity $dest,
86 $mergePointTimestamp
87 ) {
88 $this->mConds = $conds;
89 $this->articleID = $source->getId();
90
91 $dbr = $dbProvider->getReplicaDatabase();
92 $maxtimestamp = $dbr->newSelectQueryBuilder()
93 ->select( 'MIN(rev_timestamp)' )
94 ->from( 'revision' )
95 ->where( [ 'rev_page' => $dest->getId() ] )
96 ->caller( __METHOD__ )->fetchField();
97 $this->maxTimestamp = $maxtimestamp;
98 $this->mergePointTimestamp = $mergePointTimestamp;
99
100 // Set database before parent constructor to avoid setting it there with wfGetDB
101 $this->mDb = $dbr;
102 parent::__construct( $context, $linkRenderer );
103 $this->linkBatchFactory = $linkBatchFactory;
104 $this->revisionStore = $revisionStore;
105 $this->commentFormatter = $commentFormatter;
106 }
107
108 protected function doBatchLookups() {
109 # Do a link batch query
110 $this->mResult->seek( 0 );
111 $batch = $this->linkBatchFactory->newLinkBatch();
112 # Give some pointers to make (last) links
113 $this->prevId = [];
114 $rev_id = null;
115 foreach ( $this->mResult as $row ) {
116 $batch->add( NS_USER, $row->rev_user_text );
117 $batch->add( NS_USER_TALK, $row->rev_user_text );
118
119 if ( isset( $rev_id ) ) {
120 if ( $rev_id > $row->rev_id ) {
121 $this->prevId[$rev_id] = $row->rev_id;
122 } elseif ( $rev_id < $row->rev_id ) {
123 $this->prevId[$row->rev_id] = $rev_id;
124 }
125 }
126
127 $rev_id = $row->rev_id;
128 }
129
130 $batch->execute();
131 $this->mResult->seek( 0 );
132 }
133
137 protected function getStartBody() {
138 return "<section class='mw-pager-body'>\n";
139 }
140
144 protected function getEndBody() {
145 return "</section>\n";
146 }
147
148 public function formatRow( $row ) {
149 $revRecord = $this->revisionStore->newRevisionFromRow( $row );
150
151 $linkRenderer = $this->getLinkRenderer();
152
153 $stxt = '';
154 $last = $this->msg( 'last' )->escaped();
155
156 $ts = wfTimestamp( TS_MW, $row->rev_timestamp );
157 $checkBox = Xml::radio( 'mergepoint', $ts, ( $this->mergePointTimestamp === $ts ) );
158
159 $user = $this->getUser();
160
161 $pageLink = $linkRenderer->makeKnownLink(
162 $revRecord->getPageAsLinkTarget(),
163 $this->getLanguage()->userTimeAndDate( $ts, $user ),
164 [],
165 [ 'oldid' => $revRecord->getId() ]
166 );
167 if ( $revRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
168 $class = Linker::getRevisionDeletedClass( $revRecord );
169 $pageLink = '<span class=" ' . $class . '">' . $pageLink . '</span>';
170 }
171
172 # Last link
173 if ( !$revRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
174 $last = $this->msg( 'last' )->escaped();
175 } elseif ( isset( $this->prevId[$row->rev_id] ) ) {
176 $last = $linkRenderer->makeKnownLink(
177 $revRecord->getPageAsLinkTarget(),
178 $this->msg( 'last' )->text(),
179 [],
180 [
181 'diff' => $row->rev_id,
182 'oldid' => $this->prevId[$row->rev_id]
183 ]
184 );
185 }
186
187 $userLink = Linker::revUserTools( $revRecord );
188
189 $size = $row->rev_len;
190 if ( $size !== null ) {
191 $stxt = Linker::formatRevisionSize( $size );
192 }
193 $comment = $this->commentFormatter->formatRevision( $revRecord, $user );
194
195 // Tags, if any.
196 [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
197 $row->ts_tags,
198 'mergehistory',
199 $this->getContext()
200 );
201
202 return Html::rawElement( 'li', $classes,
203 $this->msg( 'mergehistory-revisionrow' )
204 ->rawParams( $checkBox, $last, $pageLink, $userLink, $stxt, $comment, $tagSummary )->escaped() );
205 }
206
207 public function getQueryInfo() {
208 $dbr = $this->getDatabase();
209 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $dbr )
210 ->joinComment()
211 ->joinPage()
212 ->joinUser()
213 ->where( $this->mConds )
214 ->andWhere( [
215 'rev_page' => $this->articleID,
216 "rev_timestamp < " . $dbr->addQuotes( $this->maxTimestamp )
217 ] );
218 MediaWikiServices::getInstance()->getChangeTagsStore()->modifyDisplayQueryBuilder( $queryBuilder, 'revision' );
219
220 return $queryBuilder->getQueryInfo( 'join_conds' );
221 }
222
223 public function getIndexField() {
224 return [ [ 'rev_timestamp', 'rev_id' ] ];
225 }
226}
227
232class_alias( MergeHistoryPager::class, 'MergeHistoryPager' );
const NS_USER
Definition Defines.php:66
const NS_USER_TALK
Definition Defines.php:67
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.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
This is the main service interface for converting single-line comments from various DB comment fields...
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:65
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:33
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