4 * @addtogroup SpecialPage
10 require_once( dirname(__FILE__
) . '/SpecialRecentchanges.php' );
15 * @param $par Parameter passed to the page
17 function wfSpecialWatchlist( $par ) {
18 global $wgUser, $wgOut, $wgLang, $wgRequest;
19 global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
20 global $wgEnotifWatchlist;
21 $fname = 'wfSpecialWatchlist';
23 $skin = $wgUser->getSkin();
24 $specialTitle = SpecialPage
::getTitleFor( 'Watchlist' );
25 $wgOut->setRobotPolicy( 'noindex,nofollow' );
27 # Anons don't get a watchlist
28 if( $wgUser->isAnon() ) {
29 $wgOut->setPageTitle( wfMsg( 'watchnologin' ) );
30 $llink = $skin->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Userlogin' ), wfMsgHtml( 'loginreqlink' ), 'returnto=' . $specialTitle->getPrefixedUrl() );
31 $wgOut->addHtml( wfMsgWikiHtml( 'watchlistanontext', $llink ) );
35 $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
37 $sub = wfMsgExt( 'watchlistfor', 'parseinline', $wgUser->getName() );
38 $sub .= '<br />' . WatchlistEditor
::buildTools( $wgUser->getSkin() );
39 $wgOut->setSubtitle( $sub );
41 if( ( $mode = WatchlistEditor
::getMode( $wgRequest, $par ) ) !== false ) {
42 $editor = new WatchlistEditor();
43 $editor->execute( $wgUser, $wgOut, $wgRequest, $mode );
47 $uid = $wgUser->getId();
48 if( $wgEnotifWatchlist && $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) {
49 $wgUser->clearAllNotifications( $uid );
50 $wgOut->redirect( $specialTitle->getFullUrl() );
55 /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
56 /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
57 /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
58 /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
59 /* ? */ 'namespace' => 'all',
64 # Extract variables from the request, falling back to user preferences or
65 # other default values if these don't exist
66 $prefs['days' ] = floatval( $wgUser->getOption( 'watchlistdays' ) );
67 $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
68 $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
69 $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
72 $days = $wgRequest->getVal( 'days', $prefs['days'] );
73 $hideOwn = $wgRequest->getBool( 'hideOwn', $prefs['hideown'] );
74 $hideBots = $wgRequest->getBool( 'hideBots', $prefs['hidebots'] );
75 $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
77 # Get namespace value, if supplied, and prepare a WHERE fragment
78 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
79 if( !is_null( $nameSpace ) ) {
80 $nameSpace = intval( $nameSpace );
81 $nameSpaceClause = " AND rc_namespace = $nameSpace";
84 $nameSpaceClause = '';
87 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
88 list( $page, $watchlist, $recentchanges ) = $dbr->tableNamesN( 'page', 'watchlist', 'recentchanges' );
90 $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
91 array( 'wl_user' => $uid ), __METHOD__
);
92 // Adjust for page X, talk:page X, which are both stored separately,
93 // but treated together
94 $nitems = floor($watchlistCount / 2);
96 if( is_null($days) ||
!is_numeric($days) ) {
97 $big = 1000; /* The magical big */
99 # Set default cutoff shorter
100 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
102 $days = $defaults['days']; # default cutoff for shortlisters
105 $days = floatval($days);
108 // Dump everything here
109 $nondefaults = array();
111 wfAppendToArrayIfNotDefault('days' , $days , $defaults, $nondefaults);
112 wfAppendToArrayIfNotDefault('hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
113 wfAppendToArrayIfNotDefault('hideBots' , (int)$hideBots, $defaults, $nondefaults);
114 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
115 wfAppendToArrayIfNotDefault('namespace', $nameSpace , $defaults, $nondefaults);
118 if( ! wfRunHooks('BeforeWatchlist', array($nondefaults, $wgUser, &$hookSql)) ) {
123 $wgOut->addWikiMsg( 'nowatchlist' );
130 $andcutoff = "AND rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
132 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
133 $res = $dbr->query( $sql, $fname );
134 $s = $dbr->fetchObject( $res );
139 # If the watchlist is relatively short, it's simplest to zip
140 # down its entirety and then sort the results.
142 # If it's relatively long, it may be worth our while to zip
143 # through the time-sorted page list checking for watched items.
145 # Up estimate of watched items by 15% to compensate for talk pages...
148 $andHideOwn = $hideOwn ?
"AND (rc_user <> $uid)" : '';
149 $andHideBots = $hideBots ?
"AND (rc_bot = 0)" : '';
150 $andHideMinor = $hideMinor ?
'AND rc_minor = 0' : '';
152 # Show watchlist header
154 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
155 $header .= wfMsg( 'wlheader-enotif' ) . "\n";
157 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
158 $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
161 # Toggle watchlist content (all recent edits or just the latest)
162 if( $wgUser->getOption( 'extendwatchlist' )) {
164 $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) );
166 $andLatest= 'AND rc_this_oldid=page_latest';
167 $limitWatchlist = '';
170 $header .= wfMsgExt( 'watchlist-details', array( 'parsemag' ), $wgLang->formatNum( $nitems ) );
171 $wgOut->addWikiText( $header );
173 # Show a message about slave lag, if applicable
174 if( ( $lag = $dbr->getLag() ) > 0 )
175 $wgOut->showLagWarning( $lag );
177 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
178 $wgOut->addHTML( '<form action="' .
179 $specialTitle->escapeLocalUrl() .
180 '" method="post"><input type="submit" name="dummy" value="' .
181 htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
182 '" /><input type="hidden" name="reset" value="all" /></form>' .
185 if ( $wgShowUpdatedMarker ) {
186 $wltsfield=", ${watchlist}.wl_notificationtimestamp ";
188 $sql = "SELECT ${recentchanges}.* ${wltsfield}
189 FROM $watchlist,$recentchanges,$page
191 AND wl_namespace=rc_namespace
192 AND wl_title=rc_title
193 AND rc_cur_id=page_id
201 ORDER BY rc_timestamp DESC
204 $res = $dbr->query( $sql, $fname );
205 $numRows = $dbr->numRows( $res );
207 /* Start bottom header */
208 $wgOut->addHTML( "<hr />\n" );
211 $wgOut->addWikiText( wfMsgExt( 'rcnote', array( 'parseinline' ), $wgLang->formatNum( $numRows ),
212 $wgLang->formatNum( $days ), $wgLang->timeAndDate( wfTimestampNow(), true ) ) . '<br />' , false );
213 } elseif($days > 0) {
214 $wgOut->addWikiText( wfMsgExt( 'wlnote', array( 'parseinline' ), $wgLang->formatNum( $numRows ),
215 $wgLang->formatNum( round($days*24) ) ) . '<br />' , false );
218 $wgOut->addHTML( "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n" );
220 # Spit out some control panel links
221 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
222 $skin = $wgUser->getSkin();
224 # Hide/show bot edits
225 $label = $hideBots ?
wfMsgHtml( 'watchlist-show-bots' ) : wfMsgHtml( 'watchlist-hide-bots' );
226 $linkBits = wfArrayToCGI( array( 'hideBots' => 1 - (int)$hideBots ), $nondefaults );
227 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
229 # Hide/show own edits
230 $label = $hideOwn ?
wfMsgHtml( 'watchlist-show-own' ) : wfMsgHtml( 'watchlist-hide-own' );
231 $linkBits = wfArrayToCGI( array( 'hideOwn' => 1 - (int)$hideOwn ), $nondefaults );
232 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
234 # Hide/show minor edits
235 $label = $hideMinor ?
wfMsgHtml( 'watchlist-show-minor' ) : wfMsgHtml( 'watchlist-hide-minor' );
236 $linkBits = wfArrayToCGI( array( 'hideMinor' => 1 - (int)$hideMinor ), $nondefaults );
237 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
239 $wgOut->addHTML( implode( ' | ', $links ) );
241 # Form for namespace filtering
242 $form = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
244 $form .= Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
245 $form .= Xml
::namespaceSelector( $nameSpace, '' ) . ' ';
246 $form .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
247 $form .= Xml
::hidden( 'days', $days );
249 $form .= Xml
::hidden( 'hideOwn', 1 );
251 $form .= Xml
::hidden( 'hideBots', 1 );
253 $form .= Xml
::hidden( 'hideMinor', 1 );
254 $form .= Xml
::closeElement( 'form' );
255 $wgOut->addHtml( $form );
257 # If there's nothing to show, stop here
258 if( $numRows == 0 ) {
259 $wgOut->addWikiMsg( 'watchnochange' );
263 /* End bottom header */
265 /* Do link batch query */
266 $linkBatch = new LinkBatch
;
267 while ( $row = $dbr->fetchObject( $res ) ) {
268 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
269 if ( $row->rc_user
!= 0 ) {
270 $linkBatch->add( NS_USER
, $userNameUnderscored );
272 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
274 $linkBatch->execute();
275 $dbr->dataSeek( $res, 0 );
277 $list = ChangesList
::newFromUser( $wgUser );
279 $s = $list->beginRecentChangesList();
281 while ( $obj = $dbr->fetchObject( $res ) ) {
283 $rc = RecentChange
::newFromRow( $obj );
284 $rc->counter
= $counter++
;
286 if ( $wgShowUpdatedMarker ) {
287 $updated = $obj->wl_notificationtimestamp
;
289 // Same visual appearance as MW 1.4
293 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
294 $rc->numberofWatchingusers
= $dbr->selectField( 'watchlist',
297 'wl_namespace' => $obj->rc_namespace
,
298 'wl_title' => $obj->rc_title
,
302 $rc->numberofWatchingusers
= 0;
305 $s .= $list->recentChangesLine( $rc, $updated );
307 $s .= $list->endRecentChangesList();
309 $dbr->freeResult( $res );
310 $wgOut->addHTML( $s );
314 function wlHoursLink( $h, $page, $options = array() ) {
315 global $wgUser, $wgLang, $wgContLang;
316 $sk = $wgUser->getSkin();
317 $s = $sk->makeKnownLink(
318 $wgContLang->specialPage( $page ),
319 $wgLang->formatNum( $h ),
320 wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
324 function wlDaysLink( $d, $page, $options = array() ) {
325 global $wgUser, $wgLang, $wgContLang;
326 $sk = $wgUser->getSkin();
327 $s = $sk->makeKnownLink(
328 $wgContLang->specialPage( $page ),
329 ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
330 wfArrayToCGI( array('days' => $d), $options ) );
337 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
338 $hours = array( 1, 2, 6, 12 );
339 $days = array( 1, 3, 7 );
341 foreach( $hours as $h ) {
342 $hours[$i++
] = wlHoursLink( $h, $page, $options );
345 foreach( $days as $d ) {
346 $days[$i++
] = wlDaysLink( $d, $page, $options );
348 return wfMsgExt('wlshowlast',
349 array('parseinline', 'replaceafter'),
350 implode(' | ', $hours),
351 implode(' | ', $days),
352 wlDaysLink( 0, $page, $options ) );
356 * Count the number of items on a user's watchlist
358 * @param $talk Include talk pages
361 function wlCountItems( &$user, $talk = true ) {
362 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
364 # Fetch the raw count
365 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->mId
), 'wlCountItems' );
366 $row = $dbr->fetchObject( $res );
367 $count = $row->count
;
368 $dbr->freeResult( $res );
370 # Halve to remove talk pages if needed
372 $count = floor( $count / 2 );