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