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