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