a921e982a3c452dfebed539e3a2c3998b60f3e2e
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 ) );
34 $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
35 $wgOut->setSubtitle( wfMsgWikiHtml( 'watchlistfor', htmlspecialchars( $wgUser->getName() ) ) );
38 if( ( $mode = WatchlistEditor
::getMode( $wgRequest, $par ) ) !== false ) {
39 $editor = new WatchlistEditor();
40 $editor->execute( $wgUser, $wgOut, $wgRequest, $mode );
44 $uid = $wgUser->getId();
45 if( $wgEnotifWatchlist && $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) {
46 $wgUser->clearAllNotifications( $uid );
50 /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */
51 /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
52 /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
53 /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
54 /* ? */ 'namespace' => 'all',
59 # Extract variables from the request, falling back to user preferences or
60 # other default values if these don't exist
61 $prefs['days' ] = floatval( $wgUser->getOption( 'watchlistdays' ) );
62 $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
63 $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
64 $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
67 $days = $wgRequest->getVal( 'days', $prefs['days'] );
68 $hideOwn = $wgRequest->getBool( 'hideOwn', $prefs['hideown'] );
69 $hideBots = $wgRequest->getBool( 'hideBots', $prefs['hidebots'] );
70 $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
72 # Get namespace value, if supplied, and prepare a WHERE fragment
73 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
74 if( !is_null( $nameSpace ) ) {
75 $nameSpace = intval( $nameSpace );
76 $nameSpaceClause = " AND rc_namespace = $nameSpace";
79 $nameSpaceClause = '';
82 $dbr = wfGetDB( DB_SLAVE
, 'watchlist' );
83 list( $page, $watchlist, $recentchanges ) = $dbr->tableNamesN( 'page', 'watchlist', 'recentchanges' );
85 $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
86 $res = $dbr->query( $sql, $fname );
87 $s = $dbr->fetchObject( $res );
89 # Patch *** A1 *** (see A2 below)
90 # adjust for page X, talk:page X, which are both stored separately, but treated together
91 $nitems = floor($s->n
/ 2);
95 $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
99 if( is_null($days) ||
!is_numeric($days) ) {
100 $big = 1000; /* The magical big */
102 # Set default cutoff shorter
103 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
105 $days = $defaults['days']; # default cutoff for shortlisters
108 $days = floatval($days);
111 // Dump everything here
112 $nondefaults = array();
114 wfAppendToArrayIfNotDefault('days' , $days , $defaults, $nondefaults);
115 wfAppendToArrayIfNotDefault('hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
116 wfAppendToArrayIfNotDefault('hideBots' , (int)$hideBots, $defaults, $nondefaults);
117 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
118 wfAppendToArrayIfNotDefault('namespace', $nameSpace , $defaults, $nondefaults);
122 $npages = wfMsg( 'watchlistall1' );
124 $andcutoff = "AND rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
126 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
127 $res = $dbr->query( $sql, $fname );
128 $s = $dbr->fetchObject( $res );
131 $npages = 40000 * $days;
134 # If the watchlist is relatively short, it's simplest to zip
135 # down its entirety and then sort the results.
137 # If it's relatively long, it may be worth our while to zip
138 # through the time-sorted page list checking for watched items.
140 # Up estimate of watched items by 15% to compensate for talk pages...
143 $andHideOwn = $hideOwn ?
"AND (rc_user <> $uid)" : '';
144 $andHideBots = $hideBots ?
"AND (rc_bot = 0)" : '';
145 $andHideMinor = $hideMinor ?
'AND rc_minor = 0' : '';
147 # Show watchlist header
149 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
150 $header .= wfMsg( 'wlheader-enotif' ) . "\n";
152 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
153 $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
156 # Toggle watchlist content (all recent edits or just the latest)
157 if( $wgUser->getOption( 'extendwatchlist' )) {
159 $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) );
161 $andLatest= 'AND rc_this_oldid=page_latest';
162 $limitWatchlist = '';
165 # TODO: Consider removing the third parameter
166 $header .= wfMsgExt( 'watchdetails', array( 'parsemag' ), $wgLang->formatNum( $nitems ),
167 $wgLang->formatNum( $npages ), '',
168 $specialTitle->getFullUrl( 'edit=yes' ) );
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 );