MediaWiki  1.23.2
RCCacheEntryFactory.php
Go to the documentation of this file.
1 <?php
24 
25  /* @var IContextSource */
26  private $context;
27 
28  /* @var string[] */
29  private $messages;
30 
35  public function __construct( IContextSource $context, $messages ) {
36  $this->context = $context;
37  $this->messages = $messages;
38  }
39 
46  public function newFromRecentChange( RecentChange $baseRC, $watched ) {
47  $user = $this->context->getUser();
48  $counter = $baseRC->counter;
49 
50  $cacheEntry = RCCacheEntry::newFromParent( $baseRC );
51 
52  // Should patrol-related stuff be shown?
53  $cacheEntry->unpatrolled = ChangesList::isUnpatrolled( $baseRC, $user );
54 
55  $cacheEntry->watched = $cacheEntry->mAttribs['rc_type'] == RC_LOG ? false : $watched;
56  $cacheEntry->numberofWatchingusers = $baseRC->numberofWatchingusers;
57 
58  $cacheEntry->link = $this->buildCLink( $cacheEntry );
59  $cacheEntry->timestamp = $this->buildTimestamp( $cacheEntry );
60 
61  // Make "cur" and "diff" links. Do not use link(), it is too slow if
62  // called too many times (50% of CPU time on RecentChanges!).
63  $showDiffLinks = $this->showDiffLinks( $cacheEntry, $user );
64 
65  $cacheEntry->difflink = $this->buildDiffLink( $cacheEntry, $showDiffLinks, $counter );
66  $cacheEntry->curlink = $this->buildCurLink( $cacheEntry, $showDiffLinks, $counter );
67  $cacheEntry->lastlink = $this->buildLastLink( $cacheEntry, $showDiffLinks );
68 
69  // Make user links
70  $cacheEntry->userlink = $this->getUserLink( $cacheEntry );
71 
72  if ( !ChangesList::isDeleted( $cacheEntry, Revision::DELETED_USER ) ) {
73  $cacheEntry->usertalklink = Linker::userToolLinks(
74  $cacheEntry->mAttribs['rc_user'],
75  $cacheEntry->mAttribs['rc_user_text']
76  );
77  }
78 
79  return $cacheEntry;
80  }
81 
88  private function showDiffLinks( RecentChange $cacheEntry, User $user ) {
89  return ChangesList::userCan( $cacheEntry, Revision::DELETED_TEXT, $user );
90  }
91 
97  private function buildCLink( RecentChange $cacheEntry ) {
98  $type = $cacheEntry->mAttribs['rc_type'];
99 
100  // Page moves, very old style, not supported anymore
101  if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
102  $clink = '';
103  // New unpatrolled pages
104  } elseif ( $cacheEntry->unpatrolled && $type == RC_NEW ) {
105  $clink = Linker::linkKnown( $cacheEntry->getTitle() );
106  // Log entries
107  } elseif ( $type == RC_LOG ) {
108  $logType = $cacheEntry->mAttribs['rc_log_type'];
109 
110  if ( $logType ) {
111  $clink = $this->getLogLink( $logType );
112  } else {
113  wfDebugLog( 'recentchanges', 'Unexpected log entry with no log type in recent changes' );
114  $clink = Linker::link( $cacheEntry->getTitle() );
115  }
116  // Log entries (old format) and special pages
117  } elseif ( $cacheEntry->mAttribs['rc_namespace'] == NS_SPECIAL ) {
118  wfDebugLog( 'recentchanges', 'Unexpected special page in recentchanges' );
119  $clink = '';
120  // Edits
121  } else {
122  $clink = Linker::linkKnown( $cacheEntry->getTitle() );
123  }
124 
125  return $clink;
126  }
127 
128  private function getLogLink( $logType ) {
129  $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
130  $logpage = new LogPage( $logType );
131  $logname = $logpage->getName()->escaped();
132 
133  $logLink = $this->context->msg( 'parentheses' )
134  ->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped();
135 
136  return $logLink;
137  }
138 
144  private function buildTimestamp( RecentChange $cacheEntry ) {
145  return $this->context->getLanguage()->userTime(
146  $cacheEntry->mAttribs['rc_timestamp'],
147  $this->context->getUser()
148  );
149  }
150 
156  private function buildCurQueryParams( RecentChange $recentChange ) {
157  return array(
158  'curid' => $recentChange->mAttribs['rc_cur_id'],
159  'diff' => 0,
160  'oldid' => $recentChange->mAttribs['rc_this_oldid']
161  );
162  }
163 
171  private function buildCurLink( RecentChange $cacheEntry, $showDiffLinks, $counter ) {
172  $queryParams = $this->buildCurQueryParams( $cacheEntry );
173  $curMessage = $this->getMessage( 'cur' );
174  $logTypes = array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT );
175 
176  if ( !$showDiffLinks || in_array( $cacheEntry->mAttribs['rc_type'], $logTypes ) ) {
177  $curLink = $curMessage;
178  } else {
179  $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $queryParams ) );
180  $curLink = "<a href=\"$curUrl\" tabindex=\"$counter\">$curMessage</a>";
181  }
182 
183  return $curLink;
184  }
185 
191  private function buildDiffQueryParams( RecentChange $recentChange ) {
192  return array(
193  'curid' => $recentChange->mAttribs['rc_cur_id'],
194  'diff' => $recentChange->mAttribs['rc_this_oldid'],
195  'oldid' => $recentChange->mAttribs['rc_last_oldid']
196  );
197  }
198 
206  private function buildDiffLink( RecentChange $cacheEntry, $showDiffLinks, $counter ) {
207  $queryParams = $this->buildDiffQueryParams( $cacheEntry );
208  $diffMessage = $this->getMessage( 'diff' );
209  $logTypes = array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT );
210 
211  if ( !$showDiffLinks ) {
212  $diffLink = $diffMessage;
213  } elseif ( in_array( $cacheEntry->mAttribs['rc_type'], $logTypes ) ) {
214  $diffLink = $diffMessage;
215  } else {
216  $diffUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $queryParams ) );
217  $diffLink = "<a href=\"$diffUrl\" tabindex=\"$counter\">$diffMessage</a>";
218  }
219 
220  return $diffLink;
221  }
222 
229  private function buildLastLink( RecentChange $cacheEntry, $showDiffLinks ) {
230  $lastOldid = $cacheEntry->mAttribs['rc_last_oldid'];
231  $lastMessage = $this->getMessage( 'last' );
232  $type = $cacheEntry->mAttribs['rc_type'];
233  $logTypes = array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT );
234 
235  // Make "last" link
236  if ( !$showDiffLinks || !$lastOldid || in_array( $type, $logTypes ) ) {
237  $lastLink = $lastMessage;
238  } else {
239  $lastLink = Linker::linkKnown(
240  $cacheEntry->getTitle(),
241  $lastMessage,
242  array(),
243  $this->buildDiffQueryParams( $cacheEntry )
244  );
245  }
246 
247  return $lastLink;
248  }
249 
255  private function getUserLink( RecentChange $cacheEntry ) {
256  if ( ChangesList::isDeleted( $cacheEntry, Revision::DELETED_USER ) ) {
257  $userLink = ' <span class="history-deleted">' .
258  $this->context->msg( 'rev-deleted-user' )->escaped() . '</span>';
259  } else {
260  $userLink = Linker::userLink(
261  $cacheEntry->mAttribs['rc_user'],
262  $cacheEntry->mAttribs['rc_user_text']
263  );
264  }
265 
266  return $userLink;
267  }
268 
274  private function getMessage( $key ) {
275  return $this->messages[$key];
276  }
277 
278 }
Revision\DELETED_USER
const DELETED_USER
Definition: Revision.php:67
RCCacheEntryFactory\showDiffLinks
showDiffLinks(RecentChange $cacheEntry, User $user)
Definition: RCCacheEntryFactory.php:86
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Linker\userLink
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:1072
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:63
RC_MOVE_OVER_REDIRECT
const RC_MOVE_OVER_REDIRECT
Definition: Defines.php:182
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1040
RC_LOG
const RC_LOG
Definition: Defines.php:181
RC_MOVE
const RC_MOVE
Definition: Defines.php:180
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
RCCacheEntryFactory
Definition: RCCacheEntryFactory.php:23
RCCacheEntryFactory\getLogLink
getLogLink( $logType)
Definition: RCCacheEntryFactory.php:126
messages
namespace and then decline to actually register it RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok in case the handler function wants to provide a converted Content object Note that $result getContentModel() must return $toModel. Handler functions that modify $result should generally return false to further attempts at conversion. 'ContribsPager you ll need to handle error messages
Definition: hooks.txt:896
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=array(), $query=array(), $options=array( 'known', 'noclasses'))
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
ChangesList\isDeleted
static isDeleted( $rc, $field)
Determine if said field of a revision is hidden.
Definition: ChangesList.php:482
RCCacheEntryFactory\buildDiffQueryParams
buildDiffQueryParams(RecentChange $recentChange)
Definition: RCCacheEntryFactory.php:189
Linker\link
static link( $target, $html=null, $customAttribs=array(), $query=array(), $options=array())
This function returns an HTML link to the given target.
Definition: Linker.php:192
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:68
RCCacheEntry\newFromParent
static newFromParent( $rc)
Definition: RCCacheEntry.php:36
RCCacheEntryFactory\buildCLink
buildCLink(RecentChange $cacheEntry)
Definition: RCCacheEntryFactory.php:95
LogPage
Class to simplify the use of log pages.
Definition: LogPage.php:32
RCCacheEntryFactory\getUserLink
getUserLink(RecentChange $cacheEntry)
Definition: RCCacheEntryFactory.php:253
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
RCCacheEntryFactory\__construct
__construct(IContextSource $context, $messages)
Definition: RCCacheEntryFactory.php:33
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
RCCacheEntryFactory\buildCurLink
buildCurLink(RecentChange $cacheEntry, $showDiffLinks, $counter)
Definition: RCCacheEntryFactory.php:169
RCCacheEntryFactory\buildDiffLink
buildDiffLink(RecentChange $cacheEntry, $showDiffLinks, $counter)
Definition: RCCacheEntryFactory.php:204
Linker\userToolLinks
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:1100
RCCacheEntryFactory\buildTimestamp
buildTimestamp(RecentChange $cacheEntry)
Definition: RCCacheEntryFactory.php:142
RC_NEW
const RC_NEW
Definition: Defines.php:179
RCCacheEntryFactory\$context
IContextSource $context
Definition: RCCacheEntryFactory.php:25
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
IContextSource
Interface for objects which can provide a context on request.
Definition: IContextSource.php:29
RCCacheEntryFactory\$messages
string[] $messages
Definition: RCCacheEntryFactory.php:27
RCCacheEntryFactory\buildCurQueryParams
buildCurQueryParams(RecentChange $recentChange)
Definition: RCCacheEntryFactory.php:154
RCCacheEntryFactory\newFromRecentChange
newFromRecentChange(RecentChange $baseRC, $watched)
Definition: RCCacheEntryFactory.php:44
ChangesList\isUnpatrolled
static isUnpatrolled( $rc, User $user)
Definition: ChangesList.php:574
RecentChange\getTitle
& getTitle()
Definition: RecentChange.php:200
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
RCCacheEntryFactory\buildLastLink
buildLastLink(RecentChange $cacheEntry, $showDiffLinks)
Definition: RCCacheEntryFactory.php:227
Revision\DELETED_TEXT
const DELETED_TEXT
Definition: Revision.php:65
ChangesList\userCan
static userCan( $rc, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: ChangesList.php:494
RCCacheEntryFactory\getMessage
getMessage( $key)
Definition: RCCacheEntryFactory.php:272
$type
$type
Definition: testCompression.php:46