removing call to the database for "recentchangestext". That's automaticly get by...
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?php
2
3 require_once( 'Feed.php' );
4
5 function wfSpecialRecentchanges( $par )
6 {
7 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname;
8 global $wgRequest, $wgSitename, $wgLanguageCode;
9 global $wgFeedClasses;
10 $fname = 'wfSpecialRecentchanges';
11
12 # Get query parameters
13 $feedFormat = $wgRequest->getVal( 'feed' );
14
15 $defaultDays = $wgUser->getOption( 'rcdays' );
16 if ( !$defaultDays ) { $defaultDays = 3; }
17
18 $days = $wgRequest->getInt( 'days', $defaultDays );
19 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ? 1 : 0;
20 $from = $wgRequest->getText( 'from' );
21 $hidebots = $wgRequest->getBool( 'hidebots', true ) ? 1 : 0;
22 $hideliu = $wgRequest->getBool( 'hideliu', false ) ? 1 : 0;
23 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', false ) ? 1 : 0;
24
25 # Get query parameters from path
26 if( $par ) {
27 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
28 if( in_array( 'hidebots', $bits ) ) $hidebots = 1;
29 if( in_array( 'bots', $bits ) ) $hidebots = 0;
30 if( in_array( 'hideminor', $bits ) ) $hideminor = 1;
31 if( in_array( 'minor', $bits ) ) $hideminor = 0;
32 if( in_array( 'hideliu', $bits) ) $hideliu = 1;
33 if( in_array( 'hidepatrolled', $bits) ) $hidepatrolled = 1;
34 }
35
36 $dbr =& wfGetDB( DB_SLAVE );
37 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
38
39 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
40 # 10 seconds server-side caching max
41 $wgOut->setSquidMaxage( 10 );
42 if( $wgOut->checkLastModified( $lastmod ) ){
43 # Client cache fresh and headers sent, nothing more to do.
44 return;
45 }
46
47 # The next few lines can probably be commented out now that wfMsg can get text from the DB
48 /* $rctext = $dbr->selectField( 'cur', 'cur_text',
49 array( 'cur_namespace' => NS_WIKIPEDIA, 'cur_title' => 'Recentchanges' ),
50 $fname
51 );
52 if( !$rctext ) {
53 $rctext = wfMsg( "recentchangestext" );
54 } */
55
56 $rctext = wfMsg( "recentchangestext" );
57
58 $wgOut->addWikiText( $rctext );
59
60 list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
61 $now = wfTimestampNow();
62 $cutoff_unixtime = time() - ( $days * 86400 );
63 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
64 $cutoff = $dbr->timestamp( $cutoff_unixtime );
65 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW,$cutoff)) {
66 $cutoff = $dbr->timestamp($from);
67 } else {
68 unset($from);
69 }
70
71 $sk = $wgUser->getSkin();
72 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
73
74 $hidem = ( $hideminor ) ? 'AND rc_minor=0' : '';
75 $hidem .= ( $hidebots ) ? ' AND rc_bot=0' : '';
76 $hidem .= ( $hideliu ) ? ' AND rc_user=0' : '';
77 $hidem .= ( $hidepatrolled )? ' AND rc_patrolled=0' : '';
78
79 $urlparams = array( 'hideminor' => $hideminor, 'hideliu' => $hideliu,
80 'hidebots' => $hidebots, 'hidepatrolled' => $hidepatrolled );
81 $hideparams = wfArrayToCGI( $urlparams );
82
83 $minorLink = $sk->makeKnownLink( $wgLang->specialPage( 'Recentchanges' ),
84 $showhide[1-$hideminor], wfArrayToCGI( array( 'hideminor' => 1-$hideminor ), $urlparams ) );
85 $botLink = $sk->makeKnownLink( $wgLang->specialPage( 'Recentchanges' ),
86 $showhide[1-$hidebots], wfArrayToCGI( array( 'hidebots' => 1-$hidebots ), $urlparams ) );
87 $liuLink = $sk->makeKnownLink( $wgLang->specialPage( 'Recentchanges' ),
88 $showhide[1-$hideliu], wfArrayToCGI( array( 'hideliu' => 1-$hideliu ), $urlparams ) );
89 $patrLink = $sk->makeKnownLink( $wgLang->specialPage( 'Recentchanges' ),
90 $showhide[1-$hidepatrolled], wfArrayToCGI( array( 'hidepatrolled' => 1-$hidepatrolled ), $urlparams ) );
91
92 $uid = $wgUser->getID();
93 $sql2 = "SELECT $recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM $recentchanges " .
94 ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
95 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
96 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
97
98 $res = $dbr->query( $sql2, DB_SLAVE, $fname );
99 $rows = array();
100 while( $row = $dbr->fetchObject( $res ) ){
101 $rows[] = $row;
102 }
103 $dbr->freeResult( $res );
104
105 if(isset($from)) {
106 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $limit ),
107 $wgLang->timeanddate( $from, true ) );
108 } else {
109 $note = wfMsg( 'rcnote', $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
110 }
111 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
112
113 $note = rcDayLimitLinks( $days, $limit, 'Recentchanges', $hideparams, false, $minorLink, $botLink, $liuLink, $patrLink );
114
115 $note .= "<br />\n" . wfMsg( 'rclistfrom',
116 $sk->makeKnownLink( $wgLang->specialPage( 'Recentchanges' ),
117 $wgLang->timeanddate( $now, true ), $hideparams.'&from='.$now ) );
118
119 $wgOut->addHTML( $note."\n" );
120
121 if( isset($wgFeedClasses[$feedFormat]) ) {
122 $feed = new $wgFeedClasses[$feedFormat](
123 $wgSitename . ' - ' . wfMsg( 'recentchanges' ) . ' [' . $wgLanguageCode . ']',
124 htmlspecialchars( wfMsg( 'recentchangestext' ) ),
125 $wgTitle->getFullUrl() );
126 $feed->outHeader();
127 foreach( $rows as $obj ) {
128 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
129 $talkpage = $title->getTalkPage();
130 $item = new FeedItem(
131 $title->getPrefixedText(),
132 htmlspecialchars( $obj->rc_comment ),
133 $title->getFullURL(),
134 $obj->rc_timestamp,
135 $obj->rc_user_text,
136 $talkpage->getFullURL()
137 );
138 $feed->outItem( $item );
139 }
140 $feed->outFooter();
141 } else {
142 $wgOut->setSyndicated( true );
143 $s = $sk->beginRecentChangesList();
144 $counter = 1;
145 foreach( $rows as $obj ){
146 if( $limit == 0) {
147 break;
148 }
149
150 if ( ! ( $hideminor && $obj->rc_minor ) &&
151 ! ( $hidepatrolled && $obj->rc_patrolled ) ) {
152 $rc = RecentChange::newFromRow( $obj );
153 $rc->counter = $counter++;
154 $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user ) );
155 --$limit;
156 }
157 }
158 $s .= $sk->endRecentChangesList();
159 $wgOut->addHTML( $s );
160 }
161 }
162
163 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' )
164 {
165 global $wgUser, $wgLang;
166 $sk = $wgUser->getSkin();
167 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
168 ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( 'all' ) ), "{$more}" .
169 ($d ? "days={$d}&" : '') . 'limit='.$lim );
170 return $s;
171 }
172
173 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' )
174 {
175 global $wgUser, $wgLang;
176 $sk = $wgUser->getSkin();
177 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
178 ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), $more.'days='.$d .
179 ($lim ? '&limit='.$lim : '') );
180 return $s;
181 }
182
183 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
184 $botLink = '', $liuLink = '', $patrLink = '' )
185 {
186 if ($more != '') $more .= '&';
187 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
188 rcCountLink( 100, $days, $page, $more ) . ' | ' .
189 rcCountLink( 250, $days, $page, $more ) . ' | ' .
190 rcCountLink( 500, $days, $page, $more ) .
191 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
192 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
193 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
194 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
195 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
196 rcDaysLink( $limit, 30, $page, $more ) .
197 ( $doall ? ( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
198 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink );
199 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
200 return $note;
201 }
202
203 # Obsolete? Isn't called from anywhere and $mlink isn't defined
204 function rcLimitLinks( $page='Recentchanges', $more='', $doall = false )
205 {
206 if ($more != '') $more .= '&';
207 $cl = rcCountLink( 50, 0, $page, $more ) . ' | ' .
208 rcCountLink( 100, 0, $page, $more ) . ' | ' .
209 rcCountLink( 250, 0, $page, $more ) . ' | ' .
210 rcCountLink( 500, 0, $page, $more ) .
211 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
212 $note = wfMsg( 'rclinks', $cl, '', $mlink );
213 return $note;
214 }
215
216 ?>