Reactivate the cutoff date in the watchlist to speed up performance, hopefully; chang...
[lhc/web/wiklou.git] / includes / SpecialWatchlist.php
1 <?
2 global $IP;
3 include_once( "$IP/SpecialRecentchanges.php" );
4
5 function wfSpecialWatchlist()
6 {
7 global $wgUser, $wgOut, $wgLang, $wgTitle;
8 global $days, $limit, $target; # From query string
9 $fname = "wfSpecialWatchlist";
10
11 $wgOut->setPagetitle( wfMsg( "watchlist" ) );
12 $sub = str_replace( "$1", $wgUser->getName(), wfMsg( "watchlistsub" ) );
13 $wgOut->setSubtitle( $sub );
14 $wgOut->setRobotpolicy( "index,follow" );
15
16 if ( ! isset( $days ) ) {
17 /*
18 $days = $wgUser->getOption( "rcdays" );
19 if ( ! $days ) { $days = 3; }
20 */
21 $days = 7;
22 }
23 $days = (int)$days;
24 list( $limit, $offset ) = wfCheckLimits( 100, "rclimit" );
25
26 if ( $days <= 0 ) {
27 $docutoff = '';
28 } else {
29 $docutoff = "cur_timestamp > '" .
30 wfUnix2Timestamp( time() - ( $days * 86400 ) )
31 . "' AND";
32 }
33 if ( $limit == 0 ) {
34 $dolimit = "";
35 } else {
36 $dolimit = "LIMIT $limit";
37 }
38
39 $uid = $wgUser->getID();
40 if( $uid == 0 ) {
41 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
42 return;
43 }
44
45 $sql = "SELECT DISTINCT
46 cur_id,cur_namespace,cur_title,cur_comment,
47 cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new
48 FROM cur,watchlist
49 WHERE wl_user={$uid} AND wl_title=cur_title
50 AND {$docutoff} (cur_namespace=wl_namespace OR cur_namespace=wl_namespace+1)
51 ORDER BY inverse_timestamp {$dolimit}";
52 $res = wfQuery( $sql, $fname );
53 if ( wfNumRows( $res ) == 0 ) {
54 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
55 return;
56 }
57
58 $note = wfMsg( "rcnote", $limit, $days );
59 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
60 $note = rcDayLimitlinks( $days, $limit, "Watchlist", "", true );
61 $wgOut->addHTML( "{$note}\n" );
62
63 $sk = $wgUser->getSkin();
64 $s = $sk->beginRecentChangesList();
65
66 while ( $obj = wfFetchObject( $res ) ) {
67 $ts = $obj->cur_timestamp;
68 $u = $obj->cur_user;
69 $ut = $obj->cur_user_text;
70 $ns = $obj->cur_namespace;
71 $ttl = $obj->cur_title;
72 $com = $obj->cur_comment;
73 $me = ( $obj->cur_minor_edit > 0 );
74 $new = ( $obj->cur_is_new > 0 );
75 $watched = true;
76
77 $s .= $sk->recentChangesLine( $ts, $u, $ut, $ns, $ttl, $com, $me, $new, $watched );
78 }
79 $s .= $sk->endRecentChangesList();
80
81 wfFreeResult( $res );
82 $wgOut->addHTML( $s );
83 }
84
85 ?>