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