* Tweaks from profiling
[lhc/web/wiklou.git] / includes / ChangesList.php
1 <?php
2
3 /**
4 * @todo document
5 */
6 class RCCacheEntry extends RecentChange {
7 var $secureName, $link;
8 var $curlink , $difflink, $lastlink, $usertalklink, $versionlink;
9 var $userlink, $timestamp, $watched;
10
11 static function newFromParent( $rc ) {
12 $rc2 = new RCCacheEntry;
13 $rc2->mAttribs = $rc->mAttribs;
14 $rc2->mExtra = $rc->mExtra;
15 return $rc2;
16 }
17 }
18
19 /**
20 * Class to show various lists of changes:
21 * - what links here
22 * - related changes
23 * - recent changes
24 */
25 class ChangesList {
26 # Called by history lists and recent changes
27 public $skin;
28
29 /**
30 * Changeslist contructor
31 * @param Skin $skin
32 */
33 public function __construct( &$skin ) {
34 $this->skin =& $skin;
35 $this->preCacheMessages();
36 }
37
38 /**
39 * Fetch an appropriate changes list class for the specified user
40 * Some users might want to use an enhanced list format, for instance
41 *
42 * @param $user User to fetch the list class for
43 * @return ChangesList derivative
44 */
45 public static function newFromUser( &$user ) {
46 $sk = $user->getSkin();
47 $list = NULL;
48 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
49 return $user->getOption( 'usenewrc' ) ?
50 new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
51 } else {
52 return $list;
53 }
54 }
55
56 /**
57 * As we use the same small set of messages in various methods and that
58 * they are called often, we call them once and save them in $this->message
59 */
60 private function preCacheMessages() {
61 if( !isset( $this->message ) ) {
62 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
63 'blocklink history boteditletter semicolon-separator' ) as $msg ) {
64 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
65 }
66 }
67 }
68
69
70 /**
71 * Returns the appropriate flags for new page, minor change and patrolling
72 * @param bool $new
73 * @param bool $minor
74 * @param bool $patrolled
75 * @param string $nothing, string to use for empty space
76 * @param bool $bot
77 * @return string
78 */
79 protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&nbsp;', $bot = false ) {
80 $f = $new ?
81 '<span class="newpage">' . $this->message['newpageletter'] . '</span>' : $nothing;
82 $f .= $minor ?
83 '<span class="minor">' . $this->message['minoreditletter'] . '</span>' : $nothing;
84 $f .= $bot ? '<span class="bot">' . $this->message['boteditletter'] . '</span>' : $nothing;
85 $f .= $patrolled ? '<span class="unpatrolled">!</span>' : $nothing;
86 return $f;
87 }
88
89 /**
90 * Returns text for the start of the tabular part of RC
91 * @return string
92 */
93 public function beginRecentChangesList() {
94 $this->rc_cache = array();
95 $this->rcMoveIndex = 0;
96 $this->rcCacheIndex = 0;
97 $this->lastdate = '';
98 $this->rclistOpen = false;
99 return '';
100 }
101
102 /**
103 * Show formatted char difference
104 * @param int $old bytes
105 * @param int $new bytes
106 * @returns string
107 */
108 public static function showCharacterDifference( $old, $new ) {
109 global $wgRCChangedSizeThreshold, $wgLang;
110 $szdiff = $new - $old;
111 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape'), $wgLang->formatNum($szdiff) );
112 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
113 $tag = 'strong';
114 } else {
115 $tag = 'span';
116 }
117 if( $szdiff === 0 ) {
118 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
119 } elseif( $szdiff > 0 ) {
120 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
121 } else {
122 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
123 }
124 }
125
126 /**
127 * Returns text for the end of RC
128 * @return string
129 */
130 public function endRecentChangesList() {
131 if( $this->rclistOpen ) {
132 return "</ul>\n";
133 } else {
134 return '';
135 }
136 }
137
138 protected function insertMove( &$s, $rc ) {
139 # Diff
140 $s .= '(' . $this->message['diff'] . ') (';
141 # Hist
142 $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'],
143 'action=history' ) . ') . . ';
144 # "[[x]] moved to [[y]]"
145 $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
146 $s .= wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
147 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
148 }
149
150 protected function insertDateHeader( &$s, $rc_timestamp ) {
151 global $wgLang;
152 # Make date header if necessary
153 $date = $wgLang->date( $rc_timestamp, true, true );
154 if( $date != $this->lastdate ) {
155 if( '' != $this->lastdate ) {
156 $s .= "</ul>\n";
157 }
158 $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
159 $this->lastdate = $date;
160 $this->rclistOpen = true;
161 }
162 }
163
164 protected function insertLog( &$s, $title, $logtype ) {
165 $logname = LogPage::logName( $logtype );
166 $s .= '(' . $this->skin->makeKnownLinkObj($title, $logname ) . ')';
167 }
168
169 protected function insertDiffHist( &$s, &$rc, $unpatrolled ) {
170 # Diff link
171 if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
172 $diffLink = $this->message['diff'];
173 } else if( !$this->userCan($rc,Revision::DELETED_TEXT) ) {
174 $diffLink = $this->message['diff'];
175 } else {
176 $rcidparam = $unpatrolled ? array( 'rcid' => $rc->mAttribs['rc_id'] ) : array();
177 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'],
178 wfArrayToCGI( array(
179 'curid' => $rc->mAttribs['rc_cur_id'],
180 'diff' => $rc->mAttribs['rc_this_oldid'],
181 'oldid' => $rc->mAttribs['rc_last_oldid'] ),
182 $rcidparam ),
183 '', '', ' tabindex="'.$rc->counter.'"');
184 }
185 $s .= '('.$diffLink.') (';
186 # History link
187 $s .= $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['hist'],
188 wfArrayToCGI( array(
189 'curid' => $rc->mAttribs['rc_cur_id'],
190 'action' => 'history' ) ) );
191 $s .= ') . . ';
192 }
193
194 protected function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
195 global $wgContLang;
196 # If it's a new article, there is no diff link, but if it hasn't been
197 # patrolled yet, we need to give users a way to do so
198 $params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) ?
199 'rcid='.$rc->mAttribs['rc_id'] : '';
200 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
201 $articlelink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
202 $articlelink = '<span class="history-deleted">'.$articlelink.'</span>';
203 } else {
204 $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
205 }
206 # Bolden pages watched by this user
207 if( $watched ) {
208 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
209 }
210 # RTL/LTR marker
211 $articlelink .= $wgContLang->getDirMark();
212
213 wfRunHooks( 'ChangesListInsertArticleLink',
214 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
215
216 $s .= " $articlelink";
217 }
218
219 protected function insertTimestamp( &$s, $rc ) {
220 global $wgLang;
221 $s .= $this->message['semicolon-separator'] . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
222 }
223
224 /** Insert links to user page, user talk page and eventually a blocking link */
225 public function insertUserRelatedLinks(&$s, &$rc) {
226 if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
227 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
228 } else {
229 $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
230 $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
231 }
232 }
233
234 /** insert a formatted action */
235 protected function insertAction(&$s, &$rc) {
236 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
237 if( $this->isDeleted($rc,LogPage::DELETED_ACTION) ) {
238 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
239 } else {
240 $s .= ' '.LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
241 $rc->getTitle(), $this->skin, LogPage::extractParams($rc->mAttribs['rc_params']), true, true );
242 }
243 }
244 }
245
246 /** insert a formatted comment */
247 protected function insertComment(&$s, &$rc) {
248 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
249 if( $this->isDeleted($rc,Revision::DELETED_COMMENT) ) {
250 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
251 } else {
252 $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
253 }
254 }
255 }
256
257 /**
258 * Check whether to enable recent changes patrol features
259 * @return bool
260 */
261 public static function usePatrol() {
262 global $wgUser;
263 return $wgUser->useRCPatrol();
264 }
265
266 /**
267 * Returns the string which indicates the number of watching users
268 */
269 protected function numberofWatchingusers( $count ) {
270 global $wgLang;
271 static $cache = array();
272 if( $count > 0 ) {
273 if( !isset( $cache[$count] ) ) {
274 $cache[$count] = wfMsgExt('number_of_watching_users_RCview',
275 array('parsemag', 'escape'), $wgLang->formatNum($count));
276 }
277 return $cache[$count];
278 } else {
279 return '';
280 }
281 }
282
283 /**
284 * Determine if said field of a revision is hidden
285 * @param RCCacheEntry $rc
286 * @param int $field one of DELETED_* bitfield constants
287 * @return bool
288 */
289 public static function isDeleted( $rc, $field ) {
290 return ($rc->mAttribs['rc_deleted'] & $field) == $field;
291 }
292
293 /**
294 * Determine if the current user is allowed to view a particular
295 * field of this revision, if it's marked as deleted.
296 * @param RCCacheEntry $rc
297 * @param int $field
298 * @return bool
299 */
300 public static function userCan( $rc, $field ) {
301 if( ( $rc->mAttribs['rc_deleted'] & $field ) == $field ) {
302 global $wgUser;
303 $permission = ( $rc->mAttribs['rc_deleted'] & Revision::DELETED_RESTRICTED ) == Revision::DELETED_RESTRICTED
304 ? 'suppressrevision'
305 : 'deleterevision';
306 wfDebug( "Checking for $permission due to $field match on $rc->mAttribs['rc_deleted']\n" );
307 return $wgUser->isAllowed( $permission );
308 } else {
309 return true;
310 }
311 }
312
313 protected function maybeWatchedLink( $link, $watched=false ) {
314 if( $watched ) {
315 return '<strong class="mw-watched">' . $link . '</strong>';
316 } else {
317 return '<span class="mw-rc-unwatched">' . $link . '</span>';
318 }
319 }
320 }
321
322
323 /**
324 * Generate a list of changes using the good old system (no javascript)
325 */
326 class OldChangesList extends ChangesList {
327 /**
328 * Format a line using the old system (aka without any javascript).
329 */
330 public function recentChangesLine( &$rc, $watched = false ) {
331 global $wgContLang, $wgRCShowChangedSize, $wgUser;
332 wfProfileIn( __METHOD__ );
333 # Should patrol-related stuff be shown?
334 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs['rc_patrolled'];
335
336 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
337 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
338
339 $s = '';
340 // Moved pages
341 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
342 $this->insertMove( $s, $rc );
343 // Log entries
344 } elseif( $rc->mAttribs['rc_log_type'] ) {
345 $logtitle = Title::newFromText( 'Log/'.$rc->mAttribs['rc_log_type'], NS_SPECIAL );
346 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
347 // Log entries (old format) or log targets, and special pages
348 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
349 list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $rc->mAttribs['rc_title'] );
350 if( $name == 'Log' ) {
351 $this->insertLog( $s, $rc->getTitle(), $subpage );
352 }
353 // Regular entries
354 } else {
355 $this->insertDiffHist( $s, $rc, $unpatrolled );
356 # M, N, b and ! (minor, new, bot and unpatrolled)
357 $s .= $this->recentChangesFlags( $rc->mAttribs['rc_new'], $rc->mAttribs['rc_minor'],
358 $unpatrolled, '', $rc->mAttribs['rc_bot'] );
359 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
360 }
361 # Edit/log timestamp
362 $this->insertTimestamp( $s, $rc );
363 # Bytes added or removed
364 if( $wgRCShowChangedSize && ($cd = $rc->getCharacterDifference()) ) {
365 $s .= "$cd . . ";
366 }
367 # User tool links
368 $this->insertUserRelatedLinks($s,$rc);
369 # Log action text (if any)
370 $this->insertAction($s, $rc);
371 # Edit or log comment
372 $this->insertComment($s, $rc);
373 # Mark revision as deleted if so
374 if( !$rc->mAttribs['rc_log_type'] && $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
375 $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
376 }
377 # How many users watch this page
378 if( $rc->numberofWatchingusers > 0 ) {
379 $s .= ' ' . wfMsg( 'number_of_watching_users_RCview',
380 $wgContLang->formatNum($rc->numberofWatchingusers) );
381 }
382
383 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
384
385 wfProfileOut( __METHOD__ );
386 return "$dateheader<li>$s</li>\n";
387 }
388 }
389
390
391 /**
392 * Generate a list of changes using an Enhanced system (uses javascript).
393 */
394 class EnhancedChangesList extends ChangesList {
395 /**
396 * Add the JavaScript file for enhanced changeslist
397 * @ return string
398 */
399 public function beginRecentChangesList() {
400 global $wgStylePath, $wgJsMimeType, $wgStyleVersion;
401 $this->rc_cache = array();
402 $this->rcMoveIndex = 0;
403 $this->rcCacheIndex = 0;
404 $this->lastdate = '';
405 $this->rclistOpen = false;
406 $script = Xml::tags( 'script', array(
407 'type' => $wgJsMimeType,
408 'src' => $wgStylePath . "/common/enhancedchanges.js?$wgStyleVersion" ), '' );
409 return $script;
410 }
411 /**
412 * Format a line for enhanced recentchange (aka with javascript and block of lines).
413 */
414 public function recentChangesLine( &$baseRC, $watched = false ) {
415 global $wgLang, $wgContLang, $wgUser;
416
417 # Create a specialised object
418 $rc = RCCacheEntry::newFromParent( $baseRC );
419
420 # Extract fields from DB into the function scope (rc_xxxx variables)
421 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
422 extract( $rc->mAttribs );
423 $curIdEq = 'curid=' . $rc_cur_id;
424
425 # If it's a new day, add the headline and flush the cache
426 $date = $wgLang->date( $rc_timestamp, true );
427 $ret = '';
428 if( $date != $this->lastdate ) {
429 # Process current cache
430 $ret = $this->recentChangesBlock();
431 $this->rc_cache = array();
432 $ret .= "<h4>{$date}</h4>\n";
433 $this->lastdate = $date;
434 }
435
436 # Should patrol-related stuff be shown?
437 if( $wgUser->useRCPatrol() ) {
438 $rc->unpatrolled = !$rc_patrolled;
439 } else {
440 $rc->unpatrolled = false;
441 }
442
443 $showdifflinks = true;
444 # Make article link
445 // Page moves
446 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
447 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
448 $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
449 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
450 // New unpatrolled pages
451 } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
452 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
453 // Log entries
454 } else if( $rc_type == RC_LOG ) {
455 if( $rc_log_type ) {
456 $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type );
457 $clink = '(' . $this->skin->makeKnownLinkObj( $logtitle, LogPage::logName($rc_log_type) ) . ')';
458 } else {
459 $clink = $this->skin->makeLinkObj( $rc->getTitle(), '' );
460 }
461 $watched = false;
462 // Log entries (old format) and special pages
463 } elseif( $rc_namespace == NS_SPECIAL ) {
464 list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
465 if ( $specialName == 'Log' ) {
466 # Log updates, etc
467 $logname = LogPage::logName( $logtype );
468 $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
469 } else {
470 wfDebug( "Unexpected special page in recentchanges\n" );
471 $clink = '';
472 }
473 // Edits
474 } else {
475 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' );
476 }
477
478 # Don't show unusable diff links
479 if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
480 $showdifflinks = false;
481 }
482
483 $time = $wgContLang->time( $rc_timestamp, true, true );
484 $rc->watched = $watched;
485 $rc->link = $clink;
486 $rc->timestamp = $time;
487 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
488
489 # Make "cur" and "diff" links
490 if( $rc->unpatrolled ) {
491 $rcIdQuery = "&rcid={$rc_id}";
492 } else {
493 $rcIdQuery = '';
494 }
495 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
496 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
497 $aprops = ' tabindex="'.$baseRC->counter.'"';
498 $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['cur'], $querycur, '' ,'', $aprops );
499
500 # Make "diff" an "cur" links
501 if( !$showdifflinks ) {
502 $curLink = $this->message['cur'];
503 $diffLink = $this->message['diff'];
504 } else if( $rc_type == RC_NEW || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
505 if( $rc_type != RC_NEW ) {
506 $curLink = $this->message['cur'];
507 }
508 $diffLink = $this->message['diff'];
509 } else {
510 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], $querydiff, '' ,'', $aprops );
511 }
512
513 # Make "last" link
514 if( !$showdifflinks ) {
515 $lastLink = $this->message['last'];
516 } else if( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
517 $lastLink = $this->message['last'];
518 } else {
519 $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'],
520 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
521 }
522
523 # Make user links
524 if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
525 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
526 } else {
527 $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text );
528 $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text );
529 }
530
531 $rc->lastlink = $lastLink;
532 $rc->curlink = $curLink;
533 $rc->difflink = $diffLink;
534
535 # Put accumulated information into the cache, for later display
536 # Page moves go on their own line
537 $title = $rc->getTitle();
538 $secureName = $title->getPrefixedDBkey();
539 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
540 # Use an @ character to prevent collision with page names
541 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
542 } else {
543 # Logs are grouped by type
544 if( $rc_type == RC_LOG ){
545 $secureName = SpecialPage::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
546 }
547 if( !isset( $this->rc_cache[$secureName] ) ) {
548 $this->rc_cache[$secureName] = array();
549 }
550 array_push( $this->rc_cache[$secureName], $rc );
551 }
552 return $ret;
553 }
554
555 /**
556 * Enhanced RC group
557 */
558 protected function recentChangesBlockGroup( $block ) {
559 global $wgLang, $wgContLang, $wgRCShowChangedSize;
560 $r = '<table cellpadding="0" cellspacing="0" border="0" style="background: none"><tr>';
561
562 # Collate list of users
563 $userlinks = array();
564 # Other properties
565 $unpatrolled = false;
566 $isnew = false;
567 $curId = $currentRevision = 0;
568 # Some catalyst variables...
569 $namehidden = true;
570 $allLogs = true;
571 foreach( $block as $rcObj ) {
572 $oldid = $rcObj->mAttribs['rc_last_oldid'];
573 if( $rcObj->mAttribs['rc_new'] ) {
574 $isnew = true;
575 }
576 // If all log actions to this page were hidden, then don't
577 // give the name of the affected page for this block!
578 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
579 $namehidden = false;
580 }
581 $u = $rcObj->userlink;
582 if( !isset( $userlinks[$u] ) ) {
583 $userlinks[$u] = 0;
584 }
585 if( $rcObj->unpatrolled ) {
586 $unpatrolled = true;
587 }
588 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
589 $allLogs = false;
590 }
591 # Get the latest entry with a page_id and oldid
592 # since logs may not have these.
593 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
594 $curId = $rcObj->mAttribs['rc_cur_id'];
595 }
596 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
597 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
598 }
599
600 $bot = $rcObj->mAttribs['rc_bot'];
601 $userlinks[$u]++;
602 }
603
604 # Sort the list and convert to text
605 krsort( $userlinks );
606 asort( $userlinks );
607 $users = array();
608 foreach( $userlinks as $userlink => $count) {
609 $text = $userlink;
610 $text .= $wgContLang->getDirMark();
611 if( $count > 1 ) {
612 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
613 }
614 array_push( $users, $text );
615 }
616
617 $users = ' <span class="changedby">[' . implode( $this->message['semicolon-separator'], $users ) . ']</span>';
618
619 # ID for JS visibility toggle
620 $jsid = $this->rcCacheIndex;
621 # onclick handler to toggle hidden/expanded
622 $toggleLink = "onclick='toggleVisibility($jsid); return false'";
623 # Title for <a> tags
624 $expandTitle = htmlspecialchars( wfMsg('rc-enhanced-expand') );
625 $closeTitle = htmlspecialchars( wfMsg('rc-enhanced-hide') );
626
627 $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
628 $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
629 $r .= '<td valign="top" style="white-space: nowrap"><tt>'.$tl.'&nbsp;';
630
631 # Main line
632 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
633
634 # Timestamp
635 $r .= '&nbsp;'.$block[0]->timestamp.'&nbsp;</tt></td><td>';
636
637 # Article link
638 if( $namehidden ) {
639 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
640 } else if( $allLogs ) {
641 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
642 } else {
643 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
644 }
645
646 $r .= $wgContLang->getDirMark();
647
648 $curIdEq = 'curid=' . $curId;
649 # Changes message
650 $n = count($block);
651 static $nchanges = array();
652 if ( !isset( $nchanges[$n] ) ) {
653 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
654 }
655 # Total change link
656 $r .= ' ';
657 if( !$allLogs ) {
658 $r .= '(';
659 if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
660 $r .= $nchanges[$n];
661 } else if( $isnew ) {
662 $r .= $nchanges[$n];
663 } else {
664 $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
665 $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
666 }
667 }
668
669 # History
670 if( $allLogs ) {
671 // don't show history link for logs
672 } else if( $namehidden || !$block[0]->getTitle()->exists() ) {
673 $r .= $this->message['semicolon-separator'] . $this->message['hist'] . ')';
674 } else {
675 $r .= $this->message['semicolon-separator'] . $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
676 $this->message['hist'], $curIdEq . '&action=history' ) . ')';
677 }
678 $r .= ' . . ';
679
680 # Character difference (does not apply if only log items)
681 if( $wgRCShowChangedSize && !$allLogs ) {
682 $last = 0;
683 $first = count($block) - 1;
684 # Some events (like logs) have an "empty" size, so we need to skip those...
685 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === NULL ) {
686 $last++;
687 }
688 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === NULL ) {
689 $first--;
690 }
691 # Get net change
692 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
693 $block[$last]->mAttribs['rc_new_len'] );
694
695 if( $chardiff == '' ) {
696 $r .= ' ';
697 } else {
698 $r .= ' ' . $chardiff. ' . . ';
699 }
700 }
701
702 $r .= $users;
703 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
704
705 $r .= "</td></tr></table>\n";
706
707 # Sub-entries
708 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
709 $r .= '<table cellpadding="0" cellspacing="0" border="0" style="background: none">';
710 foreach( $block as $rcObj ) {
711 # Get rc_xxxx variables
712 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
713 extract( $rcObj->mAttribs );
714
715 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
716 $r .= '<tr><td valign="top">';
717 $r .= '<tt>'.$this->spacerIndent() . $this->spacerIndent();
718 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
719 $r .= '&nbsp;</tt></td><td valign="top">';
720
721 $o = '';
722 if( $rc_this_oldid != 0 ) {
723 $o = 'oldid='.$rc_this_oldid;
724 }
725 # Log timestamp
726 if( $rc_type == RC_LOG ) {
727 $link = '<tt>'.$rcObj->timestamp.'</tt> ';
728 # Revision link
729 } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
730 $link = '<span class="history-deleted"><tt>'.$rcObj->timestamp.'</tt></span> ';
731 } else {
732 $rcIdEq = ($rcObj->unpatrolled && $rc_type == RC_NEW) ?
733 '&rcid='.$rcObj->mAttribs['rc_id'] : '';
734 $link = '<tt>'.$this->skin->makeKnownLinkObj( $rcObj->getTitle(),
735 $rcObj->timestamp, $curIdEq.'&'.$o.$rcIdEq ).'</tt>';
736 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
737 $link = '<span class="history-deleted">'.$link.'</span> ';
738 }
739 $r .= $link;
740
741 if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
742 $r .= ' (';
743 $r .= $rcObj->curlink;
744 $r .= $this->message['semicolon-separator'];
745 $r .= $rcObj->lastlink;
746 $r .= ')';
747 }
748 $r .= ' . . ';
749
750 # Character diff
751 if( $wgRCShowChangedSize ) {
752 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
753 }
754 # User links
755 $r .= $rcObj->userlink;
756 $r .= $rcObj->usertalklink;
757 // log action
758 parent::insertAction( $r, $rcObj );
759 // log comment
760 parent::insertComment( $r, $rcObj );
761 # Mark revision as deleted
762 if( !$rc_log_type && $this->isDeleted($rcObj,Revision::DELETED_TEXT) ) {
763 $r .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
764 }
765
766 $r .= "</td></tr>\n";
767 }
768 $r .= "</table></div>\n";
769
770 $this->rcCacheIndex++;
771 return $r;
772 }
773
774 /**
775 * Generate HTML for an arrow or placeholder graphic
776 * @param string $dir one of '', 'd', 'l', 'r'
777 * @param string $alt text
778 * @param string $title text
779 * @return string HTML <img> tag
780 */
781 protected function arrow( $dir, $alt='', $title='' ) {
782 global $wgStylePath;
783 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
784 $encAlt = htmlspecialchars( $alt );
785 $encTitle = htmlspecialchars( $title );
786 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
787 }
788
789 /**
790 * Generate HTML for a right- or left-facing arrow,
791 * depending on language direction.
792 * @return string HTML <img> tag
793 */
794 protected function sideArrow() {
795 global $wgContLang;
796 $dir = $wgContLang->isRTL() ? 'l' : 'r';
797 return $this->arrow( $dir, '+', wfMsg('rc-enhanced-expand') );
798 }
799
800 /**
801 * Generate HTML for a down-facing arrow
802 * depending on language direction.
803 * @return string HTML <img> tag
804 */
805 protected function downArrow() {
806 return $this->arrow( 'd', '-', wfMsg('rc-enhanced-hide') );
807 }
808
809 /**
810 * Generate HTML for a spacer image
811 * @return string HTML <img> tag
812 */
813 protected function spacerArrow() {
814 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
815 }
816
817 /**
818 * Add a set of spaces
819 * @return string HTML <td> tag
820 */
821 protected function spacerIndent() {
822 return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
823 }
824
825 /**
826 * Enhanced RC ungrouped line.
827 * @return string a HTML formated line (generated using $r)
828 */
829 protected function recentChangesBlockLine( $rcObj ) {
830 global $wgContLang, $wgRCShowChangedSize;
831 # Get rc_xxxx variables
832 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
833 extract( $rcObj->mAttribs );
834 $curIdEq = "curid={$rc_cur_id}";
835
836 $r = '<table cellspacing="0" cellpadding="0" border="0" style="background: none"><tr>';
837 $r .= '<td valign="top" style="white-space: nowrap"><tt>' . $this->spacerArrow() . '&nbsp;';
838 # Flag and Timestamp
839 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
840 $r .= '&nbsp;&nbsp;&nbsp;&nbsp;'; // 4 flags -> 4 spaces
841 } else {
842 $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
843 }
844 $r .= '&nbsp;'.$rcObj->timestamp.'&nbsp;</tt></td><td>';
845 # Article or log link
846 if( $rc_log_type ) {
847 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
848 $logname = LogPage::logName( $rc_log_type );
849 $r .= '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')';
850 } else {
851 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
852 }
853 # Diff and hist links
854 if ( $rc_type != RC_LOG ) {
855 $r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator'];
856 $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ')';
857 }
858 $r .= ' . . ';
859 # Character diff
860 if( $wgRCShowChangedSize ) {
861 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
862 }
863 # User/talk
864 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
865 # Log action (if any)
866 if( $rc_log_type ) {
867 if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
868 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
869 } else {
870 $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
871 $this->skin, LogPage::extractParams($rc_params), true, true );
872 }
873 }
874 # Edit or log comment
875 if( $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
876 // log comment
877 if ( $this->isDeleted($rcObj,LogPage::DELETED_COMMENT) ) {
878 $r .= ' <span class="history-deleted">' . wfMsg('rev-deleted-comment') . '</span>';
879 } else {
880 $r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() );
881 }
882 }
883 # Show how many people are watching this if enabled
884 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
885
886 $r .= "</td></tr></table>\n";
887 return $r;
888 }
889
890 /**
891 * If enhanced RC is in use, this function takes the previously cached
892 * RC lines, arranges them, and outputs the HTML
893 */
894 protected function recentChangesBlock() {
895 if( count ( $this->rc_cache ) == 0 ) {
896 return '';
897 }
898 $blockOut = '';
899 foreach( $this->rc_cache as $block ) {
900 if( count( $block ) < 2 ) {
901 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
902 } else {
903 $blockOut .= $this->recentChangesBlockGroup( $block );
904 }
905 }
906 return '<div>'.$blockOut.'</div>';
907 }
908
909 /**
910 * Returns text for the end of RC
911 * If enhanced RC is in use, returns pretty much all the text
912 */
913 public function endRecentChangesList() {
914 return $this->recentChangesBlock() . parent::endRecentChangesList();
915 }
916
917 }