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;
17 $skin = $wgUser->getSkin();
18 $specialTitle = SpecialPage
::getTitleFor( 'Watchlist' );
19 $wgOut->setRobotPolicy( 'noindex,nofollow' );
21 # Anons don't get a watchlist
22 if( $wgUser->isAnon() ) {
23 $wgOut->setPageTitle( wfMsg( 'watchnologin' ) );
24 $llink = $skin->linkKnown(
25 SpecialPage
::getTitleFor( 'Userlogin' ),
26 wfMsgHtml( 'loginreqlink' ),
28 array( 'returnto' => $specialTitle->getPrefixedText() )
30 $wgOut->addHTML( wfMsgWikiHtml( 'watchlistanontext', $llink ) );
34 $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
36 $sub = wfMsgExt( 'watchlistfor', 'parseinline', $wgUser->getName() );
37 $sub .= '<br />' . WatchlistEditor
::buildTools( $wgUser->getSkin() );
38 $wgOut->setSubtitle( $sub );
40 if( ( $mode = WatchlistEditor
::getMode( $wgRequest, $par ) ) !== false ) {
41 $editor = new WatchlistEditor();
42 $editor->execute( $wgUser, $wgOut, $wgRequest, $mode );
46 $uid = $wgUser->getId();
47 if( ($wgEnotifWatchlist ||
$wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) &&
48 $wgRequest->wasPosted() )
50 $wgUser->clearAllNotifications( $uid );
51 $wgOut->redirect( $specialTitle->getFullUrl() );
56 /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
57 /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
58 /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
59 /* bool */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ),
60 /* bool */ 'hideLiu' => (int)$wgUser->getBoolOption( 'watchlisthideliu' ),
61 /* bool */ 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ),
62 /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
63 /* ? */ 'namespace' => 'all',
64 /* ? */ 'invert' => false,
69 # Extract variables from the request, falling back to user preferences or
70 # other default values if these don't exist
71 $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) );
72 $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
73 $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
74 $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanon' );
75 $prefs['hideliu'] = $wgUser->getBoolOption( 'watchlisthideliu' );
76 $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
77 $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' );
80 $days = $wgRequest->getVal( 'days' , $prefs['days'] );
81 $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
82 $hideBots = $wgRequest->getBool( 'hideBots' , $prefs['hidebots'] );
83 $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] );
84 $hideLiu = $wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] );
85 $hideOwn = $wgRequest->getBool( 'hideOwn' , $prefs['hideown'] );
86 $hidePatrolled = $wgRequest->getBool( 'hidePatrolled' , $prefs['hidepatrolled'] );
88 # Get namespace value, if supplied, and prepare a WHERE fragment
89 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
90 $invert = $wgRequest->getIntOrNull( 'invert' );
91 if( !is_null( $nameSpace ) ) {
92 $nameSpace = intval( $nameSpace );
93 if( $invert && $nameSpace !== 'all' )
94 $nameSpaceClause = "rc_namespace != $nameSpace";
96 $nameSpaceClause = "rc_namespace = $nameSpace";
99 $nameSpaceClause = '';
102 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
103 $recentchanges = $dbr->tableName( 'recentchanges' );
105 $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
106 array( 'wl_user' => $uid ), __METHOD__
);
107 // Adjust for page X, talk:page X, which are both stored separately,
108 // but treated together
109 $nitems = floor($watchlistCount / 2);
111 if( is_null($days) ||
!is_numeric($days) ) {
112 $big = 1000; /* The magical big */
114 # Set default cutoff shorter
115 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
117 $days = $defaults['days']; # default cutoff for shortlisters
120 $days = floatval($days);
123 // Dump everything here
124 $nondefaults = array();
126 wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults);
127 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
128 wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults);
129 wfAppendToArrayIfNotDefault( 'hideAnons', (int)$hideAnons, $defaults, $nondefaults );
130 wfAppendToArrayIfNotDefault( 'hideLiu' , (int)$hideLiu , $defaults, $nondefaults );
131 wfAppendToArrayIfNotDefault( 'hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
132 wfAppendToArrayIfNotDefault( 'namespace', $nameSpace , $defaults, $nondefaults);
133 wfAppendToArrayIfNotDefault( 'hidePatrolled', (int)$hidePatrolled, $defaults, $nondefaults );
136 $wgOut->addWikiMsg( 'nowatchlist' );
143 $andcutoff = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
146 # If the watchlist is relatively short, it's simplest to zip
147 # down its entirety and then sort the results.
149 # If it's relatively long, it may be worth our while to zip
150 # through the time-sorted page list checking for watched items.
152 # Up estimate of watched items by 15% to compensate for talk pages...
155 $andHideOwn = $hideOwn ?
"rc_user != $uid" : '';
156 $andHideBots = $hideBots ?
"rc_bot = 0" : '';
157 $andHideMinor = $hideMinor ?
"rc_minor = 0" : '';
158 $andHideLiu = $hideLiu ?
"rc_user = 0" : '';
159 $andHideAnons = $hideAnons ?
"rc_user != 0" : '';
160 $andHidePatrolled = $wgUser->useRCPatrol() && $hidePatrolled ?
"rc_patrolled != 1" : '';
162 # Toggle watchlist content (all recent edits or just the latest)
163 if( $wgUser->getOption( 'extendwatchlist' )) {
165 $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) );
168 # Top log Ids for a page are not stored
169 $andLatest = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG
;
174 # Show a message about slave lag, if applicable
175 if( ( $lag = $dbr->getLag() ) > 0 )
176 $wgOut->showLagWarning( $lag );
179 $form = Xml
::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) );
181 # Show watchlist header
182 $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) );
184 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
185 $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
187 if( $wgShowUpdatedMarker ) {
188 $form .= Xml
::openElement( 'form', array( 'method' => 'post',
189 'action' => $specialTitle->getLocalUrl(),
190 'id' => 'mw-watchlist-resetbutton' ) ) .
191 wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' .
192 Xml
::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) .
193 Xml
::hidden( 'reset', 'all' ) .
194 Xml
::closeElement( 'form' );
198 $tables = array( 'recentchanges', 'watchlist' );
199 $fields = array( "{$recentchanges}.*" );
202 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
204 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
205 if( $wgShowUpdatedMarker ) {
206 $fields[] = 'wl_notificationtimestamp';
208 if( $limitWatchlist ) {
209 $options['LIMIT'] = $limitWatchlist;
211 if( $andcutoff ) $conds[] = $andcutoff;
212 if( $andLatest ) $conds[] = $andLatest;
213 if( $andHideOwn ) $conds[] = $andHideOwn;
214 if( $andHideBots ) $conds[] = $andHideBots;
215 if( $andHideMinor ) $conds[] = $andHideMinor;
216 if( $andHideLiu ) $conds[] = $andHideLiu;
217 if( $andHideAnons ) $conds[] = $andHideAnons;
218 if( $andHidePatrolled ) $conds[] = $andHidePatrolled;
219 if( $nameSpaceClause ) $conds[] = $nameSpaceClause;
221 $rollbacker = $wgUser->isAllowed('rollback');
222 if ( $usePage ||
$rollbacker ) {
224 $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id');
226 $fields[] = 'page_latest';
229 ChangeTags
::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' );
230 wfRunHooks('SpecialWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) );
232 $res = $dbr->select( $tables, $fields, $conds, __METHOD__
, $options, $join_conds );
233 $numRows = $dbr->numRows( $res );
235 /* Start bottom header */
239 $wlInfo = wfMsgExt( 'rcnote', 'parseinline',
240 $wgLang->formatNum( $numRows ),
241 $wgLang->formatNum( $days ),
242 $wgLang->timeAndDate( wfTimestampNow(), true ),
243 $wgLang->date( wfTimestampNow(), true ),
244 $wgLang->time( wfTimestampNow(), true )
246 } elseif( $days > 0 ) {
247 $wlInfo = wfMsgExt( 'wlnote', 'parseinline',
248 $wgLang->formatNum( $numRows ),
249 $wgLang->formatNum( round($days*24) )
253 $cutofflinks = "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n";
255 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
257 # Spit out some control panel links
258 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor );
259 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots );
260 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons );
261 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu );
262 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn );
264 if( $wgUser->useRCPatrol() ) {
265 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled );
268 # Namespace filter and put the whole form together.
270 $form .= $cutofflinks;
271 $form .= $wgLang->pipeList( $links );
272 $form .= Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
273 $form .= '<hr /><p>';
274 $form .= Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
275 $form .= Xml
::namespaceSelector( $nameSpace, '' ) . ' ';
276 $form .= Xml
::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . ' ';
277 $form .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
278 $form .= Xml
::hidden( 'days', $days );
280 $form .= Xml
::hidden( 'hideMinor', 1 );
282 $form .= Xml
::hidden( 'hideBots', 1 );
284 $form .= Xml
::hidden( 'hideAnons', 1 );
286 $form .= Xml
::hidden( 'hideLiu', 1 );
288 $form .= Xml
::hidden( 'hideOwn', 1 );
289 $form .= Xml
::closeElement( 'form' );
290 $form .= Xml
::closeElement( 'fieldset' );
291 $wgOut->addHTML( $form );
293 $wgOut->addHTML( ChangesList
::flagLegend() );
295 # If there's nothing to show, stop here
296 if( $numRows == 0 ) {
297 $wgOut->addWikiMsg( 'watchnochange' );
301 /* End bottom header */
303 /* Do link batch query */
304 $linkBatch = new LinkBatch
;
305 while ( $row = $dbr->fetchObject( $res ) ) {
306 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
307 if ( $row->rc_user
!= 0 ) {
308 $linkBatch->add( NS_USER
, $userNameUnderscored );
310 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
312 $linkBatch->add( $row->rc_namespace
, $row->rc_title
);
314 $linkBatch->execute();
315 $dbr->dataSeek( $res, 0 );
317 $list = ChangesList
::newFromUser( $wgUser );
318 $list->setWatchlistDivs();
320 $s = $list->beginRecentChangesList();
322 while ( $obj = $dbr->fetchObject( $res ) ) {
324 $rc = RecentChange
::newFromRow( $obj );
325 $rc->counter
= $counter++
;
327 if ( $wgShowUpdatedMarker ) {
328 $updated = $obj->wl_notificationtimestamp
;
333 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
334 $rc->numberofWatchingusers
= $dbr->selectField( 'watchlist',
337 'wl_namespace' => $obj->rc_namespace
,
338 'wl_title' => $obj->rc_title
,
342 $rc->numberofWatchingusers
= 0;
345 $s .= $list->recentChangesLine( $rc, $updated, $counter );
347 $s .= $list->endRecentChangesList();
349 $dbr->freeResult( $res );
350 $wgOut->addHTML( $s );
353 function wlShowHideLink( $options, $message, $name, $value ) {
356 $showLinktext = wfMsgHtml( 'show' );
357 $hideLinktext = wfMsgHtml( 'hide' );
358 $title = SpecialPage
::getTitleFor( 'Watchlist' );
359 $skin = $wgUser->getSkin();
361 $label = $value ?
$showLinktext : $hideLinktext;
362 $options[$name] = 1 - (int) $value;
364 return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) );
368 function wlHoursLink( $h, $page, $options = array() ) {
369 global $wgUser, $wgLang, $wgContLang;
371 $sk = $wgUser->getSkin();
372 $title = Title
::newFromText( $wgContLang->specialPage( $page ) );
373 $options['days'] = ($h / 24.0);
377 $wgLang->formatNum( $h ),
385 function wlDaysLink( $d, $page, $options = array() ) {
386 global $wgUser, $wgLang, $wgContLang;
388 $sk = $wgUser->getSkin();
389 $title = Title
::newFromText( $wgContLang->specialPage( $page ) );
390 $options['days'] = $d;
391 $message = ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) );
406 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
409 $hours = array( 1, 2, 6, 12 );
410 $days = array( 1, 3, 7 );
412 foreach( $hours as $h ) {
413 $hours[$i++
] = wlHoursLink( $h, $page, $options );
416 foreach( $days as $d ) {
417 $days[$i++
] = wlDaysLink( $d, $page, $options );
419 return wfMsgExt('wlshowlast',
420 array('parseinline', 'replaceafter'),
421 $wgLang->pipeList( $hours ),
422 $wgLang->pipeList( $days ),
423 wlDaysLink( 0, $page, $options ) );
427 * Count the number of items on a user's watchlist
429 * @param $talk Include talk pages
432 function wlCountItems( &$user, $talk = true ) {
433 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
435 # Fetch the raw count
436 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
437 array( 'wl_user' => $user->mId
), 'wlCountItems' );
438 $row = $dbr->fetchObject( $res );
439 $count = $row->count
;
440 $dbr->freeResult( $res );
442 # Halve to remove talk pages if needed
444 $count = floor( $count / 2 );