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