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