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