4 * @ingroup SpecialPage Watchlist
10 * @param $par Parameter passed to the page
12 function wfSpecialWatchlist( $par ) {
13 global $wgUser, $wgOut, $wgLang, $wgRequest;
14 global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
15 global $wgEnotifWatchlist;
18 $wlToken = $wgUser->getOption( 'watchlisttoken' );
20 global $wgServer, $wgScriptPath, $wgFeedClasses;
21 $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
22 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken );
23 $feedTemplate = $wgServer . $wgScriptPath . '/api.php?';
25 foreach( $wgFeedClasses as $format => $class ) {
26 $theseParams = $apiParams +
array( 'feedformat' => $format );
27 $url = $feedTemplate . wfArrayToCGI( $theseParams );
28 $wgOut->addFeedLink( $format, $url );
32 $skin = $wgUser->getSkin();
33 $specialTitle = SpecialPage
::getTitleFor( 'Watchlist' );
34 $wgOut->setRobotPolicy( 'noindex,nofollow' );
36 # Anons don't get a watchlist
37 if( $wgUser->isAnon() ) {
38 $wgOut->setPageTitle( wfMsg( 'watchnologin' ) );
39 $llink = $skin->linkKnown(
40 SpecialPage
::getTitleFor( 'Userlogin' ),
41 wfMsgHtml( 'loginreqlink' ),
43 array( 'returnto' => $specialTitle->getPrefixedText() )
45 $wgOut->addHTML( wfMsgWikiHtml( 'watchlistanontext', $llink ) );
49 $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
51 $sub = wfMsgExt( 'watchlistfor', 'parseinline', $wgUser->getName() );
52 $sub .= '<br />' . WatchlistEditor
::buildTools( $wgUser->getSkin() );
53 $wgOut->setSubtitle( $sub );
55 if( ( $mode = WatchlistEditor
::getMode( $wgRequest, $par ) ) !== false ) {
56 $editor = new WatchlistEditor();
57 $editor->execute( $wgUser, $wgOut, $wgRequest, $mode );
61 $uid = $wgUser->getId();
62 if( ($wgEnotifWatchlist ||
$wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) &&
63 $wgRequest->wasPosted() )
65 $wgUser->clearAllNotifications( $uid );
66 $wgOut->redirect( $specialTitle->getFullUrl() );
71 /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
72 /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
73 /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
74 /* bool */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ),
75 /* bool */ 'hideLiu' => (int)$wgUser->getBoolOption( 'watchlisthideliu' ),
76 /* bool */ 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ),
77 /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
78 /* ? */ 'namespace' => 'all',
79 /* ? */ 'invert' => false,
84 # Extract variables from the request, falling back to user preferences or
85 # other default values if these don't exist
86 $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) );
87 $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
88 $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
89 $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanon' );
90 $prefs['hideliu'] = $wgUser->getBoolOption( 'watchlisthideliu' );
91 $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
92 $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' );
95 $days = $wgRequest->getVal( 'days' , $prefs['days'] );
96 $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
97 $hideBots = $wgRequest->getBool( 'hideBots' , $prefs['hidebots'] );
98 $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] );
99 $hideLiu = $wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] );
100 $hideOwn = $wgRequest->getBool( 'hideOwn' , $prefs['hideown'] );
101 $hidePatrolled = $wgRequest->getBool( 'hidePatrolled' , $prefs['hidepatrolled'] );
103 # Get namespace value, if supplied, and prepare a WHERE fragment
104 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
105 $invert = $wgRequest->getIntOrNull( 'invert' );
106 if( !is_null( $nameSpace ) ) {
107 $nameSpace = intval( $nameSpace );
108 if( $invert && $nameSpace !== 'all' )
109 $nameSpaceClause = "rc_namespace != $nameSpace";
111 $nameSpaceClause = "rc_namespace = $nameSpace";
114 $nameSpaceClause = '';
117 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
118 $recentchanges = $dbr->tableName( 'recentchanges' );
120 $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
121 array( 'wl_user' => $uid ), __METHOD__
);
122 // Adjust for page X, talk:page X, which are both stored separately,
123 // but treated together
124 $nitems = floor($watchlistCount / 2);
126 if( is_null($days) ||
!is_numeric($days) ) {
127 $big = 1000; /* The magical big */
129 # Set default cutoff shorter
130 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
132 $days = $defaults['days']; # default cutoff for shortlisters
135 $days = floatval($days);
138 // Dump everything here
139 $nondefaults = array();
141 wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults);
142 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
143 wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults);
144 wfAppendToArrayIfNotDefault( 'hideAnons', (int)$hideAnons, $defaults, $nondefaults );
145 wfAppendToArrayIfNotDefault( 'hideLiu' , (int)$hideLiu , $defaults, $nondefaults );
146 wfAppendToArrayIfNotDefault( 'hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
147 wfAppendToArrayIfNotDefault( 'namespace', $nameSpace , $defaults, $nondefaults);
148 wfAppendToArrayIfNotDefault( 'hidePatrolled', (int)$hidePatrolled, $defaults, $nondefaults );
151 $wgOut->addWikiMsg( 'nowatchlist' );
158 $andcutoff = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
161 # If the watchlist is relatively short, it's simplest to zip
162 # down its entirety and then sort the results.
164 # If it's relatively long, it may be worth our while to zip
165 # through the time-sorted page list checking for watched items.
167 # Up estimate of watched items by 15% to compensate for talk pages...
170 $andHideOwn = $hideOwn ?
"rc_user != $uid" : '';
171 $andHideBots = $hideBots ?
"rc_bot = 0" : '';
172 $andHideMinor = $hideMinor ?
"rc_minor = 0" : '';
173 $andHideLiu = $hideLiu ?
"rc_user = 0" : '';
174 $andHideAnons = $hideAnons ?
"rc_user != 0" : '';
175 $andHidePatrolled = $wgUser->useRCPatrol() && $hidePatrolled ?
"rc_patrolled != 1" : '';
177 # Toggle watchlist content (all recent edits or just the latest)
178 if( $wgUser->getOption( 'extendwatchlist' )) {
180 $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) );
183 # Top log Ids for a page are not stored
184 $andLatest = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG
;
189 # Show a message about slave lag, if applicable
190 if( ( $lag = $dbr->getLag() ) > 0 )
191 $wgOut->showLagWarning( $lag );
194 $form = Xml
::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) );
196 # Show watchlist header
197 $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) );
199 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
200 $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
202 if( $wgShowUpdatedMarker ) {
203 $form .= Xml
::openElement( 'form', array( 'method' => 'post',
204 'action' => $specialTitle->getLocalUrl(),
205 'id' => 'mw-watchlist-resetbutton' ) ) .
206 wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' .
207 Xml
::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) .
208 Xml
::hidden( 'reset', 'all' ) .
209 Xml
::closeElement( 'form' );
213 $tables = array( 'recentchanges', 'watchlist' );
214 $fields = array( "{$recentchanges}.*" );
217 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
219 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
220 if( $wgShowUpdatedMarker ) {
221 $fields[] = 'wl_notificationtimestamp';
223 if( $limitWatchlist ) {
224 $options['LIMIT'] = $limitWatchlist;
226 if( $andcutoff ) $conds[] = $andcutoff;
227 if( $andLatest ) $conds[] = $andLatest;
228 if( $andHideOwn ) $conds[] = $andHideOwn;
229 if( $andHideBots ) $conds[] = $andHideBots;
230 if( $andHideMinor ) $conds[] = $andHideMinor;
231 if( $andHideLiu ) $conds[] = $andHideLiu;
232 if( $andHideAnons ) $conds[] = $andHideAnons;
233 if( $andHidePatrolled ) $conds[] = $andHidePatrolled;
234 if( $nameSpaceClause ) $conds[] = $nameSpaceClause;
236 $rollbacker = $wgUser->isAllowed('rollback');
237 if ( $usePage ||
$rollbacker ) {
239 $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id');
241 $fields[] = 'page_latest';
244 ChangeTags
::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' );
245 wfRunHooks('SpecialWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) );
247 $res = $dbr->select( $tables, $fields, $conds, __METHOD__
, $options, $join_conds );
248 $numRows = $dbr->numRows( $res );
250 /* Start bottom header */
254 $wlInfo = wfMsgExt( 'rcnote', 'parseinline',
255 $wgLang->formatNum( $numRows ),
256 $wgLang->formatNum( $days ),
257 $wgLang->timeAndDate( wfTimestampNow(), true ),
258 $wgLang->date( wfTimestampNow(), true ),
259 $wgLang->time( wfTimestampNow(), true )
261 } elseif( $days > 0 ) {
262 $wlInfo = wfMsgExt( 'wlnote', 'parseinline',
263 $wgLang->formatNum( $numRows ),
264 $wgLang->formatNum( round($days*24) )
268 $cutofflinks = "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n";
270 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
272 # Spit out some control panel links
273 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor );
274 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots );
275 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons );
276 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu );
277 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn );
279 if( $wgUser->useRCPatrol() ) {
280 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled );
283 # Namespace filter and put the whole form together.
285 $form .= $cutofflinks;
286 $form .= $wgLang->pipeList( $links );
287 $form .= Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
288 $form .= '<hr /><p>';
289 $form .= Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
290 $form .= Xml
::namespaceSelector( $nameSpace, '' ) . ' ';
291 $form .= Xml
::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . ' ';
292 $form .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
293 $form .= Xml
::hidden( 'days', $days );
295 $form .= Xml
::hidden( 'hideMinor', 1 );
297 $form .= Xml
::hidden( 'hideBots', 1 );
299 $form .= Xml
::hidden( 'hideAnons', 1 );
301 $form .= Xml
::hidden( 'hideLiu', 1 );
303 $form .= Xml
::hidden( 'hideOwn', 1 );
304 $form .= Xml
::closeElement( 'form' );
305 $form .= Xml
::closeElement( 'fieldset' );
306 $wgOut->addHTML( $form );
308 $wgOut->addHTML( ChangesList
::flagLegend() );
310 # If there's nothing to show, stop here
311 if( $numRows == 0 ) {
312 $wgOut->addWikiMsg( 'watchnochange' );
316 /* End bottom header */
318 /* Do link batch query */
319 $linkBatch = new LinkBatch
;
320 while ( $row = $dbr->fetchObject( $res ) ) {
321 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
322 if ( $row->rc_user
!= 0 ) {
323 $linkBatch->add( NS_USER
, $userNameUnderscored );
325 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
327 $linkBatch->add( $row->rc_namespace
, $row->rc_title
);
329 $linkBatch->execute();
330 $dbr->dataSeek( $res, 0 );
332 $list = ChangesList
::newFromUser( $wgUser );
333 $list->setWatchlistDivs();
335 $s = $list->beginRecentChangesList();
337 while ( $obj = $dbr->fetchObject( $res ) ) {
339 $rc = RecentChange
::newFromRow( $obj );
340 $rc->counter
= $counter++
;
342 if ( $wgShowUpdatedMarker ) {
343 $updated = $obj->wl_notificationtimestamp
;
348 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
349 $rc->numberofWatchingusers
= $dbr->selectField( 'watchlist',
352 'wl_namespace' => $obj->rc_namespace
,
353 'wl_title' => $obj->rc_title
,
357 $rc->numberofWatchingusers
= 0;
360 $s .= $list->recentChangesLine( $rc, $updated, $counter );
362 $s .= $list->endRecentChangesList();
364 $dbr->freeResult( $res );
365 $wgOut->addHTML( $s );
368 function wlShowHideLink( $options, $message, $name, $value ) {
371 $showLinktext = wfMsgHtml( 'show' );
372 $hideLinktext = wfMsgHtml( 'hide' );
373 $title = SpecialPage
::getTitleFor( 'Watchlist' );
374 $skin = $wgUser->getSkin();
376 $label = $value ?
$showLinktext : $hideLinktext;
377 $options[$name] = 1 - (int) $value;
379 return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) );
383 function wlHoursLink( $h, $page, $options = array() ) {
384 global $wgUser, $wgLang, $wgContLang;
386 $sk = $wgUser->getSkin();
387 $title = Title
::newFromText( $wgContLang->specialPage( $page ) );
388 $options['days'] = ($h / 24.0);
392 $wgLang->formatNum( $h ),
400 function wlDaysLink( $d, $page, $options = array() ) {
401 global $wgUser, $wgLang, $wgContLang;
403 $sk = $wgUser->getSkin();
404 $title = Title
::newFromText( $wgContLang->specialPage( $page ) );
405 $options['days'] = $d;
406 $message = ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) );
421 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
424 $hours = array( 1, 2, 6, 12 );
425 $days = array( 1, 3, 7 );
427 foreach( $hours as $h ) {
428 $hours[$i++
] = wlHoursLink( $h, $page, $options );
431 foreach( $days as $d ) {
432 $days[$i++
] = wlDaysLink( $d, $page, $options );
434 return wfMsgExt('wlshowlast',
435 array('parseinline', 'replaceafter'),
436 $wgLang->pipeList( $hours ),
437 $wgLang->pipeList( $days ),
438 wlDaysLink( 0, $page, $options ) );
442 * Count the number of items on a user's watchlist
444 * @param $talk Include talk pages
447 function wlCountItems( &$user, $talk = true ) {
448 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
450 # Fetch the raw count
451 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
452 array( 'wl_user' => $user->mId
), 'wlCountItems' );
453 $row = $dbr->fetchObject( $res );
454 $count = $row->count
;
455 $dbr->freeResult( $res );
457 # Halve to remove talk pages if needed
459 $count = floor( $count / 2 );