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