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 # Show watchlist header
164 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
165 $header .= wfMsg( 'wlheader-enotif' ) . "\n";
167 if ( $wgShowUpdatedMarker ) {
168 $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
171 # Toggle watchlist content (all recent edits or just the latest)
172 if( $wgUser->getOption( 'extendwatchlist' )) {
174 $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) );
176 # Top log Ids for a page are not stored
177 $andLatest = 'AND (rc_this_oldid=page_latest OR rc_type=' . RC_LOG
. ') ';
178 $limitWatchlist = '';
181 $header .= wfMsgExt( 'watchlist-details', array( 'parsemag' ), $wgLang->formatNum( $nitems ) );
182 $wgOut->addWikiText( $header );
184 # Show a message about slave lag, if applicable
185 if( ( $lag = $dbr->getLag() ) > 0 )
186 $wgOut->showLagWarning( $lag );
188 if ( $wgShowUpdatedMarker ) {
189 $wgOut->addHTML( '<form action="' .
190 $specialTitle->escapeLocalUrl() .
191 '" method="post"><input type="submit" name="dummy" value="' .
192 htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
193 '" /><input type="hidden" name="reset" value="all" /></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 */
223 $wgOut->addHTML( "<hr />\n" );
227 wfMsgExt( 'rcnote', 'parseinline',
228 $wgLang->formatNum( $numRows ),
229 $wgLang->formatNum( $days ),
230 $wgLang->timeAndDate( wfTimestampNow(), true ),
231 $wgLang->date( wfTimestampNow(), true ),
232 $wgLang->time( wfTimestampNow(), true )
235 } elseif($days > 0) {
237 wfMsgExt( 'wlnote', 'parseinline',
238 $wgLang->formatNum( $numRows ),
239 $wgLang->formatNum( round($days*24) )
244 $wgOut->addHTML( "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n" );
246 # Spit out some control panel links
247 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
248 $skin = $wgUser->getSkin();
250 # Hide/show minor edits
251 $label = $hideMinor ?
wfMsgHtml( 'watchlist-show-minor' ) : wfMsgHtml( 'watchlist-hide-minor' );
252 $linkBits = wfArrayToCGI( array( 'hideMinor' => 1 - (int)$hideMinor ), $nondefaults );
253 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
255 # Hide/show bot edits
256 $label = $hideBots ?
wfMsgHtml( 'watchlist-show-bots' ) : wfMsgHtml( 'watchlist-hide-bots' );
257 $linkBits = wfArrayToCGI( array( 'hideBots' => 1 - (int)$hideBots ), $nondefaults );
258 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
260 # Hide/show anonymous edits
261 $label = $hideAnons ?
wfMsgHtml( 'watchlist-show-anons' ) : wfMsgHtml( 'watchlist-hide-anons' );
262 $linkBits = wfArrayToCGI( array( 'hideAnons' => 1 - (int)$hideAnons ), $nondefaults );
263 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
265 # Hide/show logged in edits
266 $label = $hideLiu ?
wfMsgHtml( 'watchlist-show-liu' ) : wfMsgHtml( 'watchlist-hide-liu' );
267 $linkBits = wfArrayToCGI( array( 'hideLiu' => 1 - (int)$hideLiu ), $nondefaults );
268 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
270 # Hide/show own edits
271 $label = $hideOwn ?
wfMsgHtml( 'watchlist-show-own' ) : wfMsgHtml( 'watchlist-hide-own' );
272 $linkBits = wfArrayToCGI( array( 'hideOwn' => 1 - (int)$hideOwn ), $nondefaults );
273 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
275 $wgOut->addHTML( implode( ' | ', $links ) );
277 # Form for namespace filtering
278 $form = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
280 $form .= Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
281 $form .= Xml
::namespaceSelector( $nameSpace, '' ) . ' ';
282 $form .= Xml
::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . "<br />";
283 $form .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
284 $form .= Xml
::hidden( 'days', $days );
286 $form .= Xml
::hidden( 'hideMinor', 1 );
288 $form .= Xml
::hidden( 'hideBots', 1 );
290 $form .= Xml
::hidden( 'hideAnons', 1 );
292 $form .= Xml
::hidden( 'hideLiu', 1 );
294 $form .= Xml
::hidden( 'hideOwn', 1 );
295 $form .= Xml
::closeElement( 'form' );
296 $wgOut->addHtml( $form );
298 # If there's nothing to show, stop here
299 if( $numRows == 0 ) {
300 $wgOut->addWikiMsg( 'watchnochange' );
304 /* End bottom header */
306 /* Do link batch query */
307 $linkBatch = new LinkBatch
;
308 while ( $row = $dbr->fetchObject( $res ) ) {
309 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
310 if ( $row->rc_user
!= 0 ) {
311 $linkBatch->add( NS_USER
, $userNameUnderscored );
313 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
315 $linkBatch->execute();
316 $dbr->dataSeek( $res, 0 );
318 $list = ChangesList
::newFromUser( $wgUser );
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 );
347 $s .= $list->endRecentChangesList();
349 $dbr->freeResult( $res );
350 $wgOut->addHTML( $s );
353 function wlHoursLink( $h, $page, $options = array() ) {
354 global $wgUser, $wgLang, $wgContLang;
355 $sk = $wgUser->getSkin();
356 $s = $sk->makeKnownLink(
357 $wgContLang->specialPage( $page ),
358 $wgLang->formatNum( $h ),
359 wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
363 function wlDaysLink( $d, $page, $options = array() ) {
364 global $wgUser, $wgLang, $wgContLang;
365 $sk = $wgUser->getSkin();
366 $s = $sk->makeKnownLink(
367 $wgContLang->specialPage( $page ),
368 ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
369 wfArrayToCGI( array('days' => $d), $options ) );
376 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
377 $hours = array( 1, 2, 6, 12 );
378 $days = array( 1, 3, 7 );
380 foreach( $hours as $h ) {
381 $hours[$i++
] = wlHoursLink( $h, $page, $options );
384 foreach( $days as $d ) {
385 $days[$i++
] = wlDaysLink( $d, $page, $options );
387 return wfMsgExt('wlshowlast',
388 array('parseinline', 'replaceafter'),
389 implode(' | ', $hours),
390 implode(' | ', $days),
391 wlDaysLink( 0, $page, $options ) );
395 * Count the number of items on a user's watchlist
397 * @param $talk Include talk pages
400 function wlCountItems( &$user, $talk = true ) {
401 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
403 # Fetch the raw count
404 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->mId
), 'wlCountItems' );
405 $row = $dbr->fetchObject( $res );
406 $count = $row->count
;
407 $dbr->freeResult( $res );
409 # Halve to remove talk pages if needed
411 $count = floor( $count / 2 );