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