Option to hide logged in users
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?
2
3 function wfSpecialRecentchanges( $par )
4 {
5 global $wgUser, $wgOut, $wgLang, $wgTitle;
6 global $days, $hideminor, $from, $hidebots, $hideliu; # From query string
7 $fname = "wfSpecialRecentchanges";
8
9 if( $par ) {
10 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
11 if( in_array( "hidebots", $bits ) ) $hidebots = 1;
12 if( in_array( "bots", $bits ) ) $hidebots = 0;
13 if( in_array( "hideminor", $bits ) ) $hideminor = 1;
14 if( in_array( "minor", $bits ) ) $hideminor = 0;
15 if( in_array( "hideliu", $bits) ) $hideliu = 1;
16 }
17
18 $sql = "SELECT MAX(rc_timestamp) AS lastmod FROM recentchanges";
19 $res = wfQuery( $sql, DB_READ, $fname );
20 $s = wfFetchObject( $res );
21 if( $wgOut->checkLastModified( $s->lastmod ) ){
22 # Client cache fresh and headers sent, nothing more to do.
23 return;
24 }
25
26 $rctext = wfMsg( "recentchangestext" );
27
28 # The next few lines can probably be commented out now that wfMsg can get text from the DB
29 $sql = "SELECT cur_text FROM cur WHERE cur_namespace=4 AND cur_title='Recentchanges'";
30 $res = wfQuery( $sql, DB_READ, $fname );
31 if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) {
32 $rctext = $s->cur_text;
33 }
34
35 $wgOut->addWikiText( $rctext );
36
37 if ( ! $days ) {
38 $days = $wgUser->getOption( "rcdays" );
39 if ( ! $days ) { $days = 3; }
40 }
41 $days = (int)$days;
42 list( $limit, $offset ) = wfCheckLimits( 100, "rclimit" );
43 $now = wfTimestampNow();
44 $cutoff = wfUnix2Timestamp( time() - ( $days * 86400 ) );
45 if(preg_match('/^[0-9]{14}$/', $from) and $from > $cutoff) {
46 $cutoff = $from;
47 } else {
48 unset($from);
49 }
50
51 $sk = $wgUser->getSkin();
52
53 if ( ! isset( $hideminor ) ) {
54 $hideminor = $wgUser->getOption( "hideminor" );
55 }
56 $hideminor = ($hideminor ? 1 : 0);
57 if ( $hideminor ) {
58 $hidem = "AND rc_minor=0";
59 $mltitle = wfMsg( "show" );
60 $mlhide = 0;
61 } else {
62 $hidem = "";
63 $mltitle = wfMsg( "hide" );
64 $mlhide = 1;
65 }
66
67 if ( isset( $from ) ) {
68 $mlparams = "from={$from}&hideminor={$mlhide}";
69 } else {
70 $mlparams = "days={$days}&limit={$limit}&hideminor={$mlhide}";
71 }
72
73 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
74 $mltitle, $mlparams );
75
76 if ( !isset( $hidebots ) ) {
77 $hidebots = 1;
78 }
79 if( $hidebots ) {
80 $hidem .= " AND rc_bot=0";
81 }
82
83 if ( $hideliu ) {
84 $hidem .= " AND rc_user=0";
85 }
86
87 $uid = $wgUser->getID();
88 $sql2 = "SELECT recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM recentchanges " .
89 ($uid ? "LEFT OUTER JOIN watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
90 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
91 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
92 $res = wfQuery( $sql2, DB_READ, $fname );
93
94 if(isset($from)) {
95 $note = wfMsg( "rcnotefrom", $limit,
96 $wgLang->timeanddate( $from, true ) );
97 } else {
98 $note = wfMsg( "rcnote", $limit, $days );
99 }
100 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
101
102 $note = rcDayLimitLinks( $days, $limit, "Recentchanges", "hideminor={$hideminor}", false, $mlink );
103
104 $note .= "<br>\n" . wfMsg( "rclistfrom",
105 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
106 $wgLang->timeanddate( $now, true ), "hideminor={$hideminor}&from=$now" ) );
107
108 $wgOut->addHTML( "{$note}\n" );
109
110 $count1 = wfNumRows( $res );
111 $obj1 = wfFetchObject( $res );
112
113 $s = $sk->beginRecentChangesList();
114 while ( $limit ) {
115 if ( ( 0 == $count1 ) ) {
116 break;
117 }
118 if ( ! ( $hideminor && $obj1->rc_minor ) ) {
119 $rc = RecentChange::newFromRow( $obj1 );
120 $s .= $sk->recentChangesLine( $rc, $obj1->wl_user );
121 --$limit;
122 }
123 $obj1 = wfFetchObject( $res );
124 --$count1;
125 }
126 $s .= $sk->endRecentChangesList();
127
128 wfFreeResult( $res );
129 $wgOut->addHTML( $s );
130 }
131
132 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
133 {
134 global $wgUser, $wgLang;
135 $sk = $wgUser->getSkin();
136 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
137 ($lim ? "{$lim}" : wfMsg( "all" ) ), "{$more}" .
138 ($d ? "days={$d}&" : "") . "limit={$lim}" );
139 return $s;
140 }
141
142 function rcDaysLink( $lim, $d, $page="Recentchanges", $more="" )
143 {
144 global $wgUser, $wgLang;
145 $sk = $wgUser->getSkin();
146 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
147 ($d ? "{$d}" : wfMsg( "all" ) ), "{$more}days={$d}" .
148 ($lim ? "&limit={$lim}" : "") );
149 return $s;
150 }
151
152 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false, $mlink = "" )
153 {
154 if ($more != "") $more .= "&";
155 $cl = rcCountLink( 50, $days, $page, $more ) . " | " .
156 rcCountLink( 100, $days, $page, $more ) . " | " .
157 rcCountLink( 250, $days, $page, $more ) . " | " .
158 rcCountLink( 500, $days, $page, $more ) .
159 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
160 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " .
161 rcDaysLink( $limit, 3, $page, $more ) . " | " .
162 rcDaysLink( $limit, 7, $page, $more ) . " | " .
163 rcDaysLink( $limit, 14, $page, $more ) . " | " .
164 rcDaysLink( $limit, 30, $page, $more ) .
165 ( $doall ? ( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" );
166 $shm = wfMsg( "showhideminor", $mlink );
167 $note = wfMsg( "rclinks", $cl, $dl, $shm );
168 return $note;
169 }
170
171 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false )
172 {
173 if ($more != "") $more .= "&";
174 $cl = rcCountLink( 50, 0, $page, $more ) . " | " .
175 rcCountLink( 100, 0, $page, $more ) . " | " .
176 rcCountLink( 250, 0, $page, $more ) . " | " .
177 rcCountLink( 500, 0, $page, $more ) .
178 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
179 $note = wfMsg( "rclinks", $cl, "", $mlink );
180 return $note;
181 }
182
183 ?>