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