* Recent Changes improvements: object oriented back end, move page annotation and...
[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 recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM recentchanges " .
84 ($uid ? "LEFT OUTER JOIN watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
85 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
86 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
87 $res = wfQuery( $sql2, DB_READ, $fname );
88
89 if(isset($from)) {
90 $note = wfMsg( "rcnotefrom", $limit,
91 $wgLang->timeanddate( $from, true ) );
92 } else {
93 $note = wfMsg( "rcnote", $limit, $days );
94 }
95 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
96
97 $note = rcDayLimitLinks( $days, $limit, "Recentchanges", "hideminor={$hideminor}", false, $mlink );
98
99 $note .= "<br>\n" . wfMsg( "rclistfrom",
100 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ),
101 $wgLang->timeanddate( $now, true ), "hideminor={$hideminor}&from=$now" ) );
102
103 $wgOut->addHTML( "{$note}\n" );
104
105 $count1 = wfNumRows( $res );
106 $obj1 = wfFetchObject( $res );
107
108 $s = $sk->beginRecentChangesList();
109 while ( $limit ) {
110 if ( ( 0 == $count1 ) ) {
111 break;
112 }
113 if ( ! ( $hideminor && $obj1->rc_minor ) ) {
114 $s .= $sk->recentChangesLine( $obj1, $obj1->wl_user );
115 --$limit;
116 }
117 $obj1 = wfFetchObject( $res );
118 --$count1;
119 }
120 $s .= $sk->endRecentChangesList();
121
122 wfFreeResult( $res );
123 $wgOut->addHTML( $s );
124 }
125
126 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" )
127 {
128 global $wgUser, $wgLang;
129 $sk = $wgUser->getSkin();
130 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
131 ($lim ? "{$lim}" : wfMsg( "all" ) ), "{$more}" .
132 ($d ? "days={$d}&" : "") . "limit={$lim}" );
133 return $s;
134 }
135
136 function rcDaysLink( $lim, $d, $page="Recentchanges", $more="" )
137 {
138 global $wgUser, $wgLang;
139 $sk = $wgUser->getSkin();
140 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
141 ($d ? "{$d}" : wfMsg( "all" ) ), "{$more}days={$d}" .
142 ($lim ? "&limit={$lim}" : "") );
143 return $s;
144 }
145
146 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false, $mlink = "" )
147 {
148 if ($more != "") $more .= "&";
149 $cl = rcCountLink( 50, $days, $page, $more ) . " | " .
150 rcCountLink( 100, $days, $page, $more ) . " | " .
151 rcCountLink( 250, $days, $page, $more ) . " | " .
152 rcCountLink( 500, $days, $page, $more ) .
153 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
154 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " .
155 rcDaysLink( $limit, 3, $page, $more ) . " | " .
156 rcDaysLink( $limit, 7, $page, $more ) . " | " .
157 rcDaysLink( $limit, 14, $page, $more ) . " | " .
158 rcDaysLink( $limit, 30, $page, $more ) .
159 ( $doall ? ( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" );
160 $shm = wfMsg( "showhideminor", $mlink );
161 $note = wfMsg( "rclinks", $cl, $dl, $shm );
162 return $note;
163 }
164
165 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false )
166 {
167 if ($more != "") $more .= "&";
168 $cl = rcCountLink( 50, 0, $page, $more ) . " | " .
169 rcCountLink( 100, 0, $page, $more ) . " | " .
170 rcCountLink( 250, 0, $page, $more ) . " | " .
171 rcCountLink( 500, 0, $page, $more ) .
172 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" );
173 $note = wfMsg( "rclinks", $cl, "", $mlink );
174 return $note;
175 }
176
177 ?>