call static function statically
[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 protected $watchlist = false;
29
30 /**
31 * Changeslist contructor
32 * @param Skin $skin
33 */
34 public function __construct( $skin ) {
35 $this->skin = $skin;
36 $this->preCacheMessages();
37 }
38
39 /**
40 * Fetch an appropriate changes list class for the specified user
41 * Some users might want to use an enhanced list format, for instance
42 *
43 * @param $user User to fetch the list class for
44 * @return ChangesList derivative
45 */
46 public static function newFromUser( &$user ) {
47 $sk = $user->getSkin();
48 $list = NULL;
49 if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
50 return $user->getOption( 'usenewrc' ) ?
51 new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
52 } else {
53 return $list;
54 }
55 }
56
57 /**
58 * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
59 * @param bool $value
60 */
61 public function setWatchlistDivs( $value = true ) {
62 $this->watchlist = $value;
63 }
64
65 /**
66 * As we use the same small set of messages in various methods and that
67 * they are called often, we call them once and save them in $this->message
68 */
69 private function preCacheMessages() {
70 if( !isset( $this->message ) ) {
71 foreach ( explode( ' ', 'cur diff hist last blocklink history ' .
72 'semicolon-separator pipe-separator' ) as $msg ) {
73 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
74 }
75 }
76 }
77
78
79 /**
80 * Returns the appropriate flags for new page, minor change and patrolling
81 * @param bool $new
82 * @param bool $minor
83 * @param bool $patrolled
84 * @param string $nothing, string to use for empty space
85 * @param bool $bot
86 * @return string
87 */
88 protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&nbsp;', $bot = false ) {
89 $f = $new ? self::flag( 'newpage' ) : $nothing;
90 $f .= $minor ? self::flag( 'minor' ) : $nothing;
91 $f .= $bot ? self::flag( 'bot' ) : $nothing;
92 $f .= $patrolled ? self::flag( 'unpatrolled' ) : $nothing;
93 return $f;
94 }
95
96 /**
97 * Provide the <abbr> element appropriate to a given abbreviated flag,
98 * namely the flag indicating a new page, a minor edit, a bot edit, or an
99 * unpatrolled edit. By default in English it will contain "N", "m", "b",
100 * "!" respectively, plus it will have an appropriate title and class.
101 *
102 * @param $key string 'newpage', 'unpatrolled', 'minor', or 'bot'
103 * @return string Raw HTML
104 */
105 public static function flag( $key ) {
106 static $messages = null;
107 if ( is_null( $messages ) ) {
108 foreach ( explode( ' ', 'minoreditletter boteditletter newpageletter ' .
109 'unpatrolledletter recentchanges-label-minor recentchanges-label-bot ' .
110 'recentchanges-label-newpage recentchanges-label-unpatrolled' ) as $msg ) {
111 $messages[$msg] = wfMsgExt( $msg, 'escapenoentities' );
112 }
113 }
114 # Inconsistent naming, bleh
115 if ( $key == 'newpage' || $key == 'unpatrolled' ) {
116 $key2 = $key;
117 } else {
118 $key2 = $key . 'edit';
119 }
120 return "<abbr class=\"$key\" title=\""
121 . $messages["recentchanges-label-$key"] . "\">"
122 . $messages["${key2}letter"]
123 . '</abbr>';
124 }
125
126 /**
127 * Some explanatory wrapper text for the given flag, to be used in a legend
128 * explaining what the flags mean. For instance, "N - new page". See
129 * also flag().
130 *
131 * @param $key string 'newpage', 'unpatrolled', 'minor', or 'bot'
132 * @return string Raw HTML
133 */
134 private static function flagLine( $key ) {
135 return wfMsgExt( "recentchanges-legend-$key", array( 'escapenoentities',
136 'replaceafter' ), self::flag( $key ) );
137 }
138
139 /**
140 * A handy legend to tell users what the little "m", "b", and so on mean.
141 *
142 * @return string Raw HTML
143 */
144 public static function flagLegend() {
145 global $wgGroupPermissions, $wgLang;
146
147 $flags = array( self::flagLine( 'newpage' ),
148 self::flagLine( 'minor' ) );
149
150 # Don't show info on bot edits unless there's a bot group of some kind
151 foreach ( $wgGroupPermissions as $rights ) {
152 if ( isset( $rights['bot'] ) && $rights['bot'] ) {
153 $flags[] = self::flagLine( 'bot' );
154 break;
155 }
156 }
157
158 if ( self::usePatrol() ) {
159 $flags[] = self::flagLine( 'unpatrolled' );
160 }
161
162 return '<div class="mw-rc-label-legend">' .
163 wfMsgExt( 'recentchanges-label-legend', 'parseinline',
164 $wgLang->commaList( $flags ) ) . '</div>';
165 }
166
167 /**
168 * Returns text for the start of the tabular part of RC
169 * @return string
170 */
171 public function beginRecentChangesList() {
172 $this->rc_cache = array();
173 $this->rcMoveIndex = 0;
174 $this->rcCacheIndex = 0;
175 $this->lastdate = '';
176 $this->rclistOpen = false;
177 return '';
178 }
179
180 /**
181 * Show formatted char difference
182 * @param int $old bytes
183 * @param int $new bytes
184 * @returns string
185 */
186 public static function showCharacterDifference( $old, $new ) {
187 global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
188 $szdiff = $new - $old;
189
190 $code = $wgLang->getCode();
191 static $fastCharDiff = array();
192 if ( !isset($fastCharDiff[$code]) ) {
193 $fastCharDiff[$code] = $wgMiserMode || wfMsgNoTrans( 'rc-change-size' ) === '$1';
194 }
195
196 $formatedSize = $wgLang->formatNum($szdiff);
197
198 if ( !$fastCharDiff[$code] ) {
199 $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
200 }
201
202 if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
203 $tag = 'strong';
204 } else {
205 $tag = 'span';
206 }
207 if( $szdiff === 0 ) {
208 return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
209 } elseif( $szdiff > 0 ) {
210 return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
211 } else {
212 return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
213 }
214 }
215
216 /**
217 * Returns text for the end of RC
218 * @return string
219 */
220 public function endRecentChangesList() {
221 if( $this->rclistOpen ) {
222 return "</ul>\n";
223 } else {
224 return '';
225 }
226 }
227
228 protected function insertMove( &$s, $rc ) {
229 # Diff
230 $s .= '(' . $this->message['diff'] . ') (';
231 # Hist
232 $s .= $this->skin->link(
233 $rc->getMovedToTitle(),
234 $this->message['hist'],
235 array(),
236 array( 'action' => 'history' ),
237 array( 'known', 'noclasses' )
238 ) . ') . . ';
239 # "[[x]] moved to [[y]]"
240 $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
241 $s .= wfMsg(
242 $msg,
243 $this->skin->link(
244 $rc->getTitle(),
245 null,
246 array(),
247 array( 'redirect' => 'no' ),
248 array( 'known', 'noclasses' )
249 ),
250 $this->skin->link(
251 $rc->getMovedToTitle(),
252 null,
253 array(),
254 array(),
255 array( 'known', 'noclasses' )
256 )
257 );
258 }
259
260 protected function insertDateHeader( &$s, $rc_timestamp ) {
261 global $wgLang;
262 # Make date header if necessary
263 $date = $wgLang->date( $rc_timestamp, true, true );
264 if( $date != $this->lastdate ) {
265 if( '' != $this->lastdate ) {
266 $s .= "</ul>\n";
267 }
268 $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
269 $this->lastdate = $date;
270 $this->rclistOpen = true;
271 }
272 }
273
274 protected function insertLog( &$s, $title, $logtype ) {
275 $logname = LogPage::logName( $logtype );
276 $s .= '(' . $this->skin->link(
277 $title,
278 $logname,
279 array(),
280 array(),
281 array( 'known', 'noclasses' )
282 ) . ')';
283 }
284
285 protected function insertDiffHist( &$s, &$rc, $unpatrolled ) {
286 # Diff link
287 if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
288 $diffLink = $this->message['diff'];
289 } else if( !self::userCan($rc,Revision::DELETED_TEXT) ) {
290 $diffLink = $this->message['diff'];
291 } else {
292 $query = array(
293 'curid' => $rc->mAttribs['rc_cur_id'],
294 'diff' => $rc->mAttribs['rc_this_oldid'],
295 'oldid' => $rc->mAttribs['rc_last_oldid']
296 );
297
298 if( $unpatrolled ) {
299 $query['rcid'] = $rc->mAttribs['rc_id'];
300 };
301
302 $diffLink = $this->skin->link(
303 $rc->getTitle(),
304 $this->message['diff'],
305 array( 'tabindex' => $rc->counter ),
306 $query,
307 array( 'known', 'noclasses' )
308 );
309 }
310 $s .= '('.$diffLink.') (';
311 # History link
312 $s .= $this->skin->link(
313 $rc->getTitle(),
314 $this->message['hist'],
315 array(),
316 array(
317 'curid' => $rc->mAttribs['rc_cur_id'],
318 'action' => 'history'
319 ),
320 array( 'known', 'noclasses' )
321 );
322 $s .= ') . . ';
323 }
324
325 protected function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
326 global $wgContLang;
327 # If it's a new article, there is no diff link, but if it hasn't been
328 # patrolled yet, we need to give users a way to do so
329 $params = array();
330
331 if ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW ) {
332 $params['rcid'] = $rc->mAttribs['rc_id'];
333 }
334
335 if( $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
336 $articlelink = $this->skin->link(
337 $rc->getTitle(),
338 null,
339 array(),
340 $params,
341 array( 'known', 'noclasses' )
342 );
343 $articlelink = '<span class="history-deleted">' . $articlelink . '</span>';
344 } else {
345 $articlelink = ' '. $this->skin->link(
346 $rc->getTitle(),
347 null,
348 array(),
349 $params,
350 array( 'known', 'noclasses' )
351 );
352 }
353 # Bolden pages watched by this user
354 if( $watched ) {
355 $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
356 }
357 # RTL/LTR marker
358 $articlelink .= $wgContLang->getDirMark();
359
360 wfRunHooks( 'ChangesListInsertArticleLink',
361 array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched) );
362
363 $s .= " $articlelink";
364 }
365
366 protected function insertTimestamp( &$s, $rc ) {
367 global $wgLang;
368 $s .= $this->message['semicolon-separator'] .
369 $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
370 }
371
372 /** Insert links to user page, user talk page and eventually a blocking link */
373 public function insertUserRelatedLinks( &$s, &$rc ) {
374 if( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
375 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
376 } else {
377 $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
378 $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
379 }
380 }
381
382 /** insert a formatted action */
383 protected function insertAction( &$s, &$rc ) {
384 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
385 if( $this->isDeleted( $rc, LogPage::DELETED_ACTION ) ) {
386 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
387 } else {
388 $s .= ' '.LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
389 $rc->getTitle(), $this->skin, LogPage::extractParams( $rc->mAttribs['rc_params'] ), true, true );
390 }
391 }
392 }
393
394 /** insert a formatted comment */
395 protected function insertComment( &$s, &$rc ) {
396 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
397 if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
398 $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
399 } else {
400 $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
401 }
402 }
403 }
404
405 /**
406 * Check whether to enable recent changes patrol features
407 * @return bool
408 */
409 public static function usePatrol() {
410 global $wgUser;
411 return $wgUser->useRCPatrol();
412 }
413
414 /**
415 * Returns the string which indicates the number of watching users
416 */
417 protected function numberofWatchingusers( $count ) {
418 global $wgLang;
419 static $cache = array();
420 if( $count > 0 ) {
421 if( !isset( $cache[$count] ) ) {
422 $cache[$count] = wfMsgExt( 'number_of_watching_users_RCview',
423 array('parsemag', 'escape' ), $wgLang->formatNum( $count ) );
424 }
425 return $cache[$count];
426 } else {
427 return '';
428 }
429 }
430
431 /**
432 * Determine if said field of a revision is hidden
433 * @param RCCacheEntry $rc
434 * @param int $field one of DELETED_* bitfield constants
435 * @return bool
436 */
437 public static function isDeleted( $rc, $field ) {
438 return ( $rc->mAttribs['rc_deleted'] & $field ) == $field;
439 }
440
441 /**
442 * Determine if the current user is allowed to view a particular
443 * field of this revision, if it's marked as deleted.
444 * @param RCCacheEntry $rc
445 * @param int $field
446 * @return bool
447 */
448 public static function userCan( $rc, $field ) {
449 if( $rc->mAttribs['rc_deleted'] & $field ) {
450 global $wgUser;
451 $permission = '';
452 if ( $rc->mAttribs['rc_deleted'] & Revision::DELETED_RESTRICTED ) {
453 $permission = 'suppressrevision';
454 } elseif ( $field & Revision::DELETED_TEXT ) {
455 $permission = 'deletedtext';
456 } else {
457 $permission = 'deletedhistory';
458 }
459 wfDebug( "Checking for $permission due to $field match on {$rc->mAttribs['rc_deleted']}\n" );
460 return $wgUser->isAllowed( $permission );
461 } else {
462 return true;
463 }
464 }
465
466 protected function maybeWatchedLink( $link, $watched = false ) {
467 if( $watched ) {
468 return '<strong class="mw-watched">' . $link . '</strong>';
469 } else {
470 return '<span class="mw-rc-unwatched">' . $link . '</span>';
471 }
472 }
473
474 /** Inserts a rollback link */
475 public function insertRollback( &$s, &$rc ) {
476 global $wgUser;
477 if( !$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
478 $page = $rc->getTitle();
479 /** Check for rollback and edit permissions, disallow special pages, and only
480 * show a link on the top-most revision */
481 if ($wgUser->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
482 {
483 $rev = new Revision( array(
484 'id' => $rc->mAttribs['rc_this_oldid'],
485 'user' => $rc->mAttribs['rc_user'],
486 'user_text' => $rc->mAttribs['rc_user_text'],
487 'deleted' => $rc->mAttribs['rc_deleted']
488 ) );
489 $rev->setTitle( $page );
490 $s .= ' '.$this->skin->generateRollback( $rev );
491 }
492 }
493 }
494
495 public function insertTags( &$s, &$rc, &$classes ) {
496 if ( empty($rc->mAttribs['ts_tags']) )
497 return;
498
499 list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], 'changeslist' );
500 $classes = array_merge( $classes, $newClasses );
501 $s .= ' ' . $tagSummary;
502 }
503
504 public function insertExtra( &$s, &$rc, &$classes ) {
505 ## Empty, used for subclassers to add anything special.
506 }
507 }
508
509
510 /**
511 * Generate a list of changes using the good old system (no javascript)
512 */
513 class OldChangesList extends ChangesList {
514 /**
515 * Format a line using the old system (aka without any javascript).
516 */
517 public function recentChangesLine( &$rc, $watched = false, $linenumber = NULL ) {
518 global $wgLang, $wgRCShowChangedSize, $wgUser;
519 wfProfileIn( __METHOD__ );
520 # Should patrol-related stuff be shown?
521 $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs['rc_patrolled'];
522
523 $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
524 $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
525
526 $s = '';
527 $classes = array();
528 // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
529 if( $linenumber ) {
530 if( $linenumber & 1 ) {
531 $classes[] = 'mw-line-odd';
532 }
533 else {
534 $classes[] = 'mw-line-even';
535 }
536 }
537
538 // Moved pages
539 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
540 $this->insertMove( $s, $rc );
541 // Log entries
542 } elseif( $rc->mAttribs['rc_log_type'] ) {
543 $logtitle = Title::newFromText( 'Log/'.$rc->mAttribs['rc_log_type'], NS_SPECIAL );
544 $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
545 // Log entries (old format) or log targets, and special pages
546 } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
547 list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $rc->mAttribs['rc_title'] );
548 if( $name == 'Log' ) {
549 $this->insertLog( $s, $rc->getTitle(), $subpage );
550 }
551 // Regular entries
552 } else {
553 $this->insertDiffHist( $s, $rc, $unpatrolled );
554 # M, N, b and ! (minor, new, bot and unpatrolled)
555 $s .= $this->recentChangesFlags( $rc->mAttribs['rc_new'], $rc->mAttribs['rc_minor'],
556 $unpatrolled, '', $rc->mAttribs['rc_bot'] );
557 $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
558 }
559 # Edit/log timestamp
560 $this->insertTimestamp( $s, $rc );
561 # Bytes added or removed
562 if( $wgRCShowChangedSize ) {
563 $cd = $rc->getCharacterDifference();
564 if( $cd != '' ) {
565 $s .= "$cd . . ";
566 }
567 }
568 # User tool links
569 $this->insertUserRelatedLinks( $s, $rc );
570 # Log action text (if any)
571 $this->insertAction( $s, $rc );
572 # Edit or log comment
573 $this->insertComment( $s, $rc );
574 # Tags
575 $this->insertTags( $s, $rc, $classes );
576 # Rollback
577 $this->insertRollback( $s, $rc );
578 # For subclasses
579 $this->insertExtra( $s, $rc, $classes );
580
581 # How many users watch this page
582 if( $rc->numberofWatchingusers > 0 ) {
583 $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview',
584 array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers ) );
585 }
586
587 if( $this->watchlist ) {
588 $classes[] = Sanitizer::escapeClass( 'watchlist-'.$rc->mAttribs['rc_namespace'].'-'.$rc->mAttribs['rc_title'] );
589 }
590
591 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
592
593 wfProfileOut( __METHOD__ );
594 return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
595 }
596 }
597
598
599 /**
600 * Generate a list of changes using an Enhanced system (uses javascript).
601 */
602 class EnhancedChangesList extends ChangesList {
603 /**
604 * Add the JavaScript file for enhanced changeslist
605 * @ return string
606 */
607 public function beginRecentChangesList() {
608 global $wgStylePath, $wgStyleVersion;
609 $this->rc_cache = array();
610 $this->rcMoveIndex = 0;
611 $this->rcCacheIndex = 0;
612 $this->lastdate = '';
613 $this->rclistOpen = false;
614 $script = Html::linkedScript( $wgStylePath . "/common/enhancedchanges.js?$wgStyleVersion" );
615 return $script;
616 }
617 /**
618 * Format a line for enhanced recentchange (aka with javascript and block of lines).
619 */
620 public function recentChangesLine( &$baseRC, $watched = false ) {
621 global $wgLang, $wgUser;
622
623 wfProfileIn( __METHOD__ );
624
625 # Create a specialised object
626 $rc = RCCacheEntry::newFromParent( $baseRC );
627
628 # Extract fields from DB into the function scope (rc_xxxx variables)
629 // FIXME: Would be good to replace this extract() call with something
630 // that explicitly initializes variables.
631 extract( $rc->mAttribs );
632 $curIdEq = array( 'curid' => $rc_cur_id );
633
634 # If it's a new day, add the headline and flush the cache
635 $date = $wgLang->date( $rc_timestamp, true );
636 $ret = '';
637 if( $date != $this->lastdate ) {
638 # Process current cache
639 $ret = $this->recentChangesBlock();
640 $this->rc_cache = array();
641 $ret .= Xml::element( 'h4', null, $date );
642 $this->lastdate = $date;
643 }
644
645 # Should patrol-related stuff be shown?
646 if( $wgUser->useRCPatrol() ) {
647 $rc->unpatrolled = !$rc_patrolled;
648 } else {
649 $rc->unpatrolled = false;
650 }
651
652 $showdifflinks = true;
653 # Make article link
654 // Page moves
655 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
656 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
657 $clink = wfMsg( $msg, $this->skin->linkKnown( $rc->getTitle(), null,
658 array(), array( 'redirect' => 'no' ) ),
659 $this->skin->linkKnown( $rc->getMovedToTitle() ) );
660 // New unpatrolled pages
661 } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
662 $clink = $this->skin->linkKnown( $rc->getTitle(), null, array(),
663 array( 'rcid' => $rc_id ) );
664 // Log entries
665 } else if( $rc_type == RC_LOG ) {
666 if( $rc_log_type ) {
667 $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type );
668 $clink = '(' . $this->skin->linkKnown( $logtitle,
669 LogPage::logName($rc_log_type) ) . ')';
670 } else {
671 $clink = $this->skin->link( $rc->getTitle() );
672 }
673 $watched = false;
674 // Log entries (old format) and special pages
675 } elseif( $rc_namespace == NS_SPECIAL ) {
676 list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
677 if ( $specialName == 'Log' ) {
678 # Log updates, etc
679 $logname = LogPage::logName( $logtype );
680 $clink = '(' . $this->skin->linkKnown( $rc->getTitle(), $logname ) . ')';
681 } else {
682 wfDebug( "Unexpected special page in recentchanges\n" );
683 $clink = '';
684 }
685 // Edits
686 } else {
687 $clink = $this->skin->linkKnown( $rc->getTitle() );
688 }
689
690 # Don't show unusable diff links
691 if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
692 $showdifflinks = false;
693 }
694
695 $time = $wgLang->time( $rc_timestamp, true, true );
696 $rc->watched = $watched;
697 $rc->link = $clink;
698 $rc->timestamp = $time;
699 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
700
701 # Make "cur" and "diff" links. Do not use link(), it is too slow if
702 # called too many times (50% of CPU time on RecentChanges!).
703 if( $rc->unpatrolled ) {
704 $rcIdQuery = array( 'rcid' => $rc_id );
705 } else {
706 $rcIdQuery = array();
707 }
708 $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $rc_this_oldid );
709 $querydiff = $curIdEq + array( 'diff' => $rc_this_oldid, 'oldid' =>
710 $rc_last_oldid ) + $rcIdQuery;
711
712 if( !$showdifflinks ) {
713 $curLink = $this->message['cur'];
714 $diffLink = $this->message['diff'];
715 } else if( in_array( $rc_type, array(RC_NEW,RC_LOG,RC_MOVE,RC_MOVE_OVER_REDIRECT) ) ) {
716 if ( $rc_type != RC_NEW ) {
717 $curLink = $this->message['cur'];
718 } else {
719 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
720 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
721 }
722 $diffLink = $this->message['diff'];
723 } else {
724 $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
725 $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
726 $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
727 $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
728 }
729
730 # Make "last" link
731 if( !$showdifflinks || !$rc_last_oldid ) {
732 $lastLink = $this->message['last'];
733 } else if( $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
734 $lastLink = $this->message['last'];
735 } else {
736 $lastLink = $this->skin->linkKnown( $rc->getTitle(), $this->message['last'],
737 array(), $curIdEq + array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) + $rcIdQuery );
738 }
739
740 # Make user links
741 if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
742 $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
743 } else {
744 $rc->userlink = $this->skin->userLink( $rc_user, $rc_user_text );
745 $rc->usertalklink = $this->skin->userToolLinks( $rc_user, $rc_user_text );
746 }
747
748 $rc->lastlink = $lastLink;
749 $rc->curlink = $curLink;
750 $rc->difflink = $diffLink;
751
752 # Put accumulated information into the cache, for later display
753 # Page moves go on their own line
754 $title = $rc->getTitle();
755 $secureName = $title->getPrefixedDBkey();
756 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
757 # Use an @ character to prevent collision with page names
758 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
759 } else {
760 # Logs are grouped by type
761 if( $rc_type == RC_LOG ){
762 $secureName = SpecialPage::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
763 }
764 if( !isset( $this->rc_cache[$secureName] ) ) {
765 $this->rc_cache[$secureName] = array();
766 }
767
768 array_push( $this->rc_cache[$secureName], $rc );
769 }
770
771 wfProfileOut( __METHOD__ );
772
773 return $ret;
774 }
775
776 /**
777 * Enhanced RC group
778 */
779 protected function recentChangesBlockGroup( $block ) {
780 global $wgLang, $wgContLang, $wgRCShowChangedSize;
781
782 wfProfileIn( __METHOD__ );
783
784 $r = '<table class="mw-enhanced-rc"><tr>';
785
786 # Collate list of users
787 $userlinks = array();
788 # Other properties
789 $unpatrolled = false;
790 $isnew = false;
791 $curId = $currentRevision = 0;
792 # Some catalyst variables...
793 $namehidden = true;
794 $allLogs = true;
795 foreach( $block as $rcObj ) {
796 $oldid = $rcObj->mAttribs['rc_last_oldid'];
797 if( $rcObj->mAttribs['rc_new'] ) {
798 $isnew = true;
799 }
800 // If all log actions to this page were hidden, then don't
801 // give the name of the affected page for this block!
802 if( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
803 $namehidden = false;
804 }
805 $u = $rcObj->userlink;
806 if( !isset( $userlinks[$u] ) ) {
807 $userlinks[$u] = 0;
808 }
809 if( $rcObj->unpatrolled ) {
810 $unpatrolled = true;
811 }
812 if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
813 $allLogs = false;
814 }
815 # Get the latest entry with a page_id and oldid
816 # since logs may not have these.
817 if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
818 $curId = $rcObj->mAttribs['rc_cur_id'];
819 }
820 if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
821 $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
822 }
823
824 $bot = $rcObj->mAttribs['rc_bot'];
825 $userlinks[$u]++;
826 }
827
828 # Sort the list and convert to text
829 krsort( $userlinks );
830 asort( $userlinks );
831 $users = array();
832 foreach( $userlinks as $userlink => $count) {
833 $text = $userlink;
834 $text .= $wgContLang->getDirMark();
835 if( $count > 1 ) {
836 $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
837 }
838 array_push( $users, $text );
839 }
840
841 $users = ' <span class="changedby">[' .
842 implode( $this->message['semicolon-separator'], $users ) . ']</span>';
843
844 # ID for JS visibility toggle
845 $jsid = $this->rcCacheIndex;
846 # onclick handler to toggle hidden/expanded
847 $toggleLink = "onclick='toggleVisibility($jsid); return false'";
848 # Title for <a> tags
849 $expandTitle = htmlspecialchars( wfMsg( 'rc-enhanced-expand' ) );
850 $closeTitle = htmlspecialchars( wfMsg( 'rc-enhanced-hide' ) );
851
852 $tl = "<span id='mw-rc-openarrow-$jsid' class='mw-changeslist-expanded' style='visibility:hidden'><a href='#' $toggleLink title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
853 $tl .= "<span id='mw-rc-closearrow-$jsid' class='mw-changeslist-hidden' style='display:none'><a href='#' $toggleLink title='$closeTitle'>" . $this->downArrow() . "</a></span>";
854 $r .= '<td class="mw-enhanced-rc">'.$tl.'&nbsp;';
855
856 # Main line
857 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
858
859 # Timestamp
860 $r .= '&nbsp;'.$block[0]->timestamp.'&nbsp;</td><td style="padding:0px;">';
861
862 # Article link
863 if( $namehidden ) {
864 $r .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
865 } else if( $allLogs ) {
866 $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
867 } else {
868 $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
869 }
870
871 $r .= $wgContLang->getDirMark();
872
873 $queryParams['curid'] = $curId;
874 # Changes message
875 $n = count($block);
876 static $nchanges = array();
877 if ( !isset( $nchanges[$n] ) ) {
878 $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) );
879 }
880 # Total change link
881 $r .= ' ';
882 if( !$allLogs ) {
883 $r .= '(';
884 if( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT ) ) {
885 $r .= $nchanges[$n];
886 } else if( $isnew ) {
887 $r .= $nchanges[$n];
888 } else {
889 $params = $queryParams;
890 $params['diff'] = $currentRevision;
891 $params['oldid'] = $oldid;
892
893 $r .= $this->skin->link(
894 $block[0]->getTitle(),
895 $nchanges[$n],
896 array(),
897 $params,
898 array( 'known', 'noclasses' )
899 );
900 }
901 }
902
903 # History
904 if( $allLogs ) {
905 // don't show history link for logs
906 } else if( $namehidden || !$block[0]->getTitle()->exists() ) {
907 $r .= $this->message['pipe-separator'] . $this->message['hist'] . ')';
908 } else {
909 $params = $queryParams;
910 $params['action'] = 'history';
911
912 $r .= $this->message['pipe-separator'] .
913 $this->skin->link(
914 $block[0]->getTitle(),
915 $this->message['hist'],
916 array(),
917 $params,
918 array( 'known', 'noclasses' )
919 ) . ')';
920 }
921 $r .= ' . . ';
922
923 # Character difference (does not apply if only log items)
924 if( $wgRCShowChangedSize && !$allLogs ) {
925 $last = 0;
926 $first = count($block) - 1;
927 # Some events (like logs) have an "empty" size, so we need to skip those...
928 while( $last < $first && $block[$last]->mAttribs['rc_new_len'] === NULL ) {
929 $last++;
930 }
931 while( $first > $last && $block[$first]->mAttribs['rc_old_len'] === NULL ) {
932 $first--;
933 }
934 # Get net change
935 $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
936 $block[$last]->mAttribs['rc_new_len'] );
937
938 if( $chardiff == '' ) {
939 $r .= ' ';
940 } else {
941 $r .= ' ' . $chardiff. ' . . ';
942 }
943 }
944
945 $r .= $users;
946 $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
947
948 $r .= "</td></tr></table>\n";
949
950 # Sub-entries
951 $r .= '<div id="mw-rc-subentries-'.$jsid.'" class="mw-changeslist-hidden">';
952 $r .= '<table class="mw-enhanced-rc">';
953 foreach( $block as $rcObj ) {
954 # Extract fields from DB into the function scope (rc_xxxx variables)
955 // FIXME: Would be good to replace this extract() call with something
956 // that explicitly initializes variables.
957 # Classes to apply -- TODO implement
958 $classes = array();
959 extract( $rcObj->mAttribs );
960
961 #$r .= '<tr><td valign="top">'.$this->spacerArrow();
962 $r .= '<tr><td style="vertical-align:top;font-family:monospace; padding:0px;">';
963 $r .= $this->spacerIndent() . $this->spacerIndent();
964 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
965 $r .= '&nbsp;</td><td style="vertical-align:top; padding:0px;"><span style="font-family:monospace">';
966
967 $params = $queryParams;
968
969 if( $rc_this_oldid != 0 ) {
970 $params['oldid'] = $rc_this_oldid;
971 }
972
973 # Log timestamp
974 if( $rc_type == RC_LOG ) {
975 $link = $rcObj->timestamp;
976 # Revision link
977 } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
978 $link = '<span class="history-deleted">'.$rcObj->timestamp.'</span> ';
979 } else {
980 if ( $rcObj->unpatrolled && $rc_type == RC_NEW) {
981 $params['rcid'] = $rcObj->mAttribs['rc_id'];
982 }
983
984 $link = $this->skin->link(
985 $rcObj->getTitle(),
986 $rcObj->timestamp,
987 array(),
988 $params,
989 array( 'known', 'noclasses' )
990 );
991 if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
992 $link = '<span class="history-deleted">'.$link.'</span> ';
993 }
994 $r .= $link . '</span>';
995
996 if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
997 $r .= ' (';
998 $r .= $rcObj->curlink;
999 $r .= $this->message['pipe-separator'];
1000 $r .= $rcObj->lastlink;
1001 $r .= ')';
1002 }
1003 $r .= ' . . ';
1004
1005 # Character diff
1006 if( $wgRCShowChangedSize ) {
1007 $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
1008 }
1009 # User links
1010 $r .= $rcObj->userlink;
1011 $r .= $rcObj->usertalklink;
1012 // log action
1013 $this->insertAction( $r, $rcObj );
1014 // log comment
1015 $this->insertComment( $r, $rcObj );
1016 # Rollback
1017 $this->insertRollback( $r, $rcObj );
1018 # Tags
1019 $this->insertTags( $r, $rcObj, $classes );
1020
1021 $r .= "</td></tr>\n";
1022 }
1023 $r .= "</table></div>\n";
1024
1025 $this->rcCacheIndex++;
1026
1027 wfProfileOut( __METHOD__ );
1028
1029 return $r;
1030 }
1031
1032 /**
1033 * Generate HTML for an arrow or placeholder graphic
1034 * @param string $dir one of '', 'd', 'l', 'r'
1035 * @param string $alt text
1036 * @param string $title text
1037 * @return string HTML <img> tag
1038 */
1039 protected function arrow( $dir, $alt='', $title='' ) {
1040 global $wgStylePath;
1041 $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
1042 $encAlt = htmlspecialchars( $alt );
1043 $encTitle = htmlspecialchars( $title );
1044 return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
1045 }
1046
1047 /**
1048 * Generate HTML for a right- or left-facing arrow,
1049 * depending on language direction.
1050 * @return string HTML <img> tag
1051 */
1052 protected function sideArrow() {
1053 global $wgContLang;
1054 $dir = $wgContLang->isRTL() ? 'l' : 'r';
1055 return $this->arrow( $dir, '+', wfMsg( 'rc-enhanced-expand' ) );
1056 }
1057
1058 /**
1059 * Generate HTML for a down-facing arrow
1060 * depending on language direction.
1061 * @return string HTML <img> tag
1062 */
1063 protected function downArrow() {
1064 return $this->arrow( 'd', '-', wfMsg( 'rc-enhanced-hide' ) );
1065 }
1066
1067 /**
1068 * Generate HTML for a spacer image
1069 * @return string HTML <img> tag
1070 */
1071 protected function spacerArrow() {
1072 return $this->arrow( '', codepointToUtf8( 0xa0 ) ); // non-breaking space
1073 }
1074
1075 /**
1076 * Add a set of spaces
1077 * @return string HTML <td> tag
1078 */
1079 protected function spacerIndent() {
1080 return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1081 }
1082
1083 /**
1084 * Enhanced RC ungrouped line.
1085 * @return string a HTML formated line (generated using $r)
1086 */
1087 protected function recentChangesBlockLine( $rcObj ) {
1088 global $wgRCShowChangedSize;
1089
1090 wfProfileIn( __METHOD__ );
1091
1092 # Extract fields from DB into the function scope (rc_xxxx variables)
1093 // FIXME: Would be good to replace this extract() call with something
1094 // that explicitly initializes variables.
1095 $classes = array(); // TODO implement
1096 extract( $rcObj->mAttribs );
1097 $query['curid'] = $rc_cur_id;
1098
1099 $r = '<table class="mw-enhanced-rc"><tr>';
1100 $r .= '<td class="mw-enhanced-rc">' . $this->spacerArrow() . '&nbsp;';
1101 # Flag and Timestamp
1102 if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
1103 $r .= '&nbsp;&nbsp;&nbsp;&nbsp;'; // 4 flags -> 4 spaces
1104 } else {
1105 $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
1106 }
1107 $r .= '&nbsp;'.$rcObj->timestamp.'&nbsp;</td><td style="padding:0px;">';
1108 # Article or log link
1109 if( $rc_log_type ) {
1110 $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
1111 $logname = LogPage::logName( $rc_log_type );
1112 $r .= '(' . $this->skin->link(
1113 $logtitle,
1114 $logname,
1115 array(),
1116 array(),
1117 array( 'known', 'noclasses' )
1118 ) . ')';
1119 } else {
1120 $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
1121 }
1122 # Diff and hist links
1123 if ( $rc_type != RC_LOG ) {
1124 $r .= ' ('. $rcObj->difflink . $this->message['pipe-separator'];
1125 $query['action'] = 'history';
1126 $r .= $this->skin->link(
1127 $rcObj->getTitle(),
1128 $this->message['hist'],
1129 array(),
1130 $query,
1131 array( 'known', 'noclasses' )
1132 ) . ')';
1133 }
1134 $r .= ' . . ';
1135 # Character diff
1136 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
1137 $r .= "$cd . . ";
1138 }
1139 # User/talk
1140 $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
1141 # Log action (if any)
1142 if( $rc_log_type ) {
1143 if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
1144 $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1145 } else {
1146 $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(),
1147 $this->skin, LogPage::extractParams($rc_params), true, true );
1148 }
1149 }
1150 $this->insertComment( $r, $rcObj );
1151 $this->insertRollback( $r, $rcObj );
1152 # Tags
1153 $this->insertTags( $r, $rcObj, $classes );
1154 # Show how many people are watching this if enabled
1155 $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
1156
1157 $r .= "</td></tr></table>\n";
1158
1159 wfProfileOut( __METHOD__ );
1160
1161 return $r;
1162 }
1163
1164 /**
1165 * If enhanced RC is in use, this function takes the previously cached
1166 * RC lines, arranges them, and outputs the HTML
1167 */
1168 protected function recentChangesBlock() {
1169 if( count ( $this->rc_cache ) == 0 ) {
1170 return '';
1171 }
1172
1173 wfProfileIn( __METHOD__ );
1174
1175 $blockOut = '';
1176 foreach( $this->rc_cache as $block ) {
1177 if( count( $block ) < 2 ) {
1178 $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
1179 } else {
1180 $blockOut .= $this->recentChangesBlockGroup( $block );
1181 }
1182 }
1183
1184 wfProfileOut( __METHOD__ );
1185
1186 return '<div>'.$blockOut.'</div>';
1187 }
1188
1189 /**
1190 * Returns text for the end of RC
1191 * If enhanced RC is in use, returns pretty much all the text
1192 */
1193 public function endRecentChangesList() {
1194 return $this->recentChangesBlock() . parent::endRecentChangesList();
1195 }
1196
1197 }