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