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