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, $wgContLang;
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 );
53 /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
54 /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
55 /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
56 /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
57 /* ? */ 'namespace' => 'all',
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['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
66 $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
67 $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
70 $days = $wgRequest->getVal( 'days', $prefs['days'] );
71 $hideOwn = $wgRequest->getBool( 'hideOwn', $prefs['hideown'] );
72 $hideBots = $wgRequest->getBool( 'hideBots', $prefs['hidebots'] );
73 $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
75 # Get namespace value, if supplied, and prepare a WHERE fragment
76 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
77 if( !is_null( $nameSpace ) ) {
78 $nameSpace = intval( $nameSpace );
79 $nameSpaceClause = " AND rc_namespace = $nameSpace";
82 $nameSpaceClause = '';
85 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
86 list( $page, $watchlist, $recentchanges ) = $dbr->tableNamesN( 'page', 'watchlist', 'recentchanges' );
88 $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
89 $res = $dbr->query( $sql, $fname );
90 $s = $dbr->fetchObject( $res );
92 # Patch *** A1 *** (see A2 below)
93 # adjust for page X, talk:page X, which are both stored separately, but treated together
94 $nitems = floor($s->n
/ 2);
98 $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
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('hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
119 wfAppendToArrayIfNotDefault('hideBots' , (int)$hideBots, $defaults, $nondefaults);
120 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
121 wfAppendToArrayIfNotDefault('namespace', $nameSpace , $defaults, $nondefaults);
126 $andcutoff = "AND rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
128 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
129 $res = $dbr->query( $sql, $fname );
130 $s = $dbr->fetchObject( $res );
135 # If the watchlist is relatively short, it's simplest to zip
136 # down its entirety and then sort the results.
138 # If it's relatively long, it may be worth our while to zip
139 # through the time-sorted page list checking for watched items.
141 # Up estimate of watched items by 15% to compensate for talk pages...
144 $andHideOwn = $hideOwn ?
"AND (rc_user <> $uid)" : '';
145 $andHideBots = $hideBots ?
"AND (rc_bot = 0)" : '';
146 $andHideMinor = $hideMinor ?
'AND rc_minor = 0' : '';
148 # Show watchlist header
150 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
151 $header .= wfMsg( 'wlheader-enotif' ) . "\n";
153 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
154 $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
157 # Toggle watchlist content (all recent edits or just the latest)
158 if( $wgUser->getOption( 'extendwatchlist' )) {
160 $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) );
162 $andLatest= 'AND rc_this_oldid=page_latest';
163 $limitWatchlist = '';
166 $header .= wfMsgExt( 'watchlist-details', array( 'parsemag' ), $wgLang->formatNum( $nitems ) );
167 $wgOut->addWikiText( $header );
169 # Show a message about slave lag, if applicable
170 if( ( $lag = $dbr->getLag() ) > 0 )
171 $wgOut->showLagWarning( $lag );
173 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
174 $wgOut->addHTML( '<form action="' .
175 $specialTitle->escapeLocalUrl() .
176 '" method="post"><input type="submit" name="dummy" value="' .
177 htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
178 '" /><input type="hidden" name="reset" value="all" /></form>' .
183 FROM $watchlist,$recentchanges,$page
185 AND wl_namespace=rc_namespace
186 AND wl_title=rc_title
187 AND rc_cur_id=page_id
194 ORDER BY rc_timestamp DESC
197 $res = $dbr->query( $sql, $fname );
198 $numRows = $dbr->numRows( $res );
200 /* Start bottom header */
201 $wgOut->addHTML( "<hr />\n" );
204 $wgOut->addWikiText( wfMsgExt( 'rcnote', array( 'parseinline' ), $wgLang->formatNum( $numRows ),
205 $wgLang->formatNum( $days ), $wgLang->timeAndDate( wfTimestampNow(), true ) ) . '<br />' , false );
206 } elseif($days > 0) {
207 $wgOut->addWikiText( wfMsgExt( 'wlnote', array( 'parseinline' ), $wgLang->formatNum( $numRows ),
208 $wgLang->formatNum( round($days*24) ) ) . '<br />' , false );
211 $wgOut->addHTML( "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n" );
213 # Spit out some control panel links
214 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
215 $skin = $wgUser->getSkin();
217 # Hide/show bot edits
218 $label = $hideBots ?
wfMsgHtml( 'watchlist-show-bots' ) : wfMsgHtml( 'watchlist-hide-bots' );
219 $linkBits = wfArrayToCGI( array( 'hideBots' => 1 - (int)$hideBots ), $nondefaults );
220 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
222 # Hide/show own edits
223 $label = $hideOwn ?
wfMsgHtml( 'watchlist-show-own' ) : wfMsgHtml( 'watchlist-hide-own' );
224 $linkBits = wfArrayToCGI( array( 'hideOwn' => 1 - (int)$hideOwn ), $nondefaults );
225 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
227 # Hide/show minor edits
228 $label = $hideMinor ?
wfMsgHtml( 'watchlist-show-minor' ) : wfMsgHtml( 'watchlist-hide-minor' );
229 $linkBits = wfArrayToCGI( array( 'hideMinor' => 1 - (int)$hideMinor ), $nondefaults );
230 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
232 $wgOut->addHTML( implode( ' | ', $links ) );
234 # Form for namespace filtering
235 $form = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
237 $form .= Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
238 $form .= Xml
::namespaceSelector( $nameSpace, '' ) . ' ';
239 $form .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
240 $form .= Xml
::hidden( 'days', $days );
242 $form .= Xml
::hidden( 'hideOwn', 1 );
244 $form .= Xml
::hidden( 'hideBots', 1 );
246 $form .= Xml
::hidden( 'hideMinor', 1 );
247 $form .= Xml
::closeElement( 'form' );
248 $wgOut->addHtml( $form );
250 # If there's nothing to show, stop here
251 if( $numRows == 0 ) {
252 $wgOut->addWikiText( wfMsgNoTrans( 'watchnochange' ) );
256 /* End bottom header */
258 /* Do link batch query */
259 $linkBatch = new LinkBatch
;
260 while ( $row = $dbr->fetchObject( $res ) ) {
261 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
262 if ( $row->rc_user
!= 0 ) {
263 $linkBatch->add( NS_USER
, $userNameUnderscored );
265 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
267 $linkBatch->execute();
268 $dbr->dataSeek( $res, 0 );
270 $list = ChangesList
::newFromUser( $wgUser );
272 $s = $list->beginRecentChangesList();
274 while ( $obj = $dbr->fetchObject( $res ) ) {
276 $rc = RecentChange
::newFromRow( $obj );
277 $rc->counter
= $counter++
;
279 if ( $wgShowUpdatedMarker ) {
280 $updated = $obj->wl_notificationtimestamp
;
282 // Same visual appearance as MW 1.4
286 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
287 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .$dbr->strencode($obj->page_title
). "' AND wl_namespace='{$obj->page_namespace}'" ;
288 $res3 = $dbr->query( $sql3, $fname );
289 $x = $dbr->fetchObject( $res3 );
290 $rc->numberofWatchingusers
= $x->n
;
292 $rc->numberofWatchingusers
= 0;
295 $s .= $list->recentChangesLine( $rc, $updated );
297 $s .= $list->endRecentChangesList();
299 $dbr->freeResult( $res );
300 $wgOut->addHTML( $s );
304 function wlHoursLink( $h, $page, $options = array() ) {
305 global $wgUser, $wgLang, $wgContLang;
306 $sk = $wgUser->getSkin();
307 $s = $sk->makeKnownLink(
308 $wgContLang->specialPage( $page ),
309 $wgLang->formatNum( $h ),
310 wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
314 function wlDaysLink( $d, $page, $options = array() ) {
315 global $wgUser, $wgLang, $wgContLang;
316 $sk = $wgUser->getSkin();
317 $s = $sk->makeKnownLink(
318 $wgContLang->specialPage( $page ),
319 ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
320 wfArrayToCGI( array('days' => $d), $options ) );
327 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
328 $hours = array( 1, 2, 6, 12 );
329 $days = array( 1, 3, 7 );
331 foreach( $hours as $h ) {
332 $hours[$i++
] = wlHoursLink( $h, $page, $options );
335 foreach( $days as $d ) {
336 $days[$i++
] = wlDaysLink( $d, $page, $options );
338 return wfMsgExt('wlshowlast',
339 array('parseinline', 'replaceafter'),
340 implode(' | ', $hours),
341 implode(' | ', $days),
342 wlDaysLink( 0, $page, $options ) );
346 * Count the number of items on a user's watchlist
348 * @param $talk Include talk pages
351 function wlCountItems( &$user, $talk = true ) {
352 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
354 # Fetch the raw count
355 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->mId
), 'wlCountItems' );
356 $row = $dbr->fetchObject( $res );
357 $count = $row->count
;
358 $dbr->freeResult( $res );
360 # Halve to remove talk pages if needed
362 $count = floor( $count / 2 );