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