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