Partial revert of r32982; old Title method is fine here
[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( 'escape') );
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 $wgUseRCPatrol, $wgUser;
250 return( $wgUseRCPatrol && ($wgUser->isAllowed('patrol') || $wgUser->isAllowed('patrolmarks')) );
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 ? 'hiderevision'
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 ) {
310 global $wgContLang, $wgRCShowChangedSize;
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 = $this->usePatrol() && $rc_patrolled == 0;
321
322 $this->insertDateHeader($s,$rc_timestamp);
323
324 $s .= '<li>';
325
326 // Moved pages
327 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
328 $this->insertMove( $s, $rc );
329 // Log entries
330 } elseif( $rc_log_type ) {
331 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
332 $this->insertLog( $s, $logtitle, $rc_log_type );
333 // Log entries (old format) or log targets, and special pages
334 } elseif( $rc_namespace == NS_SPECIAL ) {
335 list( $specialName, $specialSubpage ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
336 if ( $specialName == 'Log' ) {
337 $this->insertLog( $s, $rc->getTitle(), $specialSubpage );
338 } else {
339 wfDebug( "Unexpected special page in recentchanges\n" );
340 }
341 // Regular entries
342 } else {
343 wfProfileIn($fname.'-page');
344
345 $this->insertDiffHist($s, $rc, $unpatrolled);
346
347 # M, N, b and ! (minor, new, bot and unpatrolled)
348 $s .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '', $rc_bot );
349 $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
350
351 wfProfileOut($fname.'-page');
352 }
353
354 wfProfileIn( $fname.'-rest' );
355
356 $this->insertTimestamp($s,$rc);
357
358 if( $wgRCShowChangedSize ) {
359 $s .= ( $rc->getCharacterDifference() == '' ? '' : $rc->getCharacterDifference() . ' . . ' );
360 }
361 # User tool links
362 $this->insertUserRelatedLinks($s,$rc);
363 # Log action text (if any)
364 $this->insertAction($s, $rc);
365 # Edit or log comment
366 $this->insertComment($s, $rc);
367
368 # Mark revision as deleted if so
369 if ( !$rc_log_type && $this->isDeleted($rc,Revision::DELETED_TEXT) )
370 $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
371 if($rc->numberofWatchingusers > 0) {
372 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers));
373 }
374
375 $s .= "</li>\n";
376
377 wfProfileOut( $fname.'-rest' );
378
379 wfProfileOut( $fname );
380 return $s;
381 }
382 }
383
384
385 /**
386 * Generate a list of changes using an Enhanced system (use javascript).
387 */
388 class EnhancedChangesList extends ChangesList {
389 /**
390 * Format a line for enhanced recentchange (aka with javascript and block of lines).
391 */
392 public function recentChangesLine( &$baseRC, $watched = false ) {
393 global $wgLang, $wgContLang;
394
395 # Create a specialised object
396 $rc = RCCacheEntry::newFromParent( $baseRC );
397
398 # Extract fields from DB into the function scope (rc_xxxx variables)
399 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
400 extract( $rc->mAttribs );
401 $curIdEq = 'curid=' . $rc_cur_id;
402
403 # If it's a new day, add the headline and flush the cache
404 $date = $wgLang->date( $rc_timestamp, true);
405 $ret = '';
406 if( $date != $this->lastdate ) {
407 # Process current cache
408 $ret = $this->recentChangesBlock();
409 $this->rc_cache = array();
410 $ret .= "<h4>{$date}</h4>\n";
411 $this->lastdate = $date;
412 }
413
414 # Should patrol-related stuff be shown?
415 if( $this->usePatrol() ) {
416 $rc->unpatrolled = !$rc_patrolled;
417 } else {
418 $rc->unpatrolled = false;
419 }
420
421 $showdifflinks = true;
422 # Make article link
423 // Page moves
424 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
425 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
426 $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
427 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
428 // Log entries (old format) and special pages
429 } elseif( $rc_namespace == NS_SPECIAL ) {
430 list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
431 if ( $specialName == 'Log' ) {
432 # Log updates, etc
433 $logname = LogPage::logName( $logtype );
434 $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
435 } else {
436 wfDebug( "Unexpected special page in recentchanges\n" );
437 $clink = '';
438 }
439 // New unpatrolled pages
440 } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
441 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
442 // Other edits or log entries
443 } else {
444 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' );
445 }
446
447 # Don't show unusable diff links
448 if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
449 $showdifflinks = false;
450 }
451
452 $time = $wgContLang->time( $rc_timestamp, true, true );
453 $rc->watched = $watched;
454 $rc->link = $clink;
455 $rc->timestamp = $time;
456 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
457
458 # Make "cur" and "diff" links
459 if( $rc->unpatrolled ) {
460 $rcIdQuery = "&rcid={$rc_id}";
461 } else {
462 $rcIdQuery = '';
463 }
464 $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
465 $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
466 $aprops = ' tabindex="'.$baseRC->counter.'"';
467 $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['cur'], $querycur, '' ,'', $aprops );
468
469 # Make "diff" an "cur" links
470 if( !$showdifflinks ) {
471 $curLink = $this->message['cur'];
472 $diffLink = $this->message['diff'];
473 } else if( $rc_type == RC_NEW || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
474 if( $rc_type != RC_NEW ) {
475 $curLink = $this->message['cur'];
476 }
477 $diffLink = $this->message['diff'];
478 } else {
479 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], $querydiff, '' ,'', $aprops );
480 }
481
482 # Make "last" link
483 if( !$showdifflinks ) {
484 $lastLink = $this->message['last'];
485 } else if( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
486 $lastLink = $this->message['last'];
487 } else {
488 $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'],
489 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
490 }
491
492 # Make user links
493 if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
494 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
495 } else {
496 $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text );
497 $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text );
498 }
499
500 $rc->lastlink = $lastLink;
501 $rc->curlink = $curLink;
502 $rc->difflink = $diffLink;
503
504 # Put accumulated information into the cache, for later display
505 # Page moves go on their own line
506 $title = $rc->getTitle();
507 $secureName = $title->getPrefixedDBkey();
508 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
509 # Use an @ character to prevent collision with page names
510 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
511 } else {
512 if( $rc_type == RC_LOG ){
513 $secureName = SpecialPage::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
514 }
515 if( !isset( $this->rc_cache[$secureName] ) ) {
516 $this->rc_cache[$secureName] = array();
517 }
518 array_push( $this->rc_cache[$secureName], $rc );
519 }
520 return $ret;
521 }
522
523 /**
524 * Enhanced RC group
525 */
526 protected function recentChangesBlockGroup( $block ) {
527 global $wgLang, $wgContLang, $wgRCShowChangedSize;
528 $r = '<table cellpadding="0" cellspacing="0" border="0" style="background: none"><tr>';
529
530 # Collate list of users
531 $userlinks = array();
532 # Other properties
533 $unpatrolled = false;
534 $isnew = false;
535 $curId = $currentRevision = 0;
536 # Some catalyst variables...
537 $namehidden = true;
538 $alllogs = true;
539 foreach( $block as $rcObj ) {
540 $oldid = $rcObj->mAttribs['rc_last_oldid'];
541 if( $rcObj->mAttribs['rc_new'] ) {
542 $isnew = true;
543 }
544 // If all log actions to this page were hidden, then don't
545 // give the name of the affected page for this block!
546 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
547 $namehidden = false;
548 }
549 $u = $rcObj->userlink;
550 if( !isset( $userlinks[$u] ) ) {
551 $userlinks[$u] = 0;
552 }
553 if( $rcObj->unpatrolled ) {
554 $unpatrolled = true;
555 }
556 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
557 $alllogs = false;
558 }
559 # Get the latest entry with a page_id and oldid
560 # since logs may not have these.
561 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
562 $curId = $rcObj->mAttribs['rc_cur_id'];
563 }
564 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
565 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
566 }
567
568 $bot = $rcObj->mAttribs['rc_bot'];
569 $userlinks[$u]++;
570 }
571
572 # Sort the list and convert to text
573 krsort( $userlinks );
574 asort( $userlinks );
575 $users = array();
576 foreach( $userlinks as $userlink => $count) {
577 $text = $userlink;
578 $text .= $wgContLang->getDirMark();
579 if( $count > 1 ) {
580 $text .= ' ('.$count.'&times;)';
581 }
582 array_push( $users, $text );
583 }
584
585 $users = ' <span class="changedby">[' . implode( $this->message['semicolon-separator'] . ' ', $users ) . ']</span>';
586
587 # Arrow
588 $rci = 'RCI'.$this->rcCacheIndex;
589 $rcl = 'RCL'.$this->rcCacheIndex;
590 $rcm = 'RCM'.$this->rcCacheIndex;
591 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')";
592 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'">' . $this->sideArrow() . '</a></span>';
593 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'">' . $this->downArrow() . '</a></span>';
594 $r .= '<td valign="top" style="white-space: nowrap"><tt>'.$tl.'&nbsp;';
595
596 # Main line
597 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
598
599 # Timestamp
600 $r .= '&nbsp;'.$block[0]->timestamp.'&nbsp;</tt></td><td>';
601
602 # Article link
603 if( $alllogs ){
604 $logtype = $block[0]->mAttribs['rc_log_type'];
605 if( is_null( $logtype ) ){
606 //Old format
607 $r .= $block[0]->link;
608 } else {
609 $logname = LogPage::logName( $logtype );
610 $r .= ' (' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log', $logtype ), $logname ) . ')';
611 }
612 } else if( $namehidden ) {
613 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
614 } else {
615 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
616 }
617
618 $r .= $wgContLang->getDirMark();
619
620 $curIdEq = 'curid=' . $curId;
621 # Changes message
622 $n = count($block);
623 static $nchanges = array();
624 if ( !isset( $nchanges[$n] ) ) {
625 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
626 }
627 # Total change link
628 $r .= ' ';
629 if( !$alllogs ) {
630 $r .= '(';
631 if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
632 $r .= $nchanges[$n];
633 } else if( $isnew ) {
634 $r .= $nchanges[$n];
635 } else {
636 $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
637 $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
638 }
639 $r .= ') . . ';
640 }
641
642 # Character difference (does not apply if only log items)
643 if( $wgRCShowChangedSize && !$alllogs ) {
644 $last = 0;
645 $first = count($block) - 1;
646 # Some events (like logs) have an "empty" size, so we need to skip those...
647 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === NULL ) {
648 $last++;
649 }
650 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === NULL ) {
651 $first--;
652 }
653 # Get net change
654 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
655 $block[$last]->mAttribs['rc_new_len'] );
656
657 if( $chardiff == '' ) {
658 $r .= ' ';
659 } else {
660 $r .= ' ' . $chardiff. ' . . ';
661 }
662 }
663
664 # History
665 if( $namehidden || $alllogs ) {
666 $r .= '(' . $this->message['history'] . ')';
667 } else {
668 $r .= '(' . $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
669 $this->message['history'], $curIdEq.'&action=history' ) . ')';
670 }
671
672 $r .= $users;
673 $r .=$this->numberofWatchingusers($block[0]->numberofWatchingusers);
674
675 $r .= "</td></tr></table>\n";
676
677 # Sub-entries
678 $r .= '<div id="'.$rci.'" style="display:none;"><table cellpadding="0" cellspacing="0" border="0" style="background: none">';
679 foreach( $block as $rcObj ) {
680 # Get rc_xxxx variables
681 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
682 extract( $rcObj->mAttribs );
683
684 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
685 $r .= '<tr><td valign="top">';
686 $r .= '<tt>'.$this->spacerIndent() . $this->spacerIndent();
687 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
688 $r .= '&nbsp;</tt></td><td valign="top">';
689
690 $o = '';
691 if( $rc_this_oldid != 0 ) {
692 $o = 'oldid='.$rc_this_oldid;
693 }
694 # Revision link
695 if( $rc_type == RC_LOG ) {
696 $link = '<tt>'.$rcObj->timestamp.'</tt> ';
697 } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
698 $link = '<span class="history-deleted"><tt>'.$rcObj->timestamp.'</tt></span> ';
699 } else {
700 $link = '<tt>'.$this->skin->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp, $curIdEq.'&'.$o ).'</tt>';
701 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
702 $link = '<span class="history-deleted">'.$link.'</span> ';
703 }
704 $r .= $link;
705
706 if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
707 $r .= ' (';
708 $r .= $rcObj->curlink;
709 $r .= $this->message['semicolon-separator'] . ' ';
710 $r .= $rcObj->lastlink;
711 $r .= ')';
712 }
713 $r .= ' . . ';
714
715 # Character diff
716 if( $wgRCShowChangedSize ) {
717 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
718 }
719 # User links
720 $r .= $rcObj->userlink;
721 $r .= $rcObj->usertalklink;
722 // log action
723 parent::insertAction( $r, $rcObj );
724 // log comment
725 parent::insertComment( $r, $rcObj );
726 # Mark revision as deleted
727 if( !$rc_log_type && $this->isDeleted($rcObj,Revision::DELETED_TEXT) ) {
728 $r .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
729 }
730
731 $r .= "</td></tr>\n";
732 }
733 $r .= "</table></div>\n";
734
735 $this->rcCacheIndex++;
736 return $r;
737 }
738
739 protected function maybeWatchedLink( $link, $watched=false ) {
740 if( $watched ) {
741 // FIXME: css style might be more appropriate
742 return '<strong class="mw-watched">' . $link . '</strong>';
743 } else {
744 return $link;
745 }
746 }
747
748 /**
749 * Generate HTML for an arrow or placeholder graphic
750 * @param string $dir one of '', 'd', 'l', 'r'
751 * @param string $alt text
752 * @return string HTML <img> tag
753 */
754 protected function arrow( $dir, $alt='' ) {
755 global $wgStylePath;
756 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
757 $encAlt = htmlspecialchars( $alt );
758 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" />";
759 }
760
761 /**
762 * Generate HTML for a right- or left-facing arrow,
763 * depending on language direction.
764 * @return string HTML <img> tag
765 */
766 protected function sideArrow() {
767 global $wgContLang;
768 $dir = $wgContLang->isRTL() ? 'l' : 'r';
769 return $this->arrow( $dir, '+' );
770 }
771
772 /**
773 * Generate HTML for a down-facing arrow
774 * depending on language direction.
775 * @return string HTML <img> tag
776 */
777 protected function downArrow() {
778 return $this->arrow( 'd', '-' );
779 }
780
781 /**
782 * Generate HTML for a spacer image
783 * @return string HTML <img> tag
784 */
785 protected function spacerArrow() {
786 return $this->arrow( '', ' ' );
787 }
788
789 /**
790 * Add a set of spaces
791 * @return string HTML <td> tag
792 */
793 protected function spacerIndent() {
794 return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
795 }
796
797 /**
798 * Enhanced RC ungrouped line.
799 * @return string a HTML formated line (generated using $r)
800 */
801 protected function recentChangesBlockLine( $rcObj ) {
802 global $wgContLang, $wgRCShowChangedSize;
803
804 # Get rc_xxxx variables
805 // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
806 extract( $rcObj->mAttribs );
807 $curIdEq = 'curid='.$rc_cur_id;
808
809 $r = '<table cellspacing="0" cellpadding="0" border="0" style="background: none"><tr>';
810
811 $r .= '<td valign="top" style="white-space: nowrap"><tt>' . $this->spacerArrow() . '&nbsp;';
812
813 # Flag and Timestamp
814 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
815 $r .= '&nbsp;&nbsp;&nbsp;&nbsp;'; // 4 flags -> 4 spaces
816 } else {
817 $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
818 }
819 $r .= '&nbsp;'.$rcObj->timestamp.'&nbsp;</tt></td><td>';
820
821 # Article or log link
822 if( $rc_log_type ) {
823 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
824 $logname = LogPage::logName( $rc_log_type );
825 $r .= '(' . $this->skin->makeKnownLinkObj($logtitle, $logname ) . ')';
826 } else if( !$this->userCan($rcObj,Revision::DELETED_TEXT) ) {
827 $r .= '<span class="history-deleted">' . $rcObj->link . '</span>';
828 } else {
829 $r .= $this->maybeWatchedLink( $rcObj->link, $rcObj->watched );
830 }
831
832 # Diff and hist links
833 if ( $rc_type != RC_LOG ) {
834 $r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator'] . ' ';
835 $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ')';
836 }
837 $r .= ' . . ';
838
839 # Character diff
840 if( $wgRCShowChangedSize ) {
841 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : '&nbsp;' . $rcObj->getCharacterDifference() . ' . . ' ) ;
842 }
843
844 # User/talk
845 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
846
847 # Log action (if any)
848 if( $rc_log_type ) {
849 if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
850 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
851 } else {
852 $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(), $this->skin, LogPage::extractParams($rc_params), true, true );
853 }
854 }
855
856 # Edit or log comment
857 if( $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
858 // log comment
859 if ( $this->isDeleted($rcObj,LogPage::DELETED_COMMENT) ) {
860 $r .= ' <span class="history-deleted">' . wfMsg('rev-deleted-comment') . '</span>';
861 } else {
862 $r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() );
863 }
864 }
865
866 # Show how many people are watching this if enabled
867 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
868
869 $r .= "</td></tr></table>\n";
870 return $r;
871 }
872
873 /**
874 * If enhanced RC is in use, this function takes the previously cached
875 * RC lines, arranges them, and outputs the HTML
876 */
877 protected function recentChangesBlock() {
878 if( count ( $this->rc_cache ) == 0 ) {
879 return '';
880 }
881 $blockOut = '';
882 foreach( $this->rc_cache as $block ) {
883 if( count( $block ) < 2 ) {
884 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
885 } else {
886 $blockOut .= $this->recentChangesBlockGroup( $block );
887 }
888 }
889
890 return '<div>'.$blockOut.'</div>';
891 }
892
893 /**
894 * Returns text for the end of RC
895 * If enhanced RC is in use, returns pretty much all the text
896 */
897 public function endRecentChangesList() {
898 return $this->recentChangesBlock() . parent::endRecentChangesList();
899 }
900
901 }