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;
17 $wlToken = $wgUser->getOption( 'watchlisttoken' );
19 $wlToken = sha1( mt_rand() . microtime( true ) );
20 $wgUser->setOption( 'watchlisttoken', $wlToken );
21 $wgUser->saveSettings();
24 global $wgServer, $wgScriptPath, $wgFeedClasses;
25 $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
26 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken );
27 $feedTemplate = wfScript('api').'?';
29 foreach( $wgFeedClasses as $format => $class ) {
30 $theseParams = $apiParams +
array( 'feedformat' => $format );
31 $url = $feedTemplate . wfArrayToCGI( $theseParams );
32 $wgOut->addFeedLink( $format, $url );
35 $skin = $wgUser->getSkin();
36 $specialTitle = SpecialPage
::getTitleFor( 'Watchlist' );
37 $wgOut->setRobotPolicy( 'noindex,nofollow' );
39 # Anons don't get a watchlist
40 if( $wgUser->isAnon() ) {
41 $wgOut->setPageTitle( wfMsg( 'watchnologin' ) );
42 $llink = $skin->linkKnown(
43 SpecialPage
::getTitleFor( 'Userlogin' ),
44 wfMsgHtml( 'loginreqlink' ),
46 array( 'returnto' => $specialTitle->getPrefixedText() )
48 $wgOut->addHTML( wfMsgWikiHtml( 'watchlistanontext', $llink ) );
52 $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
54 $sub = wfMsgExt( 'watchlistfor', 'parseinline', $wgUser->getName() );
55 $sub .= '<br />' . WatchlistEditor
::buildTools( $wgUser->getSkin() );
56 $wgOut->setSubtitle( $sub );
58 if( ( $mode = WatchlistEditor
::getMode( $wgRequest, $par ) ) !== false ) {
59 $editor = new WatchlistEditor();
60 $editor->execute( $wgUser, $wgOut, $wgRequest, $mode );
64 $uid = $wgUser->getId();
65 if( ($wgEnotifWatchlist ||
$wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) &&
66 $wgRequest->wasPosted() )
68 $wgUser->clearAllNotifications( $uid );
69 $wgOut->redirect( $specialTitle->getFullUrl() );
74 /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
75 /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
76 /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
77 /* bool */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ),
78 /* bool */ 'hideLiu' => (int)$wgUser->getBoolOption( 'watchlisthideliu' ),
79 /* bool */ 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ),
80 /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
81 /* ? */ 'namespace' => 'all',
82 /* ? */ 'invert' => false,
87 # Extract variables from the request, falling back to user preferences or
88 # other default values if these don't exist
89 $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) );
90 $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
91 $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
92 $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanon' );
93 $prefs['hideliu'] = $wgUser->getBoolOption( 'watchlisthideliu' );
94 $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
95 $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' );
98 $days = $wgRequest->getVal( 'days' , $prefs['days'] );
99 $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
100 $hideBots = $wgRequest->getBool( 'hideBots' , $prefs['hidebots'] );
101 $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] );
102 $hideLiu = $wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] );
103 $hideOwn = $wgRequest->getBool( 'hideOwn' , $prefs['hideown'] );
104 $hidePatrolled = $wgRequest->getBool( 'hidePatrolled' , $prefs['hidepatrolled'] );
106 # Get namespace value, if supplied, and prepare a WHERE fragment
107 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
108 $invert = $wgRequest->getIntOrNull( 'invert' );
109 if( !is_null( $nameSpace ) ) {
110 $nameSpace = intval( $nameSpace );
111 if( $invert && $nameSpace !== 'all' )
112 $nameSpaceClause = "rc_namespace != $nameSpace";
114 $nameSpaceClause = "rc_namespace = $nameSpace";
117 $nameSpaceClause = '';
120 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
121 $recentchanges = $dbr->tableName( 'recentchanges' );
123 $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
124 array( 'wl_user' => $uid ), __METHOD__
);
125 // Adjust for page X, talk:page X, which are both stored separately,
126 // but treated together
127 $nitems = floor($watchlistCount / 2);
129 if( is_null($days) ||
!is_numeric($days) ) {
130 $big = 1000; /* The magical big */
132 # Set default cutoff shorter
133 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
135 $days = $defaults['days']; # default cutoff for shortlisters
138 $days = floatval($days);
141 // Dump everything here
142 $nondefaults = array();
144 wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults);
145 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
146 wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults);
147 wfAppendToArrayIfNotDefault( 'hideAnons', (int)$hideAnons, $defaults, $nondefaults );
148 wfAppendToArrayIfNotDefault( 'hideLiu' , (int)$hideLiu , $defaults, $nondefaults );
149 wfAppendToArrayIfNotDefault( 'hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
150 wfAppendToArrayIfNotDefault( 'namespace', $nameSpace , $defaults, $nondefaults);
151 wfAppendToArrayIfNotDefault( 'hidePatrolled', (int)$hidePatrolled, $defaults, $nondefaults );
154 $wgOut->addWikiMsg( 'nowatchlist' );
158 # Possible where conditions
164 $conds[] = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
167 # If the watchlist is relatively short, it's simplest to zip
168 # down its entirety and then sort the results.
170 # If it's relatively long, it may be worth our while to zip
171 # through the time-sorted page list checking for watched items.
173 # Up estimate of watched items by 15% to compensate for talk pages...
177 $conds[] = "rc_user != $uid";
180 $conds[] = 'rc_bot = 0';
183 $conds[] = 'rc_minor = 0';
186 $conds[] = 'rc_user = 0';
189 $conds[] = 'rc_user != 0';
191 if ( $wgUser->useRCPatrol() && $hidePatrolled ) {
192 $conds[] = 'rc_patrolled != 1';
195 # Toggle watchlist content (all recent edits or just the latest)
196 if( $wgUser->getOption( 'extendwatchlist' )) {
197 $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) );
200 # Top log Ids for a page are not stored
201 $conds[] = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG
;
206 # Show a message about slave lag, if applicable
207 if( ( $lag = $dbr->getLag() ) > 0 )
208 $wgOut->showLagWarning( $lag );
211 $form = Xml
::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) );
213 # Show watchlist header
214 $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) );
216 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
217 $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
219 if( $wgShowUpdatedMarker ) {
220 $form .= Xml
::openElement( 'form', array( 'method' => 'post',
221 'action' => $specialTitle->getLocalUrl(),
222 'id' => 'mw-watchlist-resetbutton' ) ) .
223 wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' .
224 Xml
::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) .
225 Xml
::hidden( 'reset', 'all' ) .
226 Xml
::closeElement( 'form' );
230 $tables = array( 'recentchanges', 'watchlist' );
231 $fields = array( "{$recentchanges}.*" );
233 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
235 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
236 if( $wgShowUpdatedMarker ) {
237 $fields[] = 'wl_notificationtimestamp';
239 if( $limitWatchlist ) {
240 $options['LIMIT'] = $limitWatchlist;
243 $rollbacker = $wgUser->isAllowed('rollback');
244 if ( $usePage ||
$rollbacker ) {
246 $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id');
248 $fields[] = 'page_latest';
251 ChangeTags
::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' );
252 wfRunHooks('SpecialWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) );
254 $res = $dbr->select( $tables, $fields, $conds, __METHOD__
, $options, $join_conds );
255 $numRows = $dbr->numRows( $res );
257 /* Start bottom header */
261 $wlInfo = wfMsgExt( 'rcnote', 'parseinline',
262 $wgLang->formatNum( $numRows ),
263 $wgLang->formatNum( $days ),
264 $wgLang->timeAndDate( wfTimestampNow(), true ),
265 $wgLang->date( wfTimestampNow(), true ),
266 $wgLang->time( wfTimestampNow(), true )
268 } elseif( $days > 0 ) {
269 $wlInfo = wfMsgExt( 'wlnote', 'parseinline',
270 $wgLang->formatNum( $numRows ),
271 $wgLang->formatNum( round($days*24) )
275 $cutofflinks = "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n";
277 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
279 # Spit out some control panel links
280 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor );
281 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots );
282 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons );
283 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu );
284 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn );
286 if( $wgUser->useRCPatrol() ) {
287 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled );
290 # Namespace filter and put the whole form together.
292 $form .= $cutofflinks;
293 $form .= $wgLang->pipeList( $links );
294 $form .= Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
295 $form .= '<hr /><p>';
296 $form .= Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
297 $form .= Xml
::namespaceSelector( $nameSpace, '' ) . ' ';
298 $form .= Xml
::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . ' ';
299 $form .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
300 $form .= Xml
::hidden( 'days', $days );
302 $form .= Xml
::hidden( 'hideMinor', 1 );
304 $form .= Xml
::hidden( 'hideBots', 1 );
306 $form .= Xml
::hidden( 'hideAnons', 1 );
308 $form .= Xml
::hidden( 'hideLiu', 1 );
310 $form .= Xml
::hidden( 'hideOwn', 1 );
311 $form .= Xml
::closeElement( 'form' );
312 $form .= Xml
::closeElement( 'fieldset' );
313 $wgOut->addHTML( $form );
315 $wgOut->addHTML( ChangesList
::flagLegend() );
317 # If there's nothing to show, stop here
318 if( $numRows == 0 ) {
319 $wgOut->addWikiMsg( 'watchnochange' );
323 /* End bottom header */
325 /* Do link batch query */
326 $linkBatch = new LinkBatch
;
327 while ( $row = $dbr->fetchObject( $res ) ) {
328 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
329 if ( $row->rc_user
!= 0 ) {
330 $linkBatch->add( NS_USER
, $userNameUnderscored );
332 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
334 $linkBatch->add( $row->rc_namespace
, $row->rc_title
);
336 $linkBatch->execute();
337 $dbr->dataSeek( $res, 0 );
339 $list = ChangesList
::newFromUser( $wgUser );
340 $list->setWatchlistDivs();
342 $s = $list->beginRecentChangesList();
344 while ( $obj = $dbr->fetchObject( $res ) ) {
346 $rc = RecentChange
::newFromRow( $obj );
347 $rc->counter
= $counter++
;
349 if ( $wgShowUpdatedMarker ) {
350 $updated = $obj->wl_notificationtimestamp
;
355 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
356 $rc->numberofWatchingusers
= $dbr->selectField( 'watchlist',
359 'wl_namespace' => $obj->rc_namespace
,
360 'wl_title' => $obj->rc_title
,
364 $rc->numberofWatchingusers
= 0;
367 $s .= $list->recentChangesLine( $rc, $updated, $counter );
369 $s .= $list->endRecentChangesList();
371 $dbr->freeResult( $res );
372 $wgOut->addHTML( $s );
375 function wlShowHideLink( $options, $message, $name, $value ) {
378 $showLinktext = wfMsgHtml( 'show' );
379 $hideLinktext = wfMsgHtml( 'hide' );
380 $title = SpecialPage
::getTitleFor( 'Watchlist' );
381 $skin = $wgUser->getSkin();
383 $label = $value ?
$showLinktext : $hideLinktext;
384 $options[$name] = 1 - (int) $value;
386 return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) );
390 function wlHoursLink( $h, $page, $options = array() ) {
391 global $wgUser, $wgLang, $wgContLang;
393 $sk = $wgUser->getSkin();
394 $title = Title
::newFromText( $wgContLang->specialPage( $page ) );
395 $options['days'] = ($h / 24.0);
399 $wgLang->formatNum( $h ),
407 function wlDaysLink( $d, $page, $options = array() ) {
408 global $wgUser, $wgLang, $wgContLang;
410 $sk = $wgUser->getSkin();
411 $title = Title
::newFromText( $wgContLang->specialPage( $page ) );
412 $options['days'] = $d;
413 $message = ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) );
428 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
431 $hours = array( 1, 2, 6, 12 );
432 $days = array( 1, 3, 7 );
434 foreach( $hours as $h ) {
435 $hours[$i++
] = wlHoursLink( $h, $page, $options );
438 foreach( $days as $d ) {
439 $days[$i++
] = wlDaysLink( $d, $page, $options );
441 return wfMsgExt('wlshowlast',
442 array('parseinline', 'replaceafter'),
443 $wgLang->pipeList( $hours ),
444 $wgLang->pipeList( $days ),
445 wlDaysLink( 0, $page, $options ) );
449 * Count the number of items on a user's watchlist
451 * @param $talk Include talk pages
454 function wlCountItems( &$user, $talk = true ) {
455 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
457 # Fetch the raw count
458 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
459 array( 'wl_user' => $user->mId
), 'wlCountItems' );
460 $row = $dbr->fetchObject( $res );
461 $count = $row->count
;
462 $dbr->freeResult( $res );
464 # Halve to remove talk pages if needed
466 $count = floor( $count / 2 );