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