MediaWiki  1.27.1
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 
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  // New unpatrolled pages
101  if ( $cacheEntry->unpatrolled && $type == RC_NEW ) {
102  $clink = Linker::linkKnown( $cacheEntry->getTitle() );
103  // Log entries
104  } elseif ( $type == RC_LOG ) {
105  $logType = $cacheEntry->mAttribs['rc_log_type'];
106 
107  if ( $logType ) {
108  $clink = $this->getLogLink( $logType );
109  } else {
110  wfDebugLog( 'recentchanges', 'Unexpected log entry with no log type in recent changes' );
111  $clink = Linker::link( $cacheEntry->getTitle() );
112  }
113  // Log entries (old format) and special pages
114  } elseif ( $cacheEntry->mAttribs['rc_namespace'] == NS_SPECIAL ) {
115  wfDebugLog( 'recentchanges', 'Unexpected special page in recentchanges' );
116  $clink = '';
117  // Edits
118  } else {
119  $clink = Linker::linkKnown( $cacheEntry->getTitle() );
120  }
121 
122  return $clink;
123  }
124 
125  private function getLogLink( $logType ) {
126  $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
127  $logpage = new LogPage( $logType );
128  $logname = $logpage->getName()->escaped();
129 
130  $logLink = $this->context->msg( 'parentheses' )
131  ->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped();
132 
133  return $logLink;
134  }
135 
141  private function buildTimestamp( RecentChange $cacheEntry ) {
142  return $this->context->getLanguage()->userTime(
143  $cacheEntry->mAttribs['rc_timestamp'],
144  $this->context->getUser()
145  );
146  }
147 
153  private function buildCurQueryParams( RecentChange $recentChange ) {
154  return [
155  'curid' => $recentChange->mAttribs['rc_cur_id'],
156  'diff' => 0,
157  'oldid' => $recentChange->mAttribs['rc_this_oldid']
158  ];
159  }
160 
168  private function buildCurLink( RecentChange $cacheEntry, $showDiffLinks, $counter ) {
169  $queryParams = $this->buildCurQueryParams( $cacheEntry );
170  $curMessage = $this->getMessage( 'cur' );
171  $logTypes = [ RC_LOG ];
172 
173  if ( !$showDiffLinks || in_array( $cacheEntry->mAttribs['rc_type'], $logTypes ) ) {
174  $curLink = $curMessage;
175  } else {
176  $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $queryParams ) );
177  $curLink = "<a href=\"$curUrl\" tabindex=\"$counter\">$curMessage</a>";
178  }
179 
180  return $curLink;
181  }
182 
188  private function buildDiffQueryParams( RecentChange $recentChange ) {
189  return [
190  'curid' => $recentChange->mAttribs['rc_cur_id'],
191  'diff' => $recentChange->mAttribs['rc_this_oldid'],
192  'oldid' => $recentChange->mAttribs['rc_last_oldid']
193  ];
194  }
195 
203  private function buildDiffLink( RecentChange $cacheEntry, $showDiffLinks, $counter ) {
204  $queryParams = $this->buildDiffQueryParams( $cacheEntry );
205  $diffMessage = $this->getMessage( 'diff' );
206  $logTypes = [ RC_NEW, RC_LOG ];
207 
208  if ( !$showDiffLinks ) {
209  $diffLink = $diffMessage;
210  } elseif ( in_array( $cacheEntry->mAttribs['rc_type'], $logTypes ) ) {
211  $diffLink = $diffMessage;
212  } elseif ( $cacheEntry->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
213  $rcCurId = $cacheEntry->getAttribute( 'rc_cur_id' );
214  $pageTitle = Title::newFromID( $rcCurId );
215  if ( $pageTitle === null ) {
216  wfDebugLog( 'RCCacheEntryFactory', 'Could not get Title for rc_cur_id: ' . $rcCurId );
217  return $diffMessage;
218  }
219  $diffUrl = htmlspecialchars( $pageTitle->getLinkURL( $queryParams ) );
220  $diffLink = "<a href=\"$diffUrl\" tabindex=\"$counter\">$diffMessage</a>";
221  } else {
222  $diffUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $queryParams ) );
223  $diffLink = "<a href=\"$diffUrl\" tabindex=\"$counter\">$diffMessage</a>";
224  }
225 
226  return $diffLink;
227  }
228 
235  private function buildLastLink( RecentChange $cacheEntry, $showDiffLinks ) {
236  $lastOldid = $cacheEntry->mAttribs['rc_last_oldid'];
237  $lastMessage = $this->getMessage( 'last' );
238  $type = $cacheEntry->mAttribs['rc_type'];
239  $logTypes = [ RC_LOG ];
240 
241  // Make "last" link
242  if ( !$showDiffLinks || !$lastOldid || in_array( $type, $logTypes ) ) {
243  $lastLink = $lastMessage;
244  } else {
245  $lastLink = Linker::linkKnown(
246  $cacheEntry->getTitle(),
247  $lastMessage,
248  [],
249  $this->buildDiffQueryParams( $cacheEntry )
250  );
251  }
252 
253  return $lastLink;
254  }
255 
261  private function getUserLink( RecentChange $cacheEntry ) {
262  if ( ChangesList::isDeleted( $cacheEntry, Revision::DELETED_USER ) ) {
263  $userLink = ' <span class="history-deleted">' .
264  $this->context->msg( 'rev-deleted-user' )->escaped() . '</span>';
265  } else {
266  $userLink = Linker::userLink(
267  $cacheEntry->mAttribs['rc_user'],
268  $cacheEntry->mAttribs['rc_user_text']
269  );
270  }
271 
272  return $userLink;
273  }
274 
280  private function getMessage( $key ) {
281  return $this->messages[$key];
282  }
283 
284 }
static newFromID($id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:417
const RC_CATEGORIZE
Definition: Defines.php:173
Utility class for creating new RC entries.
Interface for objects which can provide a MediaWiki context on request.
static userCan($rc, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision, if it's marked as deleted.
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Definition: hooks.txt:2321
buildLastLink(RecentChange $cacheEntry, $showDiffLinks)
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:75
static isDeleted($rc, $field)
Determine if said field of a revision is hidden.
newFromRecentChange(RecentChange $baseRC, $watched)
buildDiffQueryParams(RecentChange $recentChange)
const NS_SPECIAL
Definition: Defines.php:58
buildCurLink(RecentChange $cacheEntry, $showDiffLinks, $counter)
static newFromParent($rc)
getAttribute($name)
Get an attribute value.
Class to simplify the use of log pages.
Definition: LogPage.php:32
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
buildDiffLink(RecentChange $cacheEntry, $showDiffLinks, $counter)
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 local account $user
Definition: hooks.txt:242
static link($target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:195
const DELETED_TEXT
Definition: Revision.php:76
static userLink($userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:1102
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace 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 inclusive false for true for descending in case the handler function wants to provide a converted Content object Note that $result getContentModel() must return $toModel. 'CustomEditor'you ll need to handle error messages
Definition: hooks.txt:1099
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
const DELETED_USER
Definition: Revision.php:78
buildCLink(RecentChange $cacheEntry)
__construct(IContextSource $context, $messages)
buildTimestamp(RecentChange $cacheEntry)
showDiffLinks(RecentChange $cacheEntry, User $user)
static userToolLinks($userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:1133
getUserLink(RecentChange $cacheEntry)
const RC_NEW
Definition: Defines.php:170
static isUnpatrolled($rc, User $user)
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2338
const RC_LOG
Definition: Defines.php:171
buildCurQueryParams(RecentChange $recentChange)