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