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