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