42 private $linkRenderer;
62 $this->context = $context;
63 $this->messages = $messages;
64 $this->linkRenderer = $linkRenderer;
76 $user = $this->context->getUser();
81 $cacheEntry->unpatrolled = ChangesList::isUnpatrolled( $baseRC, $user );
83 $cacheEntry->watched = $cacheEntry->mAttribs[
'rc_type'] ==
RC_LOG ? false : $watched;
84 $cacheEntry->numberofWatchingusers = $baseRC->numberofWatchingusers;
85 $cacheEntry->watchlistExpiry = $baseRC->watchlistExpiry;
87 $cacheEntry->link = $this->buildCLink( $cacheEntry );
88 $cacheEntry->timestamp = $this->buildTimestamp( $cacheEntry );
92 $showDiffLinks = $this->showDiffLinks( $cacheEntry, $user );
94 $cacheEntry->difflink = $this->buildDiffLink( $cacheEntry, $showDiffLinks );
95 $cacheEntry->curlink = $this->buildCurLink( $cacheEntry, $showDiffLinks );
96 $cacheEntry->lastlink = $this->buildLastLink( $cacheEntry, $showDiffLinks );
99 $cacheEntry->userlink = $this->getUserLink( $cacheEntry );
101 if ( !ChangesList::isDeleted( $cacheEntry, RevisionRecord::DELETED_USER ) ) {
108 $cacheEntry->usertalklink = $this->toolLinkCache->getWithSetCallback(
109 $this->toolLinkCache->makeKey(
110 $cacheEntry->mAttribs[
'rc_user_text'],
111 $this->context->getUser()->getName(),
112 $this->context->getLanguage()->getCode()
114 static fn () => Linker::userToolLinks(
115 $cacheEntry->mAttribs[
'rc_user'],
116 $cacheEntry->mAttribs[
'rc_user_text'],
139 return ChangesList::userCan( $cacheEntry, RevisionRecord::DELETED_TEXT, $performer );
147 private function buildCLink(
RCCacheEntry $cacheEntry ) {
148 $type = $cacheEntry->mAttribs[
'rc_type'];
152 $logType = $cacheEntry->mAttribs[
'rc_log_type'];
155 $clink = $this->getLogLink( $logType );
157 wfDebugLog(
'recentchanges',
'Unexpected log entry with no log type in recent changes' );
158 $clink = $this->linkRenderer->makeLink( $cacheEntry->
getTitle() );
161 } elseif ( $cacheEntry->mAttribs[
'rc_namespace'] ==
NS_SPECIAL ) {
162 wfDebugLog(
'recentchanges',
'Unexpected special page in recentchanges' );
166 $clink = $this->linkRenderer->makeKnownLink( $cacheEntry->
getTitle() );
172 private function getLogLink( $logType ) {
173 $logtitle = SpecialPage::getTitleFor(
'Log', $logType );
174 $logpage =
new LogPage( $logType );
175 $logname = $logpage->getName()->text();
177 $logLink = $this->context->msg(
'parentheses' )
179 $this->linkRenderer->makeKnownLink( $logtitle, $logname )
190 private function buildTimestamp(
RecentChange $cacheEntry ) {
191 return $this->context->getLanguage()->userTime(
192 $cacheEntry->mAttribs[
'rc_timestamp'],
193 $this->context->getUser()
202 private function buildCurQueryParams(
RecentChange $recentChange ) {
204 'curid' => $recentChange->mAttribs[
'rc_cur_id'],
206 'oldid' => $recentChange->mAttribs[
'rc_this_oldid']
216 private function buildCurLink(
RecentChange $cacheEntry, $showDiffLinks ) {
217 $curMessage = $this->getMessage(
'cur' );
219 if ( $cacheEntry->mAttribs[
'rc_this_oldid'] == $cacheEntry->
getAttribute(
'page_latest' ) ) {
220 $showDiffLinks =
false;
223 if ( !$showDiffLinks || in_array( $cacheEntry->mAttribs[
'rc_type'], $logTypes ) ) {
224 $curLink = $curMessage;
226 $queryParams = $this->buildCurQueryParams( $cacheEntry );
227 $curUrl = htmlspecialchars( $cacheEntry->
getTitle()->getLinkURL( $queryParams ) );
228 $curLink =
"<a class=\"mw-changeslist-diff-cur\" href=\"$curUrl\">$curMessage</a>";
239 private function buildDiffQueryParams(
RecentChange $recentChange ) {
241 'curid' => $recentChange->mAttribs[
'rc_cur_id'],
242 'diff' => $recentChange->mAttribs[
'rc_this_oldid'],
243 'oldid' => $recentChange->mAttribs[
'rc_last_oldid']
253 private function buildDiffLink(
RecentChange $cacheEntry, $showDiffLinks ) {
254 $queryParams = $this->buildDiffQueryParams( $cacheEntry );
255 $diffMessage = $this->getMessage(
'diff' );
258 if ( !$showDiffLinks ) {
259 $diffLink = $diffMessage;
260 } elseif ( in_array( $cacheEntry->mAttribs[
'rc_type'], $logTypes ) ) {
261 $diffLink = $diffMessage;
264 $pageTitle = Title::newFromID( $rcCurId );
265 if ( $pageTitle ===
null ) {
266 wfDebugLog(
'RCCacheEntryFactory',
'Could not get Title for rc_cur_id: ' . $rcCurId );
269 $diffUrl = htmlspecialchars( $pageTitle->getLinkURL( $queryParams ) );
270 $diffLink =
"<a class=\"mw-changeslist-diff\" href=\"$diffUrl\">$diffMessage</a>";
272 $diffUrl = htmlspecialchars( $cacheEntry->
getTitle()->getLinkURL( $queryParams ) );
273 $diffLink =
"<a class=\"mw-changeslist-diff\" href=\"$diffUrl\">$diffMessage</a>";
287 private function buildLastLink(
RecentChange $cacheEntry, $showDiffLinks ) {
288 $lastOldid = $cacheEntry->mAttribs[
'rc_last_oldid'];
289 $lastMessage = $this->getMessage(
'last' );
290 $type = $cacheEntry->mAttribs[
'rc_type'];
294 if ( !$showDiffLinks || !$lastOldid || in_array( $type, $logTypes ) ) {
295 $lastLink = $lastMessage;
297 $lastLink = $this->linkRenderer->makeKnownLink(
300 [
'class' =>
'mw-changeslist-diff' ],
301 $this->buildDiffQueryParams( $cacheEntry )
313 private function getUserLink(
RecentChange $cacheEntry ) {
314 if ( ChangesList::isDeleted( $cacheEntry, RevisionRecord::DELETED_USER ) ) {
315 $deletedClass =
'history-deleted';
316 if ( ChangesList::isDeleted( $cacheEntry, RevisionRecord::DELETED_RESTRICTED ) ) {
317 $deletedClass .=
' mw-history-suppressed';
319 $userLink =
' <span class="' . $deletedClass .
'">' .
320 $this->context->msg(
'rev-deleted-user' )->escaped() .
'</span>';
327 $userLink = $this->userLinkCache->getWithSetCallback(
328 $this->userLinkCache->makeKey(
329 $cacheEntry->mAttribs[
'rc_user_text'],
330 $this->context->getUser()->getName(),
331 $this->context->getLanguage()->getCode()
333 static fn () => Linker::userLink(
334 $cacheEntry->mAttribs[
'rc_user'],
335 $cacheEntry->mAttribs[
'rc_user_text'],
336 ExternalUserNames::getLocal( $cacheEntry->mAttribs[
'rc_user_text'] )
349 private function getMessage( $key ) {
350 return $this->messages[$key];
Class to simplify the use of log pages.
newFromRecentChange(RecentChange $baseRC, $watched)
__construct(IContextSource $context, $messages, LinkRenderer $linkRenderer)
static newFromParent( $rc)
Interface for objects which can provide a MediaWiki context on request.