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 );
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 $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
91 $res = $dbr->query( $sql, $fname );
92 $s = $dbr->fetchObject( $res );
94 # Patch *** A1 *** (see A2 below)
95 # adjust for page X, talk:page X, which are both stored separately, but treated together
96 $nitems = floor($s->n
/ 2);
100 $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
104 if( is_null($days) ||
!is_numeric($days) ) {
105 $big = 1000; /* The magical big */
107 # Set default cutoff shorter
108 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
110 $days = $defaults['days']; # default cutoff for shortlisters
113 $days = floatval($days);
116 // Dump everything here
117 $nondefaults = array();
119 wfAppendToArrayIfNotDefault('days' , $days , $defaults, $nondefaults);
120 wfAppendToArrayIfNotDefault('hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
121 wfAppendToArrayIfNotDefault('hideBots' , (int)$hideBots, $defaults, $nondefaults);
122 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
123 wfAppendToArrayIfNotDefault('namespace', $nameSpace , $defaults, $nondefaults);
128 $andcutoff = "AND rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
130 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
131 $res = $dbr->query( $sql, $fname );
132 $s = $dbr->fetchObject( $res );
137 # If the watchlist is relatively short, it's simplest to zip
138 # down its entirety and then sort the results.
140 # If it's relatively long, it may be worth our while to zip
141 # through the time-sorted page list checking for watched items.
143 # Up estimate of watched items by 15% to compensate for talk pages...
146 $andHideOwn = $hideOwn ?
"AND (rc_user <> $uid)" : '';
147 $andHideBots = $hideBots ?
"AND (rc_bot = 0)" : '';
148 $andHideMinor = $hideMinor ?
'AND rc_minor = 0' : '';
150 # Show watchlist header
152 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
153 $header .= wfMsg( 'wlheader-enotif' ) . "\n";
155 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
156 $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
159 # Toggle watchlist content (all recent edits or just the latest)
160 if( $wgUser->getOption( 'extendwatchlist' )) {
162 $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) );
164 $andLatest= 'AND rc_this_oldid=page_latest';
165 $limitWatchlist = '';
168 $header .= wfMsgExt( 'watchlist-details', array( 'parsemag' ), $wgLang->formatNum( $nitems ) );
169 $wgOut->addWikiText( $header );
171 # Show a message about slave lag, if applicable
172 if( ( $lag = $dbr->getLag() ) > 0 )
173 $wgOut->showLagWarning( $lag );
175 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
176 $wgOut->addHTML( '<form action="' .
177 $specialTitle->escapeLocalUrl() .
178 '" method="post"><input type="submit" name="dummy" value="' .
179 htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
180 '" /><input type="hidden" name="reset" value="all" /></form>' .
185 FROM $watchlist,$recentchanges,$page
187 AND wl_namespace=rc_namespace
188 AND wl_title=rc_title
189 AND rc_cur_id=page_id
196 ORDER BY rc_timestamp DESC
199 $res = $dbr->query( $sql, $fname );
200 $numRows = $dbr->numRows( $res );
202 /* Start bottom header */
203 $wgOut->addHTML( "<hr />\n" );
206 $wgOut->addWikiText( wfMsgExt( 'rcnote', array( 'parseinline' ), $wgLang->formatNum( $numRows ),
207 $wgLang->formatNum( $days ), $wgLang->timeAndDate( wfTimestampNow(), true ) ) . '<br />' , false );
208 } elseif($days > 0) {
209 $wgOut->addWikiText( wfMsgExt( 'wlnote', array( 'parseinline' ), $wgLang->formatNum( $numRows ),
210 $wgLang->formatNum( round($days*24) ) ) . '<br />' , false );
213 $wgOut->addHTML( "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n" );
215 # Spit out some control panel links
216 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
217 $skin = $wgUser->getSkin();
219 # Hide/show bot edits
220 $label = $hideBots ?
wfMsgHtml( 'watchlist-show-bots' ) : wfMsgHtml( 'watchlist-hide-bots' );
221 $linkBits = wfArrayToCGI( array( 'hideBots' => 1 - (int)$hideBots ), $nondefaults );
222 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
224 # Hide/show own edits
225 $label = $hideOwn ?
wfMsgHtml( 'watchlist-show-own' ) : wfMsgHtml( 'watchlist-hide-own' );
226 $linkBits = wfArrayToCGI( array( 'hideOwn' => 1 - (int)$hideOwn ), $nondefaults );
227 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
229 # Hide/show minor edits
230 $label = $hideMinor ?
wfMsgHtml( 'watchlist-show-minor' ) : wfMsgHtml( 'watchlist-hide-minor' );
231 $linkBits = wfArrayToCGI( array( 'hideMinor' => 1 - (int)$hideMinor ), $nondefaults );
232 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
234 $wgOut->addHTML( implode( ' | ', $links ) );
236 # Form for namespace filtering
237 $form = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
239 $form .= Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
240 $form .= Xml
::namespaceSelector( $nameSpace, '' ) . ' ';
241 $form .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
242 $form .= Xml
::hidden( 'days', $days );
244 $form .= Xml
::hidden( 'hideOwn', 1 );
246 $form .= Xml
::hidden( 'hideBots', 1 );
248 $form .= Xml
::hidden( 'hideMinor', 1 );
249 $form .= Xml
::closeElement( 'form' );
250 $wgOut->addHtml( $form );
252 # If there's nothing to show, stop here
253 if( $numRows == 0 ) {
254 $wgOut->addWikiText( wfMsgNoTrans( 'watchnochange' ) );
258 /* End bottom header */
260 /* Do link batch query */
261 $linkBatch = new LinkBatch
;
262 while ( $row = $dbr->fetchObject( $res ) ) {
263 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
264 if ( $row->rc_user
!= 0 ) {
265 $linkBatch->add( NS_USER
, $userNameUnderscored );
267 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
269 $linkBatch->execute();
270 $dbr->dataSeek( $res, 0 );
272 $list = ChangesList
::newFromUser( $wgUser );
274 $s = $list->beginRecentChangesList();
276 while ( $obj = $dbr->fetchObject( $res ) ) {
278 $rc = RecentChange
::newFromRow( $obj );
279 $rc->counter
= $counter++
;
281 if ( $wgShowUpdatedMarker ) {
282 $updated = $obj->wl_notificationtimestamp
;
284 // Same visual appearance as MW 1.4
288 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
289 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .$dbr->strencode($obj->page_title
). "' AND wl_namespace='{$obj->page_namespace}'" ;
290 $res3 = $dbr->query( $sql3, $fname );
291 $x = $dbr->fetchObject( $res3 );
292 $rc->numberofWatchingusers
= $x->n
;
294 $rc->numberofWatchingusers
= 0;
297 $s .= $list->recentChangesLine( $rc, $updated );
299 $s .= $list->endRecentChangesList();
301 $dbr->freeResult( $res );
302 $wgOut->addHTML( $s );
306 function wlHoursLink( $h, $page, $options = array() ) {
307 global $wgUser, $wgLang, $wgContLang;
308 $sk = $wgUser->getSkin();
309 $s = $sk->makeKnownLink(
310 $wgContLang->specialPage( $page ),
311 $wgLang->formatNum( $h ),
312 wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
316 function wlDaysLink( $d, $page, $options = array() ) {
317 global $wgUser, $wgLang, $wgContLang;
318 $sk = $wgUser->getSkin();
319 $s = $sk->makeKnownLink(
320 $wgContLang->specialPage( $page ),
321 ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
322 wfArrayToCGI( array('days' => $d), $options ) );
329 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
330 $hours = array( 1, 2, 6, 12 );
331 $days = array( 1, 3, 7 );
333 foreach( $hours as $h ) {
334 $hours[$i++
] = wlHoursLink( $h, $page, $options );
337 foreach( $days as $d ) {
338 $days[$i++
] = wlDaysLink( $d, $page, $options );
340 return wfMsgExt('wlshowlast',
341 array('parseinline', 'replaceafter'),
342 implode(' | ', $hours),
343 implode(' | ', $days),
344 wlDaysLink( 0, $page, $options ) );
348 * Count the number of items on a user's watchlist
350 * @param $talk Include talk pages
353 function wlCountItems( &$user, $talk = true ) {
354 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
356 # Fetch the raw count
357 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->mId
), 'wlCountItems' );
358 $row = $dbr->fetchObject( $res );
359 $count = $row->count
;
360 $dbr->freeResult( $res );
362 # Halve to remove talk pages if needed
364 $count = floor( $count / 2 );