really fix that enhanced rc changes link
[lhc/web/wiklou.git] / includes / ChangesList.php
1 <?php
2 /**
3 * @package MediaWiki
4 */
5
6 /**
7 * @package MediaWiki
8 */
9 class ChangesList {
10 # Called by history lists and recent changes
11 #
12
13 /** @todo document */
14 function ChangesList( &$skin ) {
15 $this->skin =& $skin;
16 }
17
18 /**
19 * Returns the appropiate flags for new page, minor change and patrolling
20 */
21 function recentChangesFlags( $new, $minor, $patrolled, $nothing = '&nbsp;' ) {
22 $f = $new ? '<span class="newpage">' . htmlspecialchars( wfMsg( 'newpageletter' ) ) . '</span>'
23 : $nothing;
24 $f .= $minor ? '<span class="minor">' . htmlspecialchars( wfMsg( 'minoreditletter' ) ) . '</span>'
25 : $nothing;
26 $f .= $patrolled ? '<span class="unpatrolled">!</span>' : $nothing;
27 return $f;
28
29 }
30
31 /**
32 * Returns text for the start of the tabular part of RC
33 */
34 function beginRecentChangesList() {
35 $this->rc_cache = array() ;
36 $this->rcMoveIndex = 0;
37 $this->rcCacheIndex = 0 ;
38 $this->lastdate = '';
39 $this->rclistOpen = false;
40 return '';
41 }
42
43 /**
44 * Returns text for the end of RC
45 * If enhanced RC is in use, returns pretty much all the text
46 */
47 function endRecentChangesList() {
48 $s = $this->recentChangesBlock() ;
49 if( $this->rclistOpen ) {
50 $s .= "</ul>\n";
51 }
52 return $s;
53 }
54
55 /**
56 * Enhanced RC ungrouped line
57 */
58 function recentChangesBlockLine ( $rcObj ) {
59 global $wgStylePath, $wgContLang ;
60
61 # Get rc_xxxx variables
62 extract( $rcObj->mAttribs ) ;
63 $curIdEq = 'curid='.$rc_cur_id;
64
65 # Spacer image
66 $r = '' ;
67
68 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" border="0" />' ;
69 $r .= '<tt>' ;
70
71 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
72 $r .= '&nbsp;&nbsp;&nbsp;';
73 } else {
74 $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled );
75 }
76
77 # Timestamp
78 $r .= ' '.$rcObj->timestamp.' ' ;
79 $r .= '</tt>' ;
80
81 # Article link
82 $link = $rcObj->link ;
83 if ( $rcObj->watched ) $link = '<strong>'.$link.'</strong>' ;
84 $r .= $link ;
85
86 # Diff
87 $r .= ' (' ;
88 $r .= $rcObj->difflink ;
89 $r .= '; ' ;
90
91 # Hist
92 $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
93
94 # User/talk
95 $r .= ') . . '.$rcObj->userlink ;
96 $r .= $rcObj->usertalklink ;
97
98 # Comment
99 if ( $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
100 $r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() );
101 }
102
103 if ($rcObj->numberofWatchingusers > 0) {
104 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rcObj->numberofWatchingusers));
105 }
106
107 $r .= "<br />\n" ;
108 return $r ;
109 }
110
111 /**
112 * Enhanced RC group
113 */
114 function recentChangesBlockGroup ( $block ) {
115 global $wgStylePath, $wgContLang ;
116
117 $r = '';
118
119 # Collate list of users
120 $isnew = false ;
121 $unpatrolled = false;
122 $userlinks = array () ;
123 foreach ( $block AS $rcObj ) {
124 $oldid = $rcObj->mAttribs['rc_last_oldid'];
125 $newid = $rcObj->mAttribs['rc_this_oldid'];
126 if ( $rcObj->mAttribs['rc_new'] ) {
127 $isnew = true ;
128 }
129 $u = $rcObj->userlink ;
130 if ( !isset ( $userlinks[$u] ) ) {
131 $userlinks[$u] = 0 ;
132 }
133 if ( $rcObj->unpatrolled ) {
134 $unpatrolled = true;
135 }
136 $userlinks[$u]++ ;
137 }
138
139 # Sort the list and convert to text
140 krsort ( $userlinks ) ;
141 asort ( $userlinks ) ;
142 $users = array () ;
143 foreach ( $userlinks as $userlink => $count) {
144 $text = $userlink ;
145 if ( $count > 1 ) $text .= " ({$count}&times;)" ;
146 array_push ( $users , $text ) ;
147 }
148 $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
149
150 # Arrow
151 $rci = 'RCI'.$this->rcCacheIndex ;
152 $rcl = 'RCL'.$this->rcCacheIndex ;
153 $rcm = 'RCM'.$this->rcCacheIndex ;
154 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ;
155 $arrowdir = $wgContLang->isRTL() ? 'l' : 'r';
156 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" alt="+" /></a></span>' ;
157 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_d.png" width="12" height="12" alt="-" /></a></span>' ;
158 $r .= $tl ;
159
160 # Main line
161
162 $r .= '<tt>' ;
163 $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled );
164
165 # Timestamp
166 $r .= ' '.$block[0]->timestamp.' ' ;
167 $r .= '</tt>' ;
168
169 # Article link
170 $link = $block[0]->link ;
171 if ( $block[0]->watched ) $link = '<strong>'.$link.'</strong>' ;
172 $r .= $link ;
173
174 $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id'];
175 $currentRevision = $block[0]->mAttribs['rc_this_oldid'];
176 if ( $block[0]->mAttribs['rc_type'] != RC_LOG ) {
177 # Changes
178 $r .= ' ('.count($block).' ' ;
179 if ( $isnew ) $r .= wfMsg('changes');
180 else $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle() , wfMsg('changes') ,
181 $curIdEq."&diff=$currentRevision&oldid=$oldid" ) ;
182 $r .= '; ' ;
183
184 # History
185 $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' );
186 $r .= ')' ;
187 }
188
189 $r .= $users ;
190
191 if ($block[0]->numberofWatchingusers > 0) {
192 $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($block[0]->numberofWatchingusers));
193 }
194 $r .= "<br />\n" ;
195
196 # Sub-entries
197 $r .= '<div id="'.$rci.'" style="display:none">' ;
198 foreach ( $block AS $rcObj ) {
199 # Get rc_xxxx variables
200 extract( $rcObj->mAttribs );
201
202 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" />';
203 $r .= '<tt>&nbsp; &nbsp; &nbsp; &nbsp;' ;
204 $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled );
205 $r .= '&nbsp;</tt>' ;
206
207 $o = '' ;
208 if ( $rc_last_oldid != 0 ) {
209 $o = 'oldid='.$rc_last_oldid ;
210 }
211 if ( $rc_type == RC_LOG ) {
212 $link = $rcObj->timestamp ;
213 } else {
214 $link = $this->skin->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp , "{$curIdEq}&$o" ) ;
215 }
216 $link = '<tt>'.$link.'</tt>' ;
217
218 $r .= $link ;
219 $r .= ' (' ;
220 $r .= $rcObj->curlink ;
221 $r .= '; ' ;
222 $r .= $rcObj->lastlink ;
223 $r .= ') . . '.$rcObj->userlink ;
224 $r .= $rcObj->usertalklink ;
225 $r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() );
226 $r .= "<br />\n" ;
227 }
228 $r .= "</div>\n" ;
229
230 $this->rcCacheIndex++ ;
231 return $r ;
232 }
233
234 /**
235 * If enhanced RC is in use, this function takes the previously cached
236 * RC lines, arranges them, and outputs the HTML
237 */
238 function recentChangesBlock () {
239 global $wgStylePath ;
240 if ( count ( $this->rc_cache ) == 0 ) return '' ;
241 $blockOut = '';
242 foreach ( $this->rc_cache AS $secureName => $block ) {
243 if ( count ( $block ) < 2 ) {
244 $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ;
245 } else {
246 $blockOut .= $this->recentChangesBlockGroup ( $block ) ;
247 }
248 }
249
250 return '<div>'.$blockOut.'</div>' ;
251 }
252
253 /**
254 * Called in a loop over all displayed RC entries
255 * Either returns the line, or caches it for later use
256 */
257 function recentChangesLine( &$rc, $watched = false ) {
258 global $wgUser;
259 $usenew = $wgUser->getOption( 'usenewrc' );
260 if ( $usenew )
261 $line = $this->recentChangesLineNew ( $rc, $watched ) ;
262 else
263 $line = $this->recentChangesLineOld ( $rc, $watched ) ;
264 return $line ;
265 }
266
267
268 function recentChangesLineOld( &$rc, $watched = false ) {
269 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgUseRCPatrol,
270 $wgOnlySysopsCanPatrol, $wgSysopUserBans;
271
272 $fname = 'Skin::recentChangesLineOld';
273 wfProfileIn( $fname );
274
275 static $message;
276 if( !isset( $message ) ) {
277 foreach( explode(' ', 'diff hist minoreditletter newpageletter blocklink' ) as $msg ) {
278 $message[$msg] = wfMsg( $msg );
279 }
280 }
281
282 # Extract DB fields into local scope
283 extract( $rc->mAttribs );
284 $curIdEq = 'curid=' . $rc_cur_id;
285
286 # Should patrol-related stuff be shown?
287 $unpatrolled = $wgUseRCPatrol && $wgUser->isLoggedIn() &&
288 ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') ) && $rc_patrolled == 0;
289
290 # Make date header if necessary
291 $date = $wgLang->date( $rc_timestamp, true, true );
292 $s = '';
293 if ( $date != $this->lastdate ) {
294 if ( '' != $this->lastdate ) { $s .= "</ul>\n"; }
295 $s .= "<h4>{$date}</h4>\n<ul class=\"special\">";
296 $this->lastdate = $date;
297 $this->rclistOpen = true;
298 }
299
300 $s .= '<li>';
301
302 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
303 # Diff
304 $s .= '(' . $message['diff'] . ') (';
305 # Hist
306 $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $message['hist'], 'action=history' ) .
307 ') . . ';
308
309 # "[[x]] moved to [[y]]"
310 $msg = ( $rc_type == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
311 $s .= wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
312 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
313 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
314 # Log updates, etc
315 $logtype = $matches[1];
316 $logname = LogPage::logName( $logtype );
317 $s .= '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
318 } else {
319 wfProfileIn("$fname-page");
320 # Diff link
321 if ( $rc_type == RC_NEW || $rc_type == RC_LOG ) {
322 $diffLink = $message['diff'];
323 } else {
324 if ( $unpatrolled )
325 $rcidparam = "&rcid={$rc_id}";
326 else
327 $rcidparam = "";
328 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $message['diff'],
329 "{$curIdEq}&diff={$rc_this_oldid}&oldid={$rc_last_oldid}{$rcidparam}",
330 '', '', ' tabindex="'.$rc->counter.'"');
331 }
332 $s .= '('.$diffLink.') (';
333
334 # History link
335 $s .= $this->skin->makeKnownLinkObj( $rc->getTitle(), $message['hist'], $curIdEq.'&action=history' );
336 $s .= ') . . ';
337
338 # M, N and ! (minor, new and unpatrolled)
339 $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '' );
340
341 # Article link
342 # If it's a new article, there is no diff link, but if it hasn't been
343 # patrolled yet, we need to give users a way to do so
344 if ( $unpatrolled && $rc_type == RC_NEW )
345 $articleLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
346 else
347 $articleLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' );
348
349 if ( $watched ) {
350 $articleLink = '<strong>'.$articleLink.'</strong>';
351 }
352
353 $s .= ' '.$articleLink;
354 wfProfileOut("$fname-page");
355 }
356
357 wfProfileIn( "$fname-rest" );
358 # Timestamp
359 $s .= '; ' . $wgLang->time( $rc_timestamp, true, true ) . ' . . ';
360
361 # User link (or contributions for unregistered users)
362 if ( 0 == $rc_user ) {
363 $contribsPage =& Title::makeTitle( NS_SPECIAL, 'Contributions' );
364 $userLink = $this->skin->makeKnownLinkObj( $contribsPage,
365 $rc_user_text, 'target=' . $rc_user_text );
366 } else {
367 $userPage =& Title::makeTitle( NS_USER, $rc_user_text );
368 $userLink = $this->skin->makeLinkObj( $userPage, $rc_user_text );
369 }
370 $s .= $userLink;
371
372 # User talk link
373 $talkname = $wgContLang->getNsText(NS_TALK); # use the shorter name
374 global $wgDisableAnonTalk;
375 if( 0 == $rc_user && $wgDisableAnonTalk ) {
376 $userTalkLink = '';
377 } else {
378 $userTalkPage =& Title::makeTitle( NS_USER_TALK, $rc_user_text );
379 $userTalkLink= $this->skin->makeLinkObj( $userTalkPage, $talkname );
380 }
381 # Block link
382 $blockLink='';
383 if ( ( $wgSysopUserBans || 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
384 $blockLinkPage = Title::makeTitle( NS_SPECIAL, 'Blockip' );
385 $blockLink = $this->skin->makeKnownLinkObj( $blockLinkPage,
386 $message['blocklink'], 'ip='.$rc_user_text );
387
388 }
389 if($blockLink) {
390 if($userTalkLink) $userTalkLink .= ' | ';
391 $userTalkLink .= $blockLink;
392 }
393 if($userTalkLink) $s.=' ('.$userTalkLink.')';
394
395 # Add comment
396 if ( $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
397 $s .= $this->skin->commentBlock( $rc_comment, $rc->getTitle() );
398 }
399
400 if ($rc->numberofWatchingusers > 0) {
401 $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers));
402 }
403
404 $s .= "</li>\n";
405
406 wfProfileOut( "$fname-rest" );
407 wfProfileOut( $fname );
408 return $s;
409 }
410
411 function recentChangesLineNew( &$baseRC, $watched = false ) {
412 global $wgTitle, $wgLang, $wgContLang, $wgUser,
413 $wgUseRCPatrol, $wgOnlySysopsCanPatrol, $wgSysopUserBans;
414
415 static $message;
416 if( !isset( $message ) ) {
417 foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last blocklink' ) as $msg ) {
418 $message[$msg] = wfMsg( $msg );
419 }
420 }
421
422 # Create a specialised object
423 $rc = RCCacheEntry::newFromParent( $baseRC ) ;
424
425 # Extract fields from DB into the function scope (rc_xxxx variables)
426 extract( $rc->mAttribs );
427 $curIdEq = 'curid=' . $rc_cur_id;
428
429 # If it's a new day, add the headline and flush the cache
430 $date = $wgLang->date( $rc_timestamp, true);
431 $ret = '';
432 if ( $date != $this->lastdate ) {
433 # Process current cache
434 $ret = $this->recentChangesBlock () ;
435 $this->rc_cache = array() ;
436 $ret .= "<h4>{$date}</h4>\n";
437 $this->lastdate = $date;
438 }
439
440 # Should patrol-related stuff be shown?
441 if ( $wgUseRCPatrol && $wgUser->isLoggedIn() &&
442 ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') )) {
443 $rc->unpatrolled = !$rc_patrolled;
444 } else {
445 $rc->unpatrolled = false;
446 }
447
448 # Make article link
449 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
450 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
451 $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
452 $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
453 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
454 # Log updates, etc
455 $logtype = $matches[1];
456 $logname = LogPage::logName( $logtype );
457 $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
458 } elseif ( $rc->unpatrolled && $rc_type == RC_NEW ) {
459 # Unpatrolled new page, give rc_id in query
460 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
461 } else {
462 $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' ) ;
463 }
464
465 $time = $wgContLang->time( $rc_timestamp, true, true );
466 $rc->watched = $watched ;
467 $rc->link = $clink ;
468 $rc->timestamp = $time;
469 $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
470
471 # Make "cur" and "diff" links
472 $titleObj = $rc->getTitle();
473 if ( $rc->unpatrolled ) {
474 $rcIdQuery = "&rcid={$rc_id}";
475 } else {
476 $rcIdQuery = '';
477 }
478 if ( ( $rc_type == RC_NEW && $rc_this_oldid == 0 ) || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
479 $curLink = $message['cur'];
480 $diffLink = $message['diff'];
481 } else {
482 # $query = $curIdEq.'&diff=0&oldid='.$rc_this_oldid;
483 $query = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid";
484 $aprops = ' tabindex="'.$baseRC->counter.'"';
485 $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $message['cur'], $query, '' ,'' , $aprops );
486 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $message['diff'], $query . $rcIdQuery, '' ,'' , $aprops );
487 }
488
489 # Make "last" link
490 if ( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
491 $lastLink = $message['last'];
492 } else {
493 $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $message['last'],
494 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
495 }
496
497 # Make user link (or user contributions for unregistered users)
498 if ( $rc_user == 0 ) {
499 $contribsPage =& Title::makeTitle( NS_SPECIAL, 'Contributions' );
500 $userLink = $this->skin->makeKnownLinkObj( $contribsPage,
501 $rc_user_text, 'target=' . $rc_user_text );
502 } else {
503 $userPage =& Title::makeTitle( NS_USER, $rc_user_text );
504 $userLink = $this->skin->makeLinkObj( $userPage, $rc_user_text );
505 }
506
507 $rc->userlink = $userLink;
508 $rc->lastlink = $lastLink;
509 $rc->curlink = $curLink;
510 $rc->difflink = $diffLink;
511
512 # Make user talk link
513 $talkname = $wgContLang->getNsText( NS_TALK ); # use the shorter name
514 $userTalkPage =& Title::makeTitle( NS_USER_TALK, $rc_user_text );
515 $userTalkLink = $this->skin->makeLinkObj( $userTalkPage, $talkname );
516
517 global $wgDisableAnonTalk;
518 if ( ( $wgSysopUserBans || 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
519 $blockPage =& Title::makeTitle( NS_SPECIAL, 'Blockip' );
520 $blockLink = $this->skin->makeKnownLinkObj( $blockPage,
521 $message['blocklink'], 'ip='.$rc_user_text );
522 if( $wgDisableAnonTalk )
523 $rc->usertalklink = ' ('.$blockLink.')';
524 else
525 $rc->usertalklink = ' ('.$userTalkLink.' | '.$blockLink.')';
526 } else {
527 if( $wgDisableAnonTalk && ($rc_user == 0) )
528 $rc->usertalklink = '';
529 else
530 $rc->usertalklink = ' ('.$userTalkLink.')';
531 }
532
533 # Put accumulated information into the cache, for later display
534 # Page moves go on their own line
535 $title = $rc->getTitle();
536 $secureName = $title->getPrefixedDBkey();
537 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
538 # Use an @ character to prevent collision with page names
539 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
540 } else {
541 if ( !isset ( $this->rc_cache[$secureName] ) ) $this->rc_cache[$secureName] = array() ;
542 array_push ( $this->rc_cache[$secureName] , $rc ) ;
543 }
544 return $ret;
545 }
546
547 }
548 ?>