5 * @subpackage SpecialPage
11 require_once( 'SpecialRecentchanges.php' );
12 require_once( 'WatchedItem.php' );
17 function wfSpecialWatchlist( $par ) {
18 global $wgUser, $wgOut, $wgLang, $wgMemc, $wgRequest, $wgContLang;
19 global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname;
20 global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
21 global $wgEnotifWatchlist, $wgFilterRobotsWL;
22 $fname = 'wfSpecialWatchlist';
24 $wgOut->setPagetitle( wfMsg( 'watchlist' ) );
25 $sub = htmlspecialchars( wfMsg( 'watchlistsub', $wgUser->getName() ) );
26 $wgOut->setSubtitle( $sub );
27 $wgOut->setRobotpolicy( 'noindex,nofollow' );
29 $specialTitle = Title
::makeTitle( NS_SPECIAL
, 'Watchlist' );
31 if( $wgUser->isAnon() ) {
32 $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
37 /* float */ 'days' => 3.0, /* or 0.5, watch further below */
38 /* bool */ 'hideOwn' => false,
39 /* bool */ 'hideBots' => false,
46 $days = $wgRequest->getVal( 'days' );
47 $hideOwn = $wgRequest->getBool( 'hideOwn' );
48 $hideBots = $wgRequest->getBool( 'hideBots' );
50 # Get namespace value, if supplied, and prepare a WHERE fragment
51 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
52 if( !is_null( $nameSpace ) ) {
53 $nameSpace = intval( $nameSpace );
54 $nameSpaceClause = " AND rc_namespace = $nameSpace";
57 $nameSpaceClause = '';
61 $action = $wgRequest->getVal( 'action' );
62 $remove = $wgRequest->getVal( 'remove' );
63 $id = $wgRequest->getArray( 'id' );
65 $uid = $wgUser->getID();
66 if( $wgEnotifWatchlist && $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) {
67 $wgUser->clearAllNotifications( $uid );
70 # Deleting items from watchlist
71 if(($action == 'submit') && isset($remove) && is_array($id)) {
72 $wgOut->addWikiText( wfMsg( 'removingchecked' ) );
73 $wgOut->addHTML( '<p>' );
74 foreach($id as $one) {
75 $t = Title
::newFromURL( $one );
76 if( !is_null( $t ) ) {
77 $wl = WatchedItem
::fromUserTitle( $wgUser, $t );
78 if( $wl->removeWatch() === false ) {
79 $wgOut->addHTML( "<br />\n" . wfMsg( 'couldntremove', htmlspecialchars($one) ) );
81 $wgOut->addHTML( ' (' . htmlspecialchars($one) . ')' );
84 $wgOut->addHTML( "<br />\n" . wfMsg( 'iteminvalidname', htmlspecialchars($one) ) );
87 $wgOut->addHTML( "done.</p>\n" );
90 if ( $wgUseWatchlistCache ) {
91 $memckey = "$wgDBname:watchlist:id:" . $wgUser->getId();
92 $cache_s = @$wgMemc->get( $memckey );
94 $wgOut->addWikiText( wfMsg('wlsaved') );
95 $wgOut->addHTML( $cache_s );
100 $dbr =& wfGetDB( DB_SLAVE
);
101 extract( $dbr->tableNames( 'page', 'revision', 'watchlist', 'recentchanges' ) );
103 $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
104 $res = $dbr->query( $sql, $fname );
105 $s = $dbr->fetchObject( $res );
107 # Patch *** A1 *** (see A2 below)
108 # adjust for page X, talk:page X, which are both stored separately, but treated together
109 $nitems = floor($s->n
/ 2);
113 $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
117 if( is_null($days) ||
!is_numeric($days) ) {
118 $big = 1000; /* The magical big */
120 # Set default cutoff shorter
121 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
123 $days = $defaults['days']; # default cutoff for shortlisters
126 $days = floatval($days);
129 // Dump everything here
130 $nondefaults = array();
132 wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
133 wfAppendToArrayIfNotDefault( 'hideOwn', $hideOwn, $defaults, $nondefaults);
134 wfAppendToArrayIfNotDefault( 'hideBots', $hideBots, $defaults, $nondefaults);
135 wfAppendToArrayIfNotDefault( 'namespace', $nameSpace, $defaults, $nondefaults );
140 $npages = wfMsg( 'watchlistall1' );
142 $docutoff = "AND rev_timestamp > '" .
143 ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
146 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
147 $res = $dbr->query( $sql, $fname );
148 $s = $dbr->fetchObject( $res );
151 $npages = 40000 * $days;
155 /* Edit watchlist form */
156 if($wgRequest->getBool('edit') ||
$par == 'edit' ) {
157 $wgOut->addWikiText( wfMsg( 'watchlistcontains', $wgLang->formatNum( $nitems ) ) .
158 "\n\n" . wfMsg( 'watcheditlist' ) );
160 $wgOut->addHTML( '<form action=\'' .
161 $specialTitle->escapeLocalUrl( 'action=submit' ) .
162 "' method='post'>\n" );
165 # The following was proposed by KTurner 07.11.2004 to T.Gries
166 # $sql = "SELECT distinct (wl_namespace & ~1),wl_title FROM $watchlist WHERE wl_user=$uid";
167 $sql = "SELECT wl_namespace, wl_title, page_is_redirect FROM $watchlist LEFT JOIN $page ON wl_namespace = page_namespace AND wl_title = page_title WHERE wl_user=$uid";
169 $res = $dbr->query( $sql, $fname );
171 # Batch existence check
172 $linkBatch = new LinkBatch();
173 while( $row = $dbr->fetchObject( $res ) )
174 $linkBatch->addObj( Title
::makeTitleSafe( $row->wl_namespace
, $row->wl_title
) );
175 $linkBatch->execute();
176 if( $dbr->numRows( $res ) > 0 )
177 $dbr->dataSeek( $res, 0 ); # Let's do the time warp again!
179 $sk = $wgUser->getSkin();
182 while( $s = $dbr->fetchObject( $res ) ) {
183 $list[$s->wl_namespace
][$s->wl_title
] = $s->page_is_redirect
;
186 // TODO: Display a TOC
187 foreach($list as $ns => $titles) {
188 if (Namespace::isTalk($ns))
191 $wgOut->addHTML( '<h2>' . $wgContLang->getFormattedNsText( $ns ) . '</h2>' );
192 $wgOut->addHTML( '<ul>' );
193 foreach( $titles as $title => $redir ) {
194 $titleObj = Title
::makeTitle( $ns, $title );
195 if( is_null( $titleObj ) ) {
198 htmlspecialchars( $s->wl_title
) . '" in namespace ' . $s->wl_namespace
. " -->\n"
202 $toolLinks = array();
203 $titleText = $titleObj->getPrefixedText();
204 $pageLink = $sk->makeLinkObj( $titleObj );
205 $toolLinks[] = $sk->makeLinkObj( $titleObj->getTalkPage(), $wgLang->getNsText( NS_TALK
) );
206 if( $titleObj->exists() )
207 $toolLinks[] = $sk->makeKnownLinkObj( $titleObj, wfMsgHtml( 'history_short' ), 'action=history' );
208 $toolLinks = '(' . implode( ' | ', $toolLinks ) . ')';
209 $checkbox = '<input type="checkbox" name="id[]" value="' . htmlspecialchars( $titleObj->getPrefixedText() ) . '" /> ' . ( $wgContLang->isRTL() ?
'‏' : '‎' );
211 $spanopen = '<span class="watchlistredir">';
212 $spanclosed = '</span>';
214 $spanopen = $spanclosed = '';
217 $wgOut->addHTML( "<li>{$checkbox}{$spanopen}{$pageLink}{$spanclosed} {$toolLinks}</li>\n" );
220 $wgOut->addHTML( '</ul>' );
223 "<input type='submit' name='remove' value=\"" .
224 htmlspecialchars( wfMsg( "removechecked" ) ) . "\" />\n" .
231 # If the watchlist is relatively short, it's simplest to zip
232 # down its entirety and then sort the results.
234 # If it's relatively long, it may be worth our while to zip
235 # through the time-sorted page list checking for watched items.
237 # Up estimate of watched items by 15% to compensate for talk pages...
239 $andHideOwn = $hideOwn ?
"AND (rc_user <> $uid)" : '';
240 if( $wgFilterRobotsWL ) {
241 $andHideBotsOptional = $hideBots ?
"AND (rc_bot = 0)" : '';
243 $andHideBotsOptional = "AND rc_this_oldid=page_latest";
247 # Show watchlist header
249 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
250 $header .= wfMsg( 'wlheader-enotif' ) . "\n";
252 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
253 $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
256 # TODO: Consider removing the third parameter
257 $header .= wfMsg( 'watchdetails', $wgLang->formatNum( $nitems ),
258 $wgLang->formatNum( $npages ), '',
259 $specialTitle->getFullUrl( 'edit=yes' ) );
260 $wgOut->addWikiText( $header );
262 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
263 $wgOut->addHTML( '<form action="' .
264 $specialTitle->escapeLocalUrl() .
265 '" method="post"><input type="submit" name="dummy" value="' .
266 htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
267 '" /><input type="hidden" name="reset" value="all" /></form>' .
272 rc_namespace page_namespace,rc_title page_title,
273 rc_comment rev_comment, rc_cur_id page_id,
274 rc_user rev_user,rc_user_text rev_user_text,
275 rc_timestamp rev_timestamp,rc_minor rev_minor_edit,
276 rc_this_oldid rev_id,
278 rc_new page_is_new,wl_notificationtimestamp
279 FROM $watchlist,$recentchanges,$page
281 AND wl_namespace=rc_namespace
282 AND wl_title=rc_title
283 AND rc_timestamp > '$cutoff'
284 AND rc_cur_id=page_id
288 ORDER BY rc_timestamp DESC";
290 $res = $dbr->query( $sql, $fname );
291 $numRows = $dbr->numRows( $res );
293 /* Start bottom header */
294 $wgOut->addHTML( "<hr />\n<p>" );
297 $wgOut->addWikiText( wfMsg( 'rcnote', $wgLang->formatNum( $numRows ),
298 $wgLang->formatNum( $days ) ) . '<br />' , false );
300 $wgOut->addWikiText( wfMsg( 'wlnote', $wgLang->formatNum( $numRows ),
301 $wgLang->formatNum( round($days*24) ) ) . '<br />' , false );
303 $wgOut->addHTML( "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n" );
305 $sk = $wgUser->getSkin();
306 $s = $sk->makeKnownLink(
307 $wgContLang->specialPage( 'Watchlist' ),
308 (0 == $hideOwn) ?
wfMsgHtml( 'wlhide' ) : wfMsgHtml( 'wlshow' ),
309 wfArrayToCGI( array('hideOwn' => 1-$hideOwn ), $nondefaults ) );
310 $wgOut->addHTML( wfMsgHtml( "wlhideshowown", $s ) );
312 if( $wgFilterRobotsWL ) {
313 $s = $sk->makeKnownLink(
314 $wgContLang->specialPage( 'Watchlist' ),
315 (0 == $hideBots) ?
wfMsgHtml( 'wlhide' ) : wfMsgHtml( 'wlshow' ),
316 wfArrayToCGI( array('hideBots' => 1-$hideBots ), $nondefaults ) );
317 $wgOut->addHTML( wfMsgHtml( "wlhideshowbots", " $s" ) );
320 # Form for namespace filtering
321 $thisTitle = Title
::makeTitle( NS_SPECIAL
, 'Watchlist' );
322 $thisAction = $thisTitle->escapeLocalUrl();
323 $nsForm = "<form method=\"post\" action=\"{$thisAction}\">\n";
324 $nsForm .= "<label for=\"namespace\">" . wfMsg( 'namespace' ) . "</label> ";
325 $nsForm .= HTMLnamespaceselector( $nameSpace, '' ) . "\n";
326 $nsForm .= ( $hideOwn ?
"<input type=\"hidden\" name=\"hideown\" value=\"1\" />\n" : "" );
327 $nsForm .= ( $hideBots ?
"<input type=\"hidden\" name=\"hidebots\" value=\"1\" />\n" : "" );
328 $nsForm .= "<input type=\"hidden\" name=\"days\" value=\"" . $days . "\" />\n";
329 $nsForm .= "<input type=\"submit\" name=\"submit\" value=\"" . wfMsgHtml( 'allpagessubmit' ) . "\" />\n";
330 $nsForm .= "</form>\n";
331 $wgOut->addHTML( $nsForm );
333 if ( $numRows == 0 ) {
334 $wgOut->addWikitext( "<br />" . wfMsg( 'watchnochange' ), false );
335 $wgOut->addHTML( "</p>\n" );
339 $wgOut->addHTML( "</p>\n" );
340 /* End bottom header */
342 $list = ChangesList
::newFromUser( $wgUser );
344 $s = $list->beginRecentChangesList();
346 while ( $obj = $dbr->fetchObject( $res ) ) {
348 $rc = RecentChange
::newFromCurRow( $obj, $obj->rc_last_oldid
);
349 $rc->counter
= $counter++
;
351 if ( $wgShowUpdatedMarker ) {
352 $updated = $obj->wl_notificationtimestamp
;
354 // Same visual appearance as MW 1.4
358 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
359 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .wfStrencode($obj->page_title
). "' AND wl_namespace='{$obj->page_namespace}'" ;
360 $res3 = $dbr->query( $sql3, DB_READ
, $fname );
361 $x = $dbr->fetchObject( $res3 );
362 $rc->numberofWatchingusers
= $x->n
;
364 $rc->numberofWatchingusers
= 0;
367 $s .= $list->recentChangesLine( $rc, $updated );
369 $s .= $list->endRecentChangesList();
371 $dbr->freeResult( $res );
372 $wgOut->addHTML( $s );
374 if ( $wgUseWatchlistCache ) {
375 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
380 function wlHoursLink( $h, $page, $options = array() ) {
381 global $wgUser, $wgLang, $wgContLang;
382 $sk = $wgUser->getSkin();
383 $s = $sk->makeKnownLink(
384 $wgContLang->specialPage( $page ),
385 $wgLang->formatNum( $h ),
386 wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
390 function wlDaysLink( $d, $page, $options = array() ) {
391 global $wgUser, $wgLang, $wgContLang;
392 $sk = $wgUser->getSkin();
393 $s = $sk->makeKnownLink(
394 $wgContLang->specialPage( $page ),
395 ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
396 wfArrayToCGI( array('days' => $d), $options ) );
400 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
401 $hours = array( 1, 2, 6, 12 );
402 $days = array( 1, 3, 7 );
405 foreach( $hours as $h ) {
406 $hours[$i++
] = wlHoursLink( $h, $page, $options );
409 foreach( $days as $d ) {
410 $days[$i++
] = wlDaysLink( $d, $page, $options );
412 return wfMsg ('wlshowlast',
413 implode(' | ', $hours),
414 implode(' | ', $days),
415 wlDaysLink( 0, $page, $options ) );