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