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);
125 $npages = wfMsg( 'watchlistall1' );
127 $andcutoff = "AND rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
129 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
130 $res = $dbr->query( $sql, $fname );
131 $s = $dbr->fetchObject( $res );
134 $npages = 40000 * $days;
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 # TODO: Consider removing the third parameter
169 $header .= wfMsgExt( 'watchdetails', array( 'parsemag' ), $wgLang->formatNum( $nitems ),
170 $wgLang->formatNum( $npages ), '',
171 $specialTitle->getFullUrl( 'edit=yes' ) );
172 $wgOut->addWikiText( $header );
174 # Show a message about slave lag, if applicable
175 if( ( $lag = $dbr->getLag() ) > 0 )
176 $wgOut->showLagWarning( $lag );
178 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
179 $wgOut->addHTML( '<form action="' .
180 $specialTitle->escapeLocalUrl() .
181 '" method="post"><input type="submit" name="dummy" value="' .
182 htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
183 '" /><input type="hidden" name="reset" value="all" /></form>' .
188 FROM $watchlist,$recentchanges,$page
190 AND wl_namespace=rc_namespace
191 AND wl_title=rc_title
192 AND rc_cur_id=page_id
199 ORDER BY rc_timestamp DESC
202 $res = $dbr->query( $sql, $fname );
203 $numRows = $dbr->numRows( $res );
205 /* Start bottom header */
206 $wgOut->addHTML( "<hr />\n" );
209 $wgOut->addWikiText( wfMsgExt( 'rcnote', array( 'parseinline' ), $wgLang->formatNum( $numRows ),
210 $wgLang->formatNum( $days ), $wgLang->timeAndDate( wfTimestampNow(), true ) ) . '<br />' , false );
211 } elseif($days > 0) {
212 $wgOut->addWikiText( wfMsgExt( 'wlnote', array( 'parseinline' ), $wgLang->formatNum( $numRows ),
213 $wgLang->formatNum( round($days*24) ) ) . '<br />' , false );
216 $wgOut->addHTML( "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n" );
218 # Spit out some control panel links
219 $thisTitle = SpecialPage
::getTitleFor( 'Watchlist' );
220 $skin = $wgUser->getSkin();
222 # Hide/show bot edits
223 $label = $hideBots ?
wfMsgHtml( 'watchlist-show-bots' ) : wfMsgHtml( 'watchlist-hide-bots' );
224 $linkBits = wfArrayToCGI( array( 'hideBots' => 1 - (int)$hideBots ), $nondefaults );
225 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
227 # Hide/show own edits
228 $label = $hideOwn ?
wfMsgHtml( 'watchlist-show-own' ) : wfMsgHtml( 'watchlist-hide-own' );
229 $linkBits = wfArrayToCGI( array( 'hideOwn' => 1 - (int)$hideOwn ), $nondefaults );
230 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
232 # Hide/show minor edits
233 $label = $hideMinor ?
wfMsgHtml( 'watchlist-show-minor' ) : wfMsgHtml( 'watchlist-hide-minor' );
234 $linkBits = wfArrayToCGI( array( 'hideMinor' => 1 - (int)$hideMinor ), $nondefaults );
235 $links[] = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits );
237 $wgOut->addHTML( implode( ' | ', $links ) );
239 # Form for namespace filtering
240 $form = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
242 $form .= Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
243 $form .= Xml
::namespaceSelector( $nameSpace, '' ) . ' ';
244 $form .= Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
245 $form .= Xml
::hidden( 'days', $days );
247 $form .= Xml
::hidden( 'hideOwn', 1 );
249 $form .= Xml
::hidden( 'hideBots', 1 );
251 $form .= Xml
::hidden( 'hideMinor', 1 );
252 $form .= Xml
::closeElement( 'form' );
253 $wgOut->addHtml( $form );
255 # If there's nothing to show, stop here
256 if( $numRows == 0 ) {
257 $wgOut->addWikiText( wfMsgNoTrans( 'watchnochange' ) );
261 /* End bottom header */
263 /* Do link batch query */
264 $linkBatch = new LinkBatch
;
265 while ( $row = $dbr->fetchObject( $res ) ) {
266 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text
);
267 if ( $row->rc_user
!= 0 ) {
268 $linkBatch->add( NS_USER
, $userNameUnderscored );
270 $linkBatch->add( NS_USER_TALK
, $userNameUnderscored );
272 $linkBatch->execute();
273 $dbr->dataSeek( $res, 0 );
275 $list = ChangesList
::newFromUser( $wgUser );
277 $s = $list->beginRecentChangesList();
279 while ( $obj = $dbr->fetchObject( $res ) ) {
281 $rc = RecentChange
::newFromRow( $obj );
282 $rc->counter
= $counter++
;
284 if ( $wgShowUpdatedMarker ) {
285 $updated = $obj->wl_notificationtimestamp
;
287 // Same visual appearance as MW 1.4
291 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
292 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .$dbr->strencode($obj->page_title
). "' AND wl_namespace='{$obj->page_namespace}'" ;
293 $res3 = $dbr->query( $sql3, $fname );
294 $x = $dbr->fetchObject( $res3 );
295 $rc->numberofWatchingusers
= $x->n
;
297 $rc->numberofWatchingusers
= 0;
300 $s .= $list->recentChangesLine( $rc, $updated );
302 $s .= $list->endRecentChangesList();
304 $dbr->freeResult( $res );
305 $wgOut->addHTML( $s );
309 function wlHoursLink( $h, $page, $options = array() ) {
310 global $wgUser, $wgLang, $wgContLang;
311 $sk = $wgUser->getSkin();
312 $s = $sk->makeKnownLink(
313 $wgContLang->specialPage( $page ),
314 $wgLang->formatNum( $h ),
315 wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
319 function wlDaysLink( $d, $page, $options = array() ) {
320 global $wgUser, $wgLang, $wgContLang;
321 $sk = $wgUser->getSkin();
322 $s = $sk->makeKnownLink(
323 $wgContLang->specialPage( $page ),
324 ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
325 wfArrayToCGI( array('days' => $d), $options ) );
332 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
333 $hours = array( 1, 2, 6, 12 );
334 $days = array( 1, 3, 7 );
336 foreach( $hours as $h ) {
337 $hours[$i++
] = wlHoursLink( $h, $page, $options );
340 foreach( $days as $d ) {
341 $days[$i++
] = wlDaysLink( $d, $page, $options );
343 return wfMsgExt('wlshowlast',
344 array('parseinline', 'replaceafter'),
345 implode(' | ', $hours),
346 implode(' | ', $days),
347 wlDaysLink( 0, $page, $options ) );
351 * Count the number of items on a user's watchlist
353 * @param $talk Include talk pages
356 function wlCountItems( &$user, $talk = true ) {
357 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
359 # Fetch the raw count
360 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->mId
), 'wlCountItems' );
361 $row = $dbr->fetchObject( $res );
362 $count = $row->count
;
363 $dbr->freeResult( $res );
365 # Halve to remove talk pages if needed
367 $count = floor( $count / 2 );