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->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Userlogin' ),
25 wfMsgHtml( 'loginreqlink' ), 'returnto=' . $specialTitle->getPrefixedUrl() );
26 $wgOut->addHTML( wfMsgWikiHtml( 'watchlistanontext', $llink ) );
30 $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
32 $sub = wfMsgExt( 'watchlistfor', 'parseinline', $wgUser->getName() );
33 $sub .= '<br />' . WatchlistEditor
::buildTools( $wgUser->getSkin() );
34 $wgOut->setSubtitle( $sub );
36 if( ( $mode = WatchlistEditor
::getMode( $wgRequest, $par ) ) !== false ) {
37 $editor = new WatchlistEditor();
38 $editor->execute( $wgUser, $wgOut, $wgRequest, $mode );
42 $uid = $wgUser->getId();
43 if( ($wgEnotifWatchlist ||
$wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) &&
44 $wgRequest->wasPosted() )
46 $wgUser->clearAllNotifications( $uid );
47 $wgOut->redirect( $specialTitle->getFullUrl() );
52 /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
53 /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
54 /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
55 /* bool */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ),
56 /* bool */ 'hideLiu' => (int)$wgUser->getBoolOption( 'watchlisthideliu' ),
57 /* bool */ 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ), // TODO
58 /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
59 /* ? */ 'namespace' => 'all',
60 /* ? */ 'invert' => false,
65 # Extract variables from the request, falling back to user preferences or
66 # other default values if these don't exist
67 $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) );
68 $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
69 $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
70 $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanon' );
71 $prefs['hideliu'] = $wgUser->getBoolOption( 'watchlisthideliu' );
72 $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
73 $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' );
76 $days = $wgRequest->getVal( 'days' , $prefs['days'] );
77 $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
78 $hideBots = $wgRequest->getBool( 'hideBots' , $prefs['hidebots'] );
79 $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] );
80 $hideLiu = $wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] );
81 $hideOwn = $wgRequest->getBool( 'hideOwn' , $prefs['hideown'] );
82 $hidePatrolled = $wgRequest->getBool( 'hidePatrolled' , $prefs['hidepatrolled'] );
84 # Get namespace value, if supplied, and prepare a WHERE fragment
85 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
86 $invert = $wgRequest->getIntOrNull( 'invert' );
87 if( !is_null( $nameSpace ) ) {
88 $nameSpace = intval( $nameSpace );
89 if( $invert && $nameSpace !== 'all' )
90 $nameSpaceClause = "rc_namespace != $nameSpace";
92 $nameSpaceClause = "rc_namespace = $nameSpace";
95 $nameSpaceClause = '';
98 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
99 list( $page, $watchlist, $recentchanges ) = $dbr->tableNamesN( 'page', 'watchlist', 'recentchanges' );
101 $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
102 array( 'wl_user' => $uid ), __METHOD__
);
103 // Adjust for page X, talk:page X, which are both stored separately,
104 // but treated together
105 $nitems = floor($watchlistCount / 2);
107 if( is_null($days) ||
!is_numeric($days) ) {
108 $big = 1000; /* The magical big */
110 # Set default cutoff shorter
111 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
113 $days = $defaults['days']; # default cutoff for shortlisters
116 $days = floatval($days);
119 // Dump everything here
120 $nondefaults = array();
122 wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults);
123 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
124 wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults);
125 wfAppendToArrayIfNotDefault( 'hideAnons', (int)$hideAnons, $defaults, $nondefaults );
126 wfAppendToArrayIfNotDefault( 'hideLiu' , (int)$hideLiu , $defaults, $nondefaults );
127 wfAppendToArrayIfNotDefault( 'hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
128 wfAppendToArrayIfNotDefault( 'namespace', $nameSpace , $defaults, $nondefaults);
129 wfAppendToArrayIfNotDefault( 'hidePatrolled', (int)$hidePatrolled, $defaults, $nondefaults );
132 if( ! wfRunHooks('BeforeWatchlist', array($nondefaults, $wgUser, &$hookSql)) ) {
137 $wgOut->addWikiMsg( 'nowatchlist' );
144 $andcutoff = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
147 # If the watchlist is relatively short, it's simplest to zip
148 # down its entirety and then sort the results.
150 # If it's relatively long, it may be worth our while to zip
151 # through the time-sorted page list checking for watched items.
153 # Up estimate of watched items by 15% to compensate for talk pages...
156 $andHideOwn = $hideOwn ?
"rc_user != $uid" : '';
157 $andHideBots = $hideBots ?
"rc_bot = 0" : '';
158 $andHideMinor = $hideMinor ?
"rc_minor = 0" : '';
159 $andHideLiu = $hideLiu ?
"rc_user = 0" : '';
160 $andHideAnons = $hideAnons ?
"rc_user != 0" : '';
161 $andHidePatrolled = $wgUser->useRCPatrol() && $hidePatrolled ?
"rc_patrolled != 1" : '';
163 # Toggle watchlist content (all recent edits or just the latest)
164 if( $wgUser->getOption( 'extendwatchlist' )) {
166 $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
;
173 # Show a message about slave lag, if applicable
174 if( ( $lag = $dbr->getLag() ) > 0 )
175 $wgOut->showLagWarning( $lag );
178 $form = Xml
::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) );
180 # Show watchlist header
181 $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) );
183 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
184 $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
186 if( $wgShowUpdatedMarker ) {
187 $form .= Xml
::openElement( 'form', array( 'method' => 'post',
188 'action' => $specialTitle->getLocalUrl(),
189 'id' => 'mw-watchlist-resetbutton' ) ) .
190 wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' .
191 Xml
::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) .
192 Xml
::hidden( 'reset', 'all' ) .
193 Xml
::closeElement( 'form' );
197 $tables = array( 'recentchanges', 'watchlist', 'page' );
198 $fields = array( "{$recentchanges}.*" );
201 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
202 'page' => array('LEFT JOIN','rc_cur_id=page_id')
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;
220 if( $hookSql ) $conds[] = $hookSql;
222 $res = $dbr->select( $tables, $fields, $conds, __METHOD__
, $options, $join_conds );
223 $numRows = $dbr->numRows( $res );
225 /* Start bottom header */
229 $wlInfo = wfMsgExt( 'rcnote', 'parseinline',
230 $wgLang->formatNum( $numRows ),
231 $wgLang->formatNum( $days ),
232 $wgLang->timeAndDate( wfTimestampNow(), true ),
233 $wgLang->date( wfTimestampNow(), true ),
234 $wgLang->time( wfTimestampNow(), true )
236 } elseif( $days > 0 ) {
237 $wlInfo = wfMsgExt( 'wlnote', 'parseinline',
238 $wgLang->formatNum( $numRows ),
239 $wgLang->formatNum( round($days*24) )
243 $cutofflinks = "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n";
245 # Spit out some control panel links
246 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
247 $skin = $wgUser->getSkin();
249 $showLinktext = wfMsgHtml( 'show' );
250 $hideLinktext = wfMsgHtml( 'hide' );
251 # Hide/show minor edits
252 $label = $hideMinor ?
$showLinktext : $hideLinktext;
253 $linkBits = wfArrayToCGI( array( 'hideMinor' => 1 - (int)$hideMinor ), $nondefaults );
254 $links[] = wfMsgHtml( 'rcshowhideminor', $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits ) );
256 # Hide/show bot edits
257 $label = $hideBots ?
$showLinktext : $hideLinktext;
258 $linkBits = wfArrayToCGI( array( 'hideBots' => 1 - (int)$hideBots ), $nondefaults );
259 $links[] = wfMsgHtml( 'rcshowhidebots', $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits ) );
261 # Hide/show anonymous edits
262 $label = $hideAnons ?
$showLinktext : $hideLinktext;
263 $linkBits = wfArrayToCGI( array( 'hideAnons' => 1 - (int)$hideAnons ), $nondefaults );
264 $links[] = wfMsgHtml( 'rcshowhideanons', $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits ) );
266 # Hide/show logged in edits
267 $label = $hideLiu ?
$showLinktext : $hideLinktext;
268 $linkBits = wfArrayToCGI( array( 'hideLiu' => 1 - (int)$hideLiu ), $nondefaults );
269 $links[] = wfMsgHtml( 'rcshowhideliu', $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits ) );
271 # Hide/show own edits
272 $label = $hideOwn ?
$showLinktext : $hideLinktext;
273 $linkBits = wfArrayToCGI( array( 'hideOwn' => 1 - (int)$hideOwn ), $nondefaults );
274 $links[] = wfMsgHtml( 'rcshowhidemine', $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits ) );
276 # Hide/show patrolled edits
277 if( $wgUser->useRCPatrol() ) {
278 $label = $hidePatrolled ?
$showLinktext : $hideLinktext;
279 $linkBits = wfArrayToCGI( array( 'hidePatrolled' => 1 - (int)$hidePatrolled ), $nondefaults );
280 $links[] = wfMsgHtml( 'rcshowhidepatr', $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits ) );
283 # Namespace filter and put the whole form together.
285 $form .= $cutofflinks;
286 $form .= implode( ' | ', $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 # If there's nothing to show, stop here
309 if( $numRows == 0 ) {
310 $wgOut->addWikiMsg( 'watchnochange' );
314 /* End bottom header */
316 /* Do link batch query */
317 $linkBatch = new LinkBatch
;
318 while ( $row = $dbr->fetchObject( $res ) ) {
319 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
320 if ( $row->rc_user
!= 0 ) {
321 $linkBatch->add( NS_USER
, $userNameUnderscored );
323 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
325 $linkBatch->execute();
326 $dbr->dataSeek( $res, 0 );
328 $list = ChangesList
::newFromUser( $wgUser );
330 $s = $list->beginRecentChangesList();
332 while ( $obj = $dbr->fetchObject( $res ) ) {
334 $rc = RecentChange
::newFromRow( $obj );
335 $rc->counter
= $counter++
;
337 if ( $wgShowUpdatedMarker ) {
338 $updated = $obj->wl_notificationtimestamp
;
343 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
344 $rc->numberofWatchingusers
= $dbr->selectField( 'watchlist',
347 'wl_namespace' => $obj->rc_namespace
,
348 'wl_title' => $obj->rc_title
,
352 $rc->numberofWatchingusers
= 0;
355 $s .= $list->recentChangesLine( $rc, $updated );
357 $s .= $list->endRecentChangesList();
359 $dbr->freeResult( $res );
360 $wgOut->addHTML( $s );
363 function wlHoursLink( $h, $page, $options = array() ) {
364 global $wgUser, $wgLang, $wgContLang;
365 $sk = $wgUser->getSkin();
366 $s = $sk->makeKnownLink(
367 $wgContLang->specialPage( $page ),
368 $wgLang->formatNum( $h ),
369 wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
373 function wlDaysLink( $d, $page, $options = array() ) {
374 global $wgUser, $wgLang, $wgContLang;
375 $sk = $wgUser->getSkin();
376 $s = $sk->makeKnownLink(
377 $wgContLang->specialPage( $page ),
378 ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
379 wfArrayToCGI( array('days' => $d), $options ) );
386 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
387 $hours = array( 1, 2, 6, 12 );
388 $days = array( 1, 3, 7 );
390 foreach( $hours as $h ) {
391 $hours[$i++
] = wlHoursLink( $h, $page, $options );
394 foreach( $days as $d ) {
395 $days[$i++
] = wlDaysLink( $d, $page, $options );
397 return wfMsgExt('wlshowlast',
398 array('parseinline', 'replaceafter'),
399 implode(' | ', $hours),
400 implode(' | ', $days),
401 wlDaysLink( 0, $page, $options ) );
405 * Count the number of items on a user's watchlist
407 * @param $talk Include talk pages
410 function wlCountItems( &$user, $talk = true ) {
411 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
413 # Fetch the raw count
414 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
415 array( 'wl_user' => $user->mId
), 'wlCountItems' );
416 $row = $dbr->fetchObject( $res );
417 $count = $row->count
;
418 $dbr->freeResult( $res );
420 # Halve to remove talk pages if needed
422 $count = floor( $count / 2 );