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