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