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