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 $wlToken = sha1( mt_rand() . microtime( true ) );
21 $wgUser->setOption( 'watchlisttoken', $wlToken );
22 $wgUser->saveSettings();
25 global $wgServer, $wgScriptPath, $wgFeedClasses;
26 $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
27 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken );
28 $feedTemplate = wfScript('api').'?';
30 foreach( $wgFeedClasses as $format => $class ) {
31 $theseParams = $apiParams +
array( 'feedformat' => $format );
32 $url = $feedTemplate . wfArrayToCGI( $theseParams );
33 $wgOut->addFeedLink( $format, $url );
36 $skin = $wgUser->getSkin();
37 $specialTitle = SpecialPage
::getTitleFor( 'Watchlist' );
38 $wgOut->setRobotPolicy( 'noindex,nofollow' );
40 # Anons don't get a watchlist
41 if( $wgUser->isAnon() ) {
42 $wgOut->setPageTitle( wfMsg( 'watchnologin' ) );
43 $llink = $skin->linkKnown(
44 SpecialPage
::getTitleFor( 'Userlogin' ),
45 wfMsgHtml( 'loginreqlink' ),
47 array( 'returnto' => $specialTitle->getPrefixedText() )
49 $wgOut->addHTML( wfMsgWikiHtml( 'watchlistanontext', $llink ) );
53 $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
55 $sub = wfMsgExt( 'watchlistfor', 'parseinline', $wgUser->getName() );
56 $sub .= '<br />' . WatchlistEditor
::buildTools( $wgUser->getSkin() );
57 $wgOut->setSubtitle( $sub );
59 if( ( $mode = WatchlistEditor
::getMode( $wgRequest, $par ) ) !== false ) {
60 $editor = new WatchlistEditor();
61 $editor->execute( $wgUser, $wgOut, $wgRequest, $mode );
65 $uid = $wgUser->getId();
66 if( ($wgEnotifWatchlist ||
$wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) &&
67 $wgRequest->wasPosted() )
69 $wgUser->clearAllNotifications( $uid );
70 $wgOut->redirect( $specialTitle->getFullUrl() );
75 /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
76 /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
77 /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
78 /* bool */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ),
79 /* bool */ 'hideLiu' => (int)$wgUser->getBoolOption( 'watchlisthideliu' ),
80 /* bool */ 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ),
81 /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
82 /* ? */ 'namespace' => 'all',
83 /* ? */ 'invert' => false,
88 # Extract variables from the request, falling back to user preferences or
89 # other default values if these don't exist
90 $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) );
91 $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
92 $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
93 $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanon' );
94 $prefs['hideliu'] = $wgUser->getBoolOption( 'watchlisthideliu' );
95 $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
96 $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' );
99 $days = $wgRequest->getVal( 'days' , $prefs['days'] );
100 $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
101 $hideBots = $wgRequest->getBool( 'hideBots' , $prefs['hidebots'] );
102 $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] );
103 $hideLiu = $wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] );
104 $hideOwn = $wgRequest->getBool( 'hideOwn' , $prefs['hideown'] );
105 $hidePatrolled = $wgRequest->getBool( 'hidePatrolled' , $prefs['hidepatrolled'] );
107 # Get namespace value, if supplied, and prepare a WHERE fragment
108 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
109 $invert = $wgRequest->getIntOrNull( 'invert' );
110 if( !is_null( $nameSpace ) ) {
111 $nameSpace = intval( $nameSpace );
112 if( $invert && $nameSpace !== 'all' )
113 $nameSpaceClause = "rc_namespace != $nameSpace";
115 $nameSpaceClause = "rc_namespace = $nameSpace";
118 $nameSpaceClause = '';
121 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
122 $recentchanges = $dbr->tableName( 'recentchanges' );
124 $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
125 array( 'wl_user' => $uid ), __METHOD__
);
126 // Adjust for page X, talk:page X, which are both stored separately,
127 // but treated together
128 $nitems = floor($watchlistCount / 2);
130 if( is_null($days) ||
!is_numeric($days) ) {
131 $big = 1000; /* The magical big */
133 # Set default cutoff shorter
134 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
136 $days = $defaults['days']; # default cutoff for shortlisters
139 $days = floatval($days);
142 // Dump everything here
143 $nondefaults = array();
145 wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults);
146 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
147 wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults);
148 wfAppendToArrayIfNotDefault( 'hideAnons', (int)$hideAnons, $defaults, $nondefaults );
149 wfAppendToArrayIfNotDefault( 'hideLiu' , (int)$hideLiu , $defaults, $nondefaults );
150 wfAppendToArrayIfNotDefault( 'hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
151 wfAppendToArrayIfNotDefault( 'namespace', $nameSpace , $defaults, $nondefaults);
152 wfAppendToArrayIfNotDefault( 'hidePatrolled', (int)$hidePatrolled, $defaults, $nondefaults );
155 $wgOut->addWikiMsg( 'nowatchlist' );
162 $andcutoff = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
165 # If the watchlist is relatively short, it's simplest to zip
166 # down its entirety and then sort the results.
168 # If it's relatively long, it may be worth our while to zip
169 # through the time-sorted page list checking for watched items.
171 # Up estimate of watched items by 15% to compensate for talk pages...
174 $andHideOwn = $hideOwn ?
"rc_user != $uid" : '';
175 $andHideBots = $hideBots ?
"rc_bot = 0" : '';
176 $andHideMinor = $hideMinor ?
"rc_minor = 0" : '';
177 $andHideLiu = $hideLiu ?
"rc_user = 0" : '';
178 $andHideAnons = $hideAnons ?
"rc_user != 0" : '';
179 $andHidePatrolled = $wgUser->useRCPatrol() && $hidePatrolled ?
"rc_patrolled != 1" : '';
181 # Toggle watchlist content (all recent edits or just the latest)
182 if( $wgUser->getOption( 'extendwatchlist' )) {
184 $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) );
187 # Top log Ids for a page are not stored
188 $andLatest = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG
;
193 # Show a message about slave lag, if applicable
194 if( ( $lag = $dbr->getLag() ) > 0 )
195 $wgOut->showLagWarning( $lag );
198 $form = Xml
::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) );
200 # Show watchlist header
201 $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) );
203 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
204 $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
206 if( $wgShowUpdatedMarker ) {
207 $form .= Xml
::openElement( 'form', array( 'method' => 'post',
208 'action' => $specialTitle->getLocalUrl(),
209 'id' => 'mw-watchlist-resetbutton' ) ) .
210 wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' .
211 Xml
::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) .
212 Xml
::hidden( 'reset', 'all' ) .
213 Xml
::closeElement( 'form' );
217 $tables = array( 'recentchanges', 'watchlist' );
218 $fields = array( "{$recentchanges}.*" );
221 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
223 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
224 if( $wgShowUpdatedMarker ) {
225 $fields[] = 'wl_notificationtimestamp';
227 if( $limitWatchlist ) {
228 $options['LIMIT'] = $limitWatchlist;
230 if( $andcutoff ) $conds[] = $andcutoff;
231 if( $andLatest ) $conds[] = $andLatest;
232 if( $andHideOwn ) $conds[] = $andHideOwn;
233 if( $andHideBots ) $conds[] = $andHideBots;
234 if( $andHideMinor ) $conds[] = $andHideMinor;
235 if( $andHideLiu ) $conds[] = $andHideLiu;
236 if( $andHideAnons ) $conds[] = $andHideAnons;
237 if( $andHidePatrolled ) $conds[] = $andHidePatrolled;
238 if( $nameSpaceClause ) $conds[] = $nameSpaceClause;
240 $rollbacker = $wgUser->isAllowed('rollback');
241 if ( $usePage ||
$rollbacker ) {
243 $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id');
245 $fields[] = 'page_latest';
248 ChangeTags
::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' );
249 wfRunHooks('SpecialWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) );
251 $res = $dbr->select( $tables, $fields, $conds, __METHOD__
, $options, $join_conds );
252 $numRows = $dbr->numRows( $res );
254 /* Start bottom header */
258 $wlInfo = wfMsgExt( 'rcnote', 'parseinline',
259 $wgLang->formatNum( $numRows ),
260 $wgLang->formatNum( $days ),
261 $wgLang->timeAndDate( wfTimestampNow(), true ),
262 $wgLang->date( wfTimestampNow(), true ),
263 $wgLang->time( wfTimestampNow(), true )
265 } elseif( $days > 0 ) {
266 $wlInfo = wfMsgExt( 'wlnote', 'parseinline',
267 $wgLang->formatNum( $numRows ),
268 $wgLang->formatNum( round($days*24) )
272 $cutofflinks = "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n";
274 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
276 # Spit out some control panel links
277 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor );
278 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots );
279 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons );
280 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu );
281 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn );
283 if( $wgUser->useRCPatrol() ) {
284 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled );
287 # Namespace filter and put the whole form together.
289 $form .= $cutofflinks;
290 $form .= $wgLang->pipeList( $links );
291 $form .= Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
292 $form .= '<hr /><p>';
293 $form .= Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
294 $form .= Xml
::namespaceSelector( $nameSpace, '' ) . ' ';
295 $form .= Xml
::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . ' ';
296 $form .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
297 $form .= Xml
::hidden( 'days', $days );
299 $form .= Xml
::hidden( 'hideMinor', 1 );
301 $form .= Xml
::hidden( 'hideBots', 1 );
303 $form .= Xml
::hidden( 'hideAnons', 1 );
305 $form .= Xml
::hidden( 'hideLiu', 1 );
307 $form .= Xml
::hidden( 'hideOwn', 1 );
308 $form .= Xml
::closeElement( 'form' );
309 $form .= Xml
::closeElement( 'fieldset' );
310 $wgOut->addHTML( $form );
312 $wgOut->addHTML( ChangesList
::flagLegend() );
314 # If there's nothing to show, stop here
315 if( $numRows == 0 ) {
316 $wgOut->addWikiMsg( 'watchnochange' );
320 /* End bottom header */
322 /* Do link batch query */
323 $linkBatch = new LinkBatch
;
324 while ( $row = $dbr->fetchObject( $res ) ) {
325 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
326 if ( $row->rc_user
!= 0 ) {
327 $linkBatch->add( NS_USER
, $userNameUnderscored );
329 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
331 $linkBatch->add( $row->rc_namespace
, $row->rc_title
);
333 $linkBatch->execute();
334 $dbr->dataSeek( $res, 0 );
336 $list = ChangesList
::newFromUser( $wgUser );
337 $list->setWatchlistDivs();
339 $s = $list->beginRecentChangesList();
341 while ( $obj = $dbr->fetchObject( $res ) ) {
343 $rc = RecentChange
::newFromRow( $obj );
344 $rc->counter
= $counter++
;
346 if ( $wgShowUpdatedMarker ) {
347 $updated = $obj->wl_notificationtimestamp
;
352 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
353 $rc->numberofWatchingusers
= $dbr->selectField( 'watchlist',
356 'wl_namespace' => $obj->rc_namespace
,
357 'wl_title' => $obj->rc_title
,
361 $rc->numberofWatchingusers
= 0;
364 $s .= $list->recentChangesLine( $rc, $updated, $counter );
366 $s .= $list->endRecentChangesList();
368 $dbr->freeResult( $res );
369 $wgOut->addHTML( $s );
372 function wlShowHideLink( $options, $message, $name, $value ) {
375 $showLinktext = wfMsgHtml( 'show' );
376 $hideLinktext = wfMsgHtml( 'hide' );
377 $title = SpecialPage
::getTitleFor( 'Watchlist' );
378 $skin = $wgUser->getSkin();
380 $label = $value ?
$showLinktext : $hideLinktext;
381 $options[$name] = 1 - (int) $value;
383 return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) );
387 function wlHoursLink( $h, $page, $options = array() ) {
388 global $wgUser, $wgLang, $wgContLang;
390 $sk = $wgUser->getSkin();
391 $title = Title
::newFromText( $wgContLang->specialPage( $page ) );
392 $options['days'] = ($h / 24.0);
396 $wgLang->formatNum( $h ),
404 function wlDaysLink( $d, $page, $options = array() ) {
405 global $wgUser, $wgLang, $wgContLang;
407 $sk = $wgUser->getSkin();
408 $title = Title
::newFromText( $wgContLang->specialPage( $page ) );
409 $options['days'] = $d;
410 $message = ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) );
425 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
428 $hours = array( 1, 2, 6, 12 );
429 $days = array( 1, 3, 7 );
431 foreach( $hours as $h ) {
432 $hours[$i++
] = wlHoursLink( $h, $page, $options );
435 foreach( $days as $d ) {
436 $days[$i++
] = wlDaysLink( $d, $page, $options );
438 return wfMsgExt('wlshowlast',
439 array('parseinline', 'replaceafter'),
440 $wgLang->pipeList( $hours ),
441 $wgLang->pipeList( $days ),
442 wlDaysLink( 0, $page, $options ) );
446 * Count the number of items on a user's watchlist
448 * @param $talk Include talk pages
451 function wlCountItems( &$user, $talk = true ) {
452 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
454 # Fetch the raw count
455 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
456 array( 'wl_user' => $user->mId
), 'wlCountItems' );
457 $row = $dbr->fetchObject( $res );
458 $count = $row->count
;
459 $dbr->freeResult( $res );
461 # Halve to remove talk pages if needed
463 $count = floor( $count / 2 );