comment about extranamespaces values that should not be >255
[lhc/web/wiklou.git] / includes / SpecialRecentchanges.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 require_once( 'Feed.php' );
12
13 /**
14 * Constructor
15 */
16 function wfSpecialRecentchanges( $par ) {
17 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgTitle, $wgMemc, $wgDBname;
18 global $wgRequest, $wgSitename, $wgLanguageCode, $wgContLanguageCode;
19 global $wgFeedClasses;
20 $fname = 'wfSpecialRecentchanges';
21
22 # Get query parameters
23 $feedFormat = $wgRequest->getVal( 'feed' );
24
25 $defaultDays = $wgUser->getOption( 'rcdays' );
26 if ( !$defaultDays ) { $defaultDays = 3; }
27
28 $days = $wgRequest->getInt( 'days', $defaultDays );
29 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ? 1 : 0;
30 $from = $wgRequest->getText( 'from' );
31 $hidebots = $wgRequest->getBool( 'hidebots', true ) ? 1 : 0;
32 $hideliu = $wgRequest->getBool( 'hideliu', false ) ? 1 : 0;
33 $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', false ) ? 1 : 0;
34
35 list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
36
37 # Get query parameters from path
38 if( $par ) {
39 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
40 if( in_array( 'hidebots', $bits ) ) $hidebots = 1;
41 if( in_array( 'bots', $bits ) ) $hidebots = 0;
42 if( in_array( 'hideminor', $bits ) ) $hideminor = 1;
43 if( in_array( 'minor', $bits ) ) $hideminor = 0;
44 if( in_array( 'hideliu', $bits) ) $hideliu = 1;
45 if( in_array( 'hidepatrolled', $bits) ) $hidepatrolled = 1;
46 }
47
48
49 # Database connection and caching
50 $dbr =& wfGetDB( DB_SLAVE );
51 extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
52
53 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, $fname );
54 # 10 seconds server-side caching max
55 $wgOut->setSquidMaxage( 10 );
56 if( $lastmod && $wgOut->checkLastModified( $lastmod ) ){
57 # Client cache fresh and headers sent, nothing more to do.
58 return;
59 }
60
61 # Output header
62 $rctext = wfMsg( "recentchangestext" );
63 $wgOut->addWikiText( $rctext );
64
65
66 $now = wfTimestampNow();
67 $cutoff_unixtime = time() - ( $days * 86400 );
68 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
69 $cutoff = $dbr->timestamp( $cutoff_unixtime );
70 if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW,$cutoff)) {
71 $cutoff = $dbr->timestamp($from);
72 } else {
73 unset($from);
74 }
75
76 $sk = $wgUser->getSkin();
77
78 $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
79
80 $hidem = ( $hideminor ) ? 'AND rc_minor=0' : '';
81 $hidem .= ( $hidebots ) ? ' AND rc_bot=0' : '';
82 $hidem .= ( $hideliu ) ? ' AND rc_user=0' : '';
83 $hidem .= ( $hidepatrolled )? ' AND rc_patrolled=0' : '';
84
85 $urlparams = array( 'hideminor' => $hideminor, 'hideliu' => $hideliu,
86 'hidebots' => $hidebots, 'hidepatrolled' => $hidepatrolled,
87 'limit' => $limit );
88 $hideparams = wfArrayToCGI( $urlparams );
89
90 $minorLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
91 $showhide[1-$hideminor], wfArrayToCGI( array( 'hideminor' => 1-$hideminor ), $urlparams ) );
92 $botLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
93 $showhide[1-$hidebots], wfArrayToCGI( array( 'hidebots' => 1-$hidebots ), $urlparams ) );
94 $liuLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
95 $showhide[1-$hideliu], wfArrayToCGI( array( 'hideliu' => 1-$hideliu ), $urlparams ) );
96 $patrLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
97 $showhide[1-$hidepatrolled], wfArrayToCGI( array( 'hidepatrolled' => 1-$hidepatrolled ), $urlparams ) );
98
99 $uid = $wgUser->getID();
100 $sql2 = "SELECT $recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM $recentchanges " .
101 ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") .
102 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
103 "ORDER BY rc_timestamp DESC LIMIT {$limit}";
104
105 $res = $dbr->query( $sql2, DB_SLAVE, $fname );
106 $rows = array();
107 while( $row = $dbr->fetchObject( $res ) ){
108 $rows[] = $row;
109 }
110 $dbr->freeResult( $res );
111
112 if(isset($from)) {
113 $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $limit ),
114 $wgLang->timeanddate( $from, true ) );
115 } else {
116 $note = wfMsg( 'rcnote', $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
117 }
118 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
119
120 $note = rcDayLimitLinks( $days, $limit, 'Recentchanges', $hideparams, false, $minorLink, $botLink, $liuLink, $patrLink );
121
122 $note .= "<br />\n" . wfMsg( 'rclistfrom',
123 $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
124 $wgLang->timeanddate( $now, true ), $hideparams.'&from='.$now ) );
125
126 $wgOut->addHTML( $note."\n" );
127
128 if( isset($wgFeedClasses[$feedFormat]) ) {
129 $feed = new $wgFeedClasses[$feedFormat](
130 $wgSitename . ' - ' . wfMsg( 'recentchanges' ) . ' [' . $wgContLanguageCode . ']',
131 htmlspecialchars( wfMsg( 'recentchangestext' ) ),
132 $wgTitle->getFullUrl() );
133 $feed->outHeader();
134
135 # Merge adjacent edits by one user
136 $sorted = array();
137 $n = 0;
138 foreach( $rows as $obj ) {
139 if( $n > 0 &&
140 $obj->rc_namespace >= 0 &&
141 $obj->rc_cur_id == $sorted[$n-1]->rc_cur_id &&
142 $obj->rc_user_text == $sorted[$n-1]->rc_user_text ) {
143 $sorted[$n-1]->rc_last_oldid = $obj->rc_last_oldid;
144 } else {
145 $sorted[$n] = $obj;
146 $n++;
147 }
148 $first = false;
149 }
150
151 foreach( $sorted as $obj ) {
152 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
153 $talkpage = $title->getTalkPage();
154 $item = new FeedItem(
155 $title->getPrefixedText(),
156 rcFormatDiff( $obj ),
157 $title->getFullURL(),
158 $obj->rc_timestamp,
159 $obj->rc_user_text,
160 $talkpage->getFullURL()
161 );
162 $feed->outItem( $item );
163 }
164 $feed->outFooter();
165 } else {
166 $wgOut->setSyndicated( true );
167 $s = $sk->beginRecentChangesList();
168 $counter = 1;
169 foreach( $rows as $obj ){
170 if( $limit == 0) {
171 break;
172 }
173
174 if ( ! ( $hideminor && $obj->rc_minor ) &&
175 ! ( $hidepatrolled && $obj->rc_patrolled ) ) {
176 $rc = RecentChange::newFromRow( $obj );
177 $rc->counter = $counter++;
178 $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user ) );
179 --$limit;
180 }
181 }
182 $s .= $sk->endRecentChangesList();
183 $wgOut->addHTML( $s );
184 }
185 }
186
187 /**
188 *
189 */
190 function rcCountLink( $lim, $d, $page='Recentchanges', $more='' ) {
191 global $wgUser, $wgLang, $wgContLang;
192 $sk = $wgUser->getSkin();
193 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
194 ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( 'all' ) ), "{$more}" .
195 ($d ? "days={$d}&" : '') . 'limit='.$lim );
196 return $s;
197 }
198
199 /**
200 *
201 */
202 function rcDaysLink( $lim, $d, $page='Recentchanges', $more='' ) {
203 global $wgUser, $wgLang, $wgContLang;
204 $sk = $wgUser->getSkin();
205 $s = $sk->makeKnownLink( $wgContLang->specialPage( $page ),
206 ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), $more.'days='.$d .
207 ($lim ? '&limit='.$lim : '') );
208 return $s;
209 }
210
211 /**
212 *
213 */
214 function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
215 $botLink = '', $liuLink = '', $patrLink = '' ) {
216 if ($more != '') $more .= '&';
217 $cl = rcCountLink( 50, $days, $page, $more ) . ' | ' .
218 rcCountLink( 100, $days, $page, $more ) . ' | ' .
219 rcCountLink( 250, $days, $page, $more ) . ' | ' .
220 rcCountLink( 500, $days, $page, $more ) .
221 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
222 $dl = rcDaysLink( $limit, 1, $page, $more ) . ' | ' .
223 rcDaysLink( $limit, 3, $page, $more ) . ' | ' .
224 rcDaysLink( $limit, 7, $page, $more ) . ' | ' .
225 rcDaysLink( $limit, 14, $page, $more ) . ' | ' .
226 rcDaysLink( $limit, 30, $page, $more ) .
227 ( $doall ? ( ' | ' . rcDaysLink( $limit, 0, $page, $more ) ) : '' );
228 $shm = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink );
229 $note = wfMsg( 'rclinks', $cl, $dl, $shm );
230 return $note;
231 }
232
233 /**
234 * Obsolete? Isn't called from anywhere and $mlink isn't defined
235 */
236 function rcLimitLinks( $page='Recentchanges', $more='', $doall = false ) {
237 if ($more != '') $more .= '&';
238 $cl = rcCountLink( 50, 0, $page, $more ) . ' | ' .
239 rcCountLink( 100, 0, $page, $more ) . ' | ' .
240 rcCountLink( 250, 0, $page, $more ) . ' | ' .
241 rcCountLink( 500, 0, $page, $more ) .
242 ( $doall ? ( ' | ' . rcCountLink( 0, $days, $page, $more ) ) : '' );
243 $note = wfMsg( 'rclinks', $cl, '', $mlink );
244 return $note;
245 }
246
247 function rcFormatDiff( $row ) {
248 require_once( 'DifferenceEngine.php' );
249 $comment = "<p>" . htmlspecialchars( $row->rc_comment ) . "</p>\n";
250
251 if( $row->rc_namespace >= 0 ) {
252 global $wgContLang;
253
254 #$diff =& new DifferenceEngine( $row->rc_this_oldid, $row->rc_last_oldid, $row->rc_id );
255 #$diff->showDiffPage();
256
257 $dbr =& wfGetDB( DB_SLAVE );
258 if( $row->rc_this_oldid ) {
259 $newrow = $dbr->selectRow( 'old',
260 array( 'old_flags', 'old_text' ),
261 array( 'old_id' => $row->rc_this_oldid ) );
262 $newtext = Article::getRevisionText( $newrow );
263 } else {
264 $newrow = $dbr->selectRow( 'cur',
265 array( 'cur_text' ),
266 array( 'cur_id' => $row->rc_cur_id ) );
267 $newtext = $newrow->cur_text;
268 }
269 if( $row->rc_last_oldid ) {
270 $oldrow = $dbr->selectRow( 'old',
271 array( 'old_flags', 'old_text' ),
272 array( 'old_id' => $row->rc_last_oldid ) );
273 $oldtext = Article::getRevisionText( $oldrow );
274 $diffText = DifferenceEngine::getDiff( $oldtext, $newtext,
275 wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ),
276 wfMsg( 'currentrev' ) );
277 } else {
278 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
279 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
280 }
281
282 return $comment . $diffText;
283 }
284
285 return $comment;
286 }
287
288 ?>