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