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