MediaWiki master
MergeHistoryPager.php
Go to the documentation of this file.
1<?php
9
10use MediaWiki\Cache\LinkBatchFactory;
24use Wikimedia\Timestamp\TimestampFormat as TS;
25
30
32 public $mGroupByDate = true;
33
34 public array $mConds;
35 private int $articleID;
36 private string $mergePointTimestamp;
37 private string $mergePointTimestampOld;
38
40 public array $prevId;
41
42 private LinkBatchFactory $linkBatchFactory;
43 private RevisionStore $revisionStore;
44 private CommentFormatter $commentFormatter;
45 private ChangeTagsStore $changeTagsStore;
46
47 public function __construct(
48 IContextSource $context,
49 LinkRenderer $linkRenderer,
50 LinkBatchFactory $linkBatchFactory,
51 IConnectionProvider $dbProvider,
52 RevisionStore $revisionStore,
53 CommentFormatter $commentFormatter,
54 ChangeTagsStore $changeTagsStore,
55 array $conds,
57 PageIdentity $dest,
58 string $mergePointTimestamp,
59 string $mergePointTimestampOld
60 ) {
61 $this->mConds = $conds;
62 $this->articleID = $source->getId();
63
64 $dbr = $dbProvider->getReplicaDatabase();
65 $this->mergePointTimestamp = $mergePointTimestamp;
66 $this->mergePointTimestampOld = $mergePointTimestampOld;
67
68 // Set database before parent constructor to avoid setting it there
69 $this->mDb = $dbr;
70 parent::__construct( $context, $linkRenderer );
71 $this->linkBatchFactory = $linkBatchFactory;
72 $this->revisionStore = $revisionStore;
73 $this->commentFormatter = $commentFormatter;
74 $this->changeTagsStore = $changeTagsStore;
75 }
76
78 protected function doBatchLookups() {
79 # Do a link batch query
80 $this->mResult->seek( 0 );
81 $batch = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
82 # Give some pointers to make (last) links
83 $this->prevId = [];
84 $rev_id = null;
85 foreach ( $this->mResult as $row ) {
86 $batch->addUser( new UserIdentityValue( (int)$row->rev_user, $row->rev_user_text ) );
87
88 if ( $rev_id !== null ) {
89 if ( $rev_id > $row->rev_id ) {
90 $this->prevId[$rev_id] = $row->rev_id;
91 } elseif ( $rev_id < $row->rev_id ) {
92 $this->prevId[$row->rev_id] = $rev_id;
93 }
94 }
95
96 $rev_id = $row->rev_id;
97 }
98
99 $batch->execute();
100 $this->mResult->seek( 0 );
101 }
102
106 protected function getStartBody() {
107 return "<section id='mw-mergehistory-list' class='mw-pager-body'>\n";
108 }
109
113 protected function getEndBody() {
114 return "</section>\n";
115 }
116
118 public function formatRow( $row ) {
119 $revRecord = $this->revisionStore->newRevisionFromRow( $row );
120
121 $linkRenderer = $this->getLinkRenderer();
122
123 $stxt = '';
124 $last = $this->msg( 'last' )->escaped();
125
126 $ts = wfTimestamp( TS::MW, $row->rev_timestamp );
127 $tsWithId = $ts . "|" . $row->rev_id;
128 $oldCheckBox = Html::radio(
129 'mergepointold',
130 $this->mergePointTimestampOld === $tsWithId,
131 [ 'value' => $tsWithId ]
132 );
133 $newCheckBox = Html::radio(
134 'mergepoint',
135 $this->mergePointTimestamp === $ts || $this->mergePointTimestamp === $tsWithId,
136 [ 'value' => $tsWithId ]
137 );
138 $cbs = $oldCheckBox . $newCheckBox;
139
140 $user = $this->getUser();
141
142 $pageLink = $linkRenderer->makeKnownLink(
143 $revRecord->getPageAsLinkTarget(),
144 $this->getLanguage()->userTimeAndDate( $ts, $user ),
145 [],
146 [ 'oldid' => $revRecord->getId() ]
147 );
148 if ( $revRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
149 $class = Linker::getRevisionDeletedClass( $revRecord );
150 $pageLink = '<span class=" ' . $class . '">' . $pageLink . '</span>';
151 }
152
153 # Last link
154 if ( !$revRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
155 $last = $this->msg( 'last' )->escaped();
156 } elseif ( isset( $this->prevId[$row->rev_id] ) ) {
157 $last = $linkRenderer->makeKnownLink(
158 $revRecord->getPageAsLinkTarget(),
159 $this->msg( 'last' )->text(),
160 [],
161 [
162 'diff' => $row->rev_id,
163 'oldid' => $this->prevId[$row->rev_id]
164 ]
165 );
166 }
167
168 $userLink = Linker::revUserTools( $revRecord );
169
170 $size = $row->rev_len;
171 if ( $size !== null ) {
172 $stxt = Linker::formatRevisionSize( $size );
173 }
174 $comment = $this->commentFormatter->formatRevision( $revRecord, $user );
175
176 // Tags, if any.
177 [ $tagSummary, $classes ] = ChangeTags::formatSummaryRow(
178 $row->ts_tags,
179 'mergehistory',
180 $this->getContext()
181 );
182
183 return Html::rawElement( 'li', $classes,
184 $this->msg( 'mergehistory-revisionrow' )
185 ->rawParams( $cbs, $last, $pageLink, $userLink, $stxt, $comment, $tagSummary )->escaped() );
186 }
187
189 public function getQueryInfo() {
190 $dbr = $this->getDatabase();
191 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $dbr )
192 ->joinComment()
193 ->joinPage()
194 ->joinUser()
195 ->where( $this->mConds )
196 ->andWhere( [
197 'rev_page' => $this->articleID,
198 ] );
199 $this->changeTagsStore->modifyDisplayQueryBuilder( $queryBuilder, 'revision' );
200
201 return $queryBuilder->getQueryInfo( 'join_conds' );
202 }
203
205 public function getIndexField() {
206 return [ [ 'rev_timestamp', 'rev_id' ] ];
207 }
208}
209
214class_alias( MergeHistoryPager::class, 'MergeHistoryPager' );
215
217class_alias( MergeHistoryPager::class, 'MediaWiki\\Pager\\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:43
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition Linker.php:47
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, LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, RevisionStore $revisionStore, CommentFormatter $commentFormatter, ChangeTagsStore $changeTagsStore, array $conds, PageIdentity $source, PageIdentity $dest, string $mergePointTimestamp, 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