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;
16 $fname = 'wfSpecialWatchlist';
18 $skin = $wgUser->getSkin();
19 $specialTitle = SpecialPage
::getTitleFor( 'Watchlist' );
20 $wgOut->setRobotPolicy( 'noindex,nofollow' );
22 # Anons don't get a watchlist
23 if( $wgUser->isAnon() ) {
24 $wgOut->setPageTitle( wfMsg( 'watchnologin' ) );
25 $llink = $skin->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Userlogin' ), 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' ) && $wgRequest->wasPosted() ) {
44 $wgUser->clearAllNotifications( $uid );
45 $wgOut->redirect( $specialTitle->getFullUrl() );
50 /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
51 /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
52 /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
53 /* bool */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ),
54 /* bool */ 'hideLiu' => (int)$wgUser->getBoolOption( 'watchlisthideliu' ),
55 /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
56 /* ? */ 'namespace' => 'all',
57 /* ? */ 'invert' => false,
62 # Extract variables from the request, falling back to user preferences or
63 # other default values if these don't exist
64 $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) );
65 $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
66 $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
67 $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanon' );
68 $prefs['hideliu'] = $wgUser->getBoolOption( 'watchlisthideliu' );
69 $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
72 $days = $wgRequest->getVal( 'days' , $prefs['days'] );
73 $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
74 $hideBots = $wgRequest->getBool( 'hideBots' , $prefs['hidebots'] );
75 $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] );
76 $hideLiu = $wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] );
77 $hideOwn = $wgRequest->getBool( 'hideOwn' , $prefs['hideown'] );
79 # Get namespace value, if supplied, and prepare a WHERE fragment
80 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
81 $invert = $wgRequest->getIntOrNull( 'invert' );
82 if( !is_null( $nameSpace ) ) {
83 $nameSpace = intval( $nameSpace );
84 if( $invert && $nameSpace !== 'all' )
85 $nameSpaceClause = " AND rc_namespace != $nameSpace";
87 $nameSpaceClause = " AND rc_namespace = $nameSpace";
90 $nameSpaceClause = '';
93 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
94 list( $page, $watchlist, $recentchanges ) = $dbr->tableNamesN( 'page', 'watchlist', 'recentchanges' );
96 $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
97 array( 'wl_user' => $uid ), __METHOD__
);
98 // Adjust for page X, talk:page X, which are both stored separately,
99 // but treated together
100 $nitems = floor($watchlistCount / 2);
102 if( is_null($days) ||
!is_numeric($days) ) {
103 $big = 1000; /* The magical big */
105 # Set default cutoff shorter
106 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
108 $days = $defaults['days']; # default cutoff for shortlisters
111 $days = floatval($days);
114 // Dump everything here
115 $nondefaults = array();
117 wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults);
118 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
119 wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults);
120 wfAppendToArrayIfNotDefault( 'hideAnons', (int)$hideAnons, $defaults, $nondefaults );
121 wfAppendToArrayIfNotDefault( 'hideLiu' , (int)$hideLiu , $defaults, $nondefaults );
122 wfAppendToArrayIfNotDefault( 'hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
123 wfAppendToArrayIfNotDefault( 'namespace', $nameSpace , $defaults, $nondefaults);
126 if( ! wfRunHooks('BeforeWatchlist', array($nondefaults, $wgUser, &$hookSql)) ) {
131 $wgOut->addWikiMsg( 'nowatchlist' );
138 $andcutoff = "AND rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
140 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
141 $res = $dbr->query( $sql, $fname );
142 $s = $dbr->fetchObject( $res );
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 ?
"AND (rc_user <> $uid)" : '';
157 $andHideBots = $hideBots ?
"AND (rc_bot = 0)" : '';
158 $andHideMinor = $hideMinor ?
"AND (rc_minor = 0)" : '';
159 $andHideLiu = $hideLiu ?
"AND (rc_user = 0)" : '';
160 $andHideAnons = $hideAnons ?
"AND (rc_user != 0)" : '';
162 # Toggle watchlist content (all recent edits or just the latest)
163 if( $wgUser->getOption( 'extendwatchlist' )) {
165 $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) );
167 # Top log Ids for a page are not stored
168 $andLatest = 'AND (rc_this_oldid=page_latest OR rc_type=' . RC_LOG
. ') ';
169 $limitWatchlist = '';
172 # Show a message about slave lag, if applicable
173 if( ( $lag = $dbr->getLag() ) > 0 )
174 $wgOut->showLagWarning( $lag );
177 $form = Xml
::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) );
179 # Show watchlist header
180 $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) );
182 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
183 $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
185 if ( $wgShowUpdatedMarker ) {
186 $form .= Xml
::openElement( 'form', array( 'method' => 'post',
187 'action' => $specialTitle->getLocalUrl(),
188 'id' => 'mw-watchlist-resetbutton' ) ) .
189 wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' .
190 Xml
::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) .
191 Xml
::hidden( 'reset', 'all' ) .
192 Xml
::closeElement( 'form' );
196 if ( $wgShowUpdatedMarker ) {
197 $wltsfield = ", ${watchlist}.wl_notificationtimestamp ";
201 $sql = "SELECT ${recentchanges}.* ${wltsfield}
202 FROM $watchlist,$recentchanges
203 LEFT JOIN $page ON rc_cur_id=page_id
205 AND wl_namespace=rc_namespace
206 AND wl_title=rc_title
216 ORDER BY rc_timestamp DESC
219 $res = $dbr->query( $sql, $fname );
220 $numRows = $dbr->numRows( $res );
222 /* Start bottom header */
226 $wlInfo = wfMsgExt( 'rcnote', 'parseinline',
227 $wgLang->formatNum( $numRows ),
228 $wgLang->formatNum( $days ),
229 $wgLang->timeAndDate( wfTimestampNow(), true ),
230 $wgLang->date( wfTimestampNow(), true ),
231 $wgLang->time( wfTimestampNow(), true )
233 } elseif( $days > 0 ) {
234 $wlInfo = wfMsgExt( 'wlnote', 'parseinline',
235 $wgLang->formatNum( $numRows ),
236 $wgLang->formatNum( round($days*24) )
240 $cutofflinks = "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n";
242 # Spit out some control panel links
243 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
244 $skin = $wgUser->getSkin();
246 # Hide/show minor edits
247 $label = $hideMinor ?
wfMsgHtml( 'watchlist-show-minor' ) : wfMsgHtml( 'watchlist-hide-minor' );
248 $linkBits = wfArrayToCGI( array( 'hideMinor' => 1 - (int)$hideMinor ), $nondefaults );
249 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
251 # Hide/show bot edits
252 $label = $hideBots ?
wfMsgHtml( 'watchlist-show-bots' ) : wfMsgHtml( 'watchlist-hide-bots' );
253 $linkBits = wfArrayToCGI( array( 'hideBots' => 1 - (int)$hideBots ), $nondefaults );
254 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
256 # Hide/show anonymous edits
257 $label = $hideAnons ?
wfMsgHtml( 'watchlist-show-anons' ) : wfMsgHtml( 'watchlist-hide-anons' );
258 $linkBits = wfArrayToCGI( array( 'hideAnons' => 1 - (int)$hideAnons ), $nondefaults );
259 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
261 # Hide/show logged in edits
262 $label = $hideLiu ?
wfMsgHtml( 'watchlist-show-liu' ) : wfMsgHtml( 'watchlist-hide-liu' );
263 $linkBits = wfArrayToCGI( array( 'hideLiu' => 1 - (int)$hideLiu ), $nondefaults );
264 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
266 # Hide/show own edits
267 $label = $hideOwn ?
wfMsgHtml( 'watchlist-show-own' ) : wfMsgHtml( 'watchlist-hide-own' );
268 $linkBits = wfArrayToCGI( array( 'hideOwn' => 1 - (int)$hideOwn ), $nondefaults );
269 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
271 # Namespace filter and put the whole form together.
273 $form .= $cutofflinks;
274 $form .= implode( ' | ', $links );
275 $form .= Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
277 $form .= Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
278 $form .= Xml
::namespaceSelector( $nameSpace, '' ) . ' ';
279 $form .= Xml
::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . ' ';
280 $form .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
281 $form .= Xml
::hidden( 'days', $days );
283 $form .= Xml
::hidden( 'hideMinor', 1 );
285 $form .= Xml
::hidden( 'hideBots', 1 );
287 $form .= Xml
::hidden( 'hideAnons', 1 );
289 $form .= Xml
::hidden( 'hideLiu', 1 );
291 $form .= Xml
::hidden( 'hideOwn', 1 );
292 $form .= Xml
::closeElement( 'form' );
293 $form .= Xml
::closeElement( 'fieldset' );
294 $wgOut->addHtml( $form );
296 # If there's nothing to show, stop here
297 if( $numRows == 0 ) {
298 $wgOut->addWikiMsg( 'watchnochange' );
302 /* End bottom header */
304 /* Do link batch query */
305 $linkBatch = new LinkBatch
;
306 while ( $row = $dbr->fetchObject( $res ) ) {
307 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
308 if ( $row->rc_user
!= 0 ) {
309 $linkBatch->add( NS_USER
, $userNameUnderscored );
311 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
313 $linkBatch->execute();
314 $dbr->dataSeek( $res, 0 );
316 $list = ChangesList
::newFromUser( $wgUser );
318 $s = $list->beginRecentChangesList();
320 while ( $obj = $dbr->fetchObject( $res ) ) {
322 $rc = RecentChange
::newFromRow( $obj );
323 $rc->counter
= $counter++
;
325 if ( $wgShowUpdatedMarker ) {
326 $updated = $obj->wl_notificationtimestamp
;
331 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
332 $rc->numberofWatchingusers
= $dbr->selectField( 'watchlist',
335 'wl_namespace' => $obj->rc_namespace
,
336 'wl_title' => $obj->rc_title
,
340 $rc->numberofWatchingusers
= 0;
343 $s .= $list->recentChangesLine( $rc, $updated );
345 $s .= $list->endRecentChangesList();
347 $dbr->freeResult( $res );
348 $wgOut->addHTML( $s );
351 function wlHoursLink( $h, $page, $options = array() ) {
352 global $wgUser, $wgLang, $wgContLang;
353 $sk = $wgUser->getSkin();
354 $s = $sk->makeKnownLink(
355 $wgContLang->specialPage( $page ),
356 $wgLang->formatNum( $h ),
357 wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
361 function wlDaysLink( $d, $page, $options = array() ) {
362 global $wgUser, $wgLang, $wgContLang;
363 $sk = $wgUser->getSkin();
364 $s = $sk->makeKnownLink(
365 $wgContLang->specialPage( $page ),
366 ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
367 wfArrayToCGI( array('days' => $d), $options ) );
374 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
375 $hours = array( 1, 2, 6, 12 );
376 $days = array( 1, 3, 7 );
378 foreach( $hours as $h ) {
379 $hours[$i++
] = wlHoursLink( $h, $page, $options );
382 foreach( $days as $d ) {
383 $days[$i++
] = wlDaysLink( $d, $page, $options );
385 return wfMsgExt('wlshowlast',
386 array('parseinline', 'replaceafter'),
387 implode(' | ', $hours),
388 implode(' | ', $days),
389 wlDaysLink( 0, $page, $options ) );
393 * Count the number of items on a user's watchlist
395 * @param $talk Include talk pages
398 function wlCountItems( &$user, $talk = true ) {
399 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
401 # Fetch the raw count
402 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->mId
), 'wlCountItems' );
403 $row = $dbr->fetchObject( $res );
404 $count = $row->count
;
405 $dbr->freeResult( $res );
407 # Halve to remove talk pages if needed
409 $count = floor( $count / 2 );