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