Security fix: wpReUpload
[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 if ( $hideminor ) {
53 $hidem = "AND rc_minor=0";
54 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
55 WfMsg( "show" ), "days={$days}&limit={$limit}&hideminor=0" );
56 } else {
57 $hidem = "";
58 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
59 WfMsg( "hide" ), "days={$days}&limit={$limit}&hideminor=1" );
60 }
61
62 if ( !isset( $hidebots ) ) {
63 $hidebots = 1;
64 }
65 if( $hidebots ) {
66 $hidem .= " AND rc_bot=0";
67 }
68
69 $uid = $wgUser->getID();
70 $sql2 = "SELECT rc_cur_id,rc_namespace,rc_title,rc_user,rc_new," .
71 "rc_comment,rc_user_text,rc_timestamp,rc_minor,rc_this_oldid,rc_last_oldid,rc_bot" . ($uid ? ",wl_user" : "") . " FROM recentchanges " .
72 ($uid ? "LEFT OUTER JOIN watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
73 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
74 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
75 $res = wfQuery( $sql2, DB_READ, $fname );
76
77 if(isset($from)) {
78 $note = wfMsg( "rcnotefrom", $limit,
79 $wgLang->timeanddate( $from, true ) );
80 } else {
81 $note = wfMsg( "rcnote", $limit, $days );
82 }
83 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
84
85 $note = rcDayLimitLinks( $days, $limit );
86
87 $note .= "<br>\n" . wfMsg( "rclistfrom",
88 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
89 $wgLang->timeanddate( $now, true ), "from=$now" ) );
90
91 $wgOut->addHTML( "{$note}\n" );
92
93 $count1 = wfNumRows( $res );
94 $obj1 = wfFetchObject( $res );
95
96 $s = $sk->beginRecentChangesList();
97 while ( $limit ) {
98 if ( ( 0 == $count1 ) ) { break; }
99
100 $ts = $obj1->rc_timestamp;
101 $u = $obj1->rc_user;
102 $ut = $obj1->rc_user_text;
103 $ns = $obj1->rc_namespace;
104 $ttl = $obj1->rc_title;
105 $com = $obj1->rc_comment;
106 $me = ( $obj1->rc_minor > 0 );
107 $new = ( $obj1->rc_new > 0 );
108 $watched = ($obj1->wl_user > 0);
109 $oldid = $obj1->rc_this_oldid ;
110 $diffid = $obj1->rc_last_oldid ;
111
112 $obj1 = wfFetchObject( $res );
113 --$count1;
114 if ( ! ( $hideminor && $me ) ) {
115 $s .= $sk->recentChangesLine( $ts, $u, $ut, $ns, $ttl,
116 $com, $me, $new, $watched, $oldid , $diffid );
117 --$limit;
118 }
119 }
120 $s .= $sk->endRecentChangesList();
121
122 wfFreeResult( $res );
123 $wgOut->addHTML( $s );
124 }
125
126 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
127 {
128 global $wgUser, $wgLang;
129 $sk = $wgUser->getSkin();
130 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
131 ($lim ? "{$lim}" : wfMsg( "all" ) ), "{$more}" .
132 ($d ? "days={$d}&" : "") . "limit={$lim}" );
133 return $s;
134 }
135
136 function rcDaysLink( $lim, $d, $page="Recentchanges", $more="" )
137 {
138 global $wgUser, $wgLang;
139 $sk = $wgUser->getSkin();
140 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
141 ($d ? "{$d}" : wfMsg( "all" ) ), "{$more}days={$d}" .
142 ($lim ? "&limit={$lim}" : "") );
143 return $s;
144 }
145
146 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false )
147 {
148 if ($more != "") $more .= "&";
149 $cl = rcCountLink( 50, $days, $page, $more ) . " | " .
150 rcCountLink( 100, $days, $page, $more ) . " | " .
151 rcCountLink( 250, $days, $page, $more ) . " | " .
152 rcCountLink( 500, $days, $page, $more ) .
153 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
154 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " .
155 rcDaysLink( $limit, 3, $page, $more ) . " | " .
156 rcDaysLink( $limit, 7, $page, $more ) . " | " .
157 rcDaysLink( $limit, 14, $page, $more ) . " | " .
158 rcDaysLink( $limit, 30, $page, $more ) .
159 ( $doall ? ( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" );
160 $note = wfMsg( "rclinks", $cl, $dl, $mlink );
161 return $note;
162 }
163
164 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false )
165 {
166 if ($more != "") $more .= "&";
167 $cl = rcCountLink( 50, 0, $page, $more ) . " | " .
168 rcCountLink( 100, 0, $page, $more ) . " | " .
169 rcCountLink( 250, 0, $page, $more ) . " | " .
170 rcCountLink( 500, 0, $page, $more ) .
171 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
172 $note = wfMsg( "rclinks", $cl, "", $mlink );
173 return $note;
174 }
175
176 ?>