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