potentially uninitialized variable fixed
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?
2
3 function wfSpecialRecentchanges( $par )
4 {
5 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname;
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_unixtime = time() - ( $days * 86400 );
45 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
46 $cutoff = wfUnix2Timestamp( $cutoff_unixtime );
47 if(preg_match('/^[0-9]{14}$/', $from) and $from > $cutoff) {
48 $cutoff = $from;
49 } else {
50 unset($from);
51 }
52
53 $sk = $wgUser->getSkin();
54
55 if ( ! isset( $hideminor ) ) {
56 $hideminor = $wgUser->getOption( "hideminor" );
57 }
58 $hideminor = ($hideminor ? 1 : 0);
59 if ( $hideminor ) {
60 $hidem = "AND rc_minor=0";
61 $mltitle = wfMsg( "show" );
62 $mlhide = 0;
63 } else {
64 $hidem = "";
65 $mltitle = wfMsg( "hide" );
66 $mlhide = 1;
67 }
68
69 if ( isset( $from ) ) {
70 $mlparams = "from={$from}&hideminor={$mlhide}";
71 } else {
72 $mlparams = "days={$days}&limit={$limit}&hideminor={$mlhide}";
73 }
74
75 $mlink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
76 $mltitle, $mlparams );
77
78 if ( !isset( $hidebots ) ) {
79 $hidebots = 1;
80 }
81 if( $hidebots ) {
82 $hidem .= " AND rc_bot=0";
83 }
84
85 if ( $hideliu ) {
86 $hidem .= " AND rc_user=0";
87 }
88
89 $uid = $wgUser->getID();
90 $sql2 = "SELECT recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM recentchanges " .
91 ($uid ? "LEFT OUTER JOIN watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
92 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
93 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
94
95 $res = wfQuery( $sql2, DB_READ, $fname );
96 $rows = array();
97 while( $row = wfFetchObject( $res ) ){
98 $rows[] = $row;
99 }
100
101 if(isset($from)) {
102 $note = wfMsg( "rcnotefrom", $limit,
103 $wgLang->timeanddate( $from, true ) );
104 } else {
105 $note = wfMsg( "rcnote", $limit, $days );
106 }
107 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
108
109 $note = rcDayLimitLinks( $days, $limit, "Recentchanges", "hideminor={$hideminor}", false, $mlink );
110
111 $note .= "<br>\n" . wfMsg( "rclistfrom",
112 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
113 $wgLang->timeanddate( $now, true ), "hideminor={$hideminor}&from=$now" ) );
114
115 $wgOut->addHTML( "{$note}\n" );
116
117 $s = $sk->beginRecentChangesList();
118 foreach( $rows as $obj ){
119 if( $limit == 0) {
120 break;
121 }
122
123 if ( ! ( $hideminor && $obj->rc_minor ) ) {
124 $rc = RecentChange::newFromRow( $obj );
125 $s .= $sk->recentChangesLine( $rc, $obj->wl_user );
126 --$limit;
127 }
128 }
129 $s .= $sk->endRecentChangesList();
130
131 wfFreeResult( $res );
132 $wgOut->addHTML( $s );
133 }
134
135 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
136 {
137 global $wgUser, $wgLang;
138 $sk = $wgUser->getSkin();
139 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
140 ($lim ? "{$lim}" : wfMsg( "all" ) ), "{$more}" .
141 ($d ? "days={$d}&" : "") . "limit={$lim}" );
142 return $s;
143 }
144
145 function rcDaysLink( $lim, $d, $page="Recentchanges", $more="" )
146 {
147 global $wgUser, $wgLang;
148 $sk = $wgUser->getSkin();
149 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
150 ($d ? "{$d}" : wfMsg( "all" ) ), "{$more}days={$d}" .
151 ($lim ? "&limit={$lim}" : "") );
152 return $s;
153 }
154
155 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false, $mlink = "" )
156 {
157 if ($more != "") $more .= "&";
158 $cl = rcCountLink( 50, $days, $page, $more ) . " | " .
159 rcCountLink( 100, $days, $page, $more ) . " | " .
160 rcCountLink( 250, $days, $page, $more ) . " | " .
161 rcCountLink( 500, $days, $page, $more ) .
162 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
163 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " .
164 rcDaysLink( $limit, 3, $page, $more ) . " | " .
165 rcDaysLink( $limit, 7, $page, $more ) . " | " .
166 rcDaysLink( $limit, 14, $page, $more ) . " | " .
167 rcDaysLink( $limit, 30, $page, $more ) .
168 ( $doall ? ( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" );
169 $shm = wfMsg( "showhideminor", $mlink );
170 $note = wfMsg( "rclinks", $cl, $dl, $shm );
171 return $note;
172 }
173
174 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false )
175 {
176 if ($more != "") $more .= "&";
177 $cl = rcCountLink( 50, 0, $page, $more ) . " | " .
178 rcCountLink( 100, 0, $page, $more ) . " | " .
179 rcCountLink( 250, 0, $page, $more ) . " | " .
180 rcCountLink( 500, 0, $page, $more ) .
181 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
182 $note = wfMsg( "rclinks", $cl, "", $mlink );
183 return $note;
184 }
185
186 ?>