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