cec90c4b637cfa644abd3179addaceedabd95f2d
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,
45 $days = $wgRequest->getVal( 'days' );
46 $hideOwn = $wgRequest->getBool( 'hideOwn' );
47 $hideBots = $wgRequest->getBool( 'hideBots' );
50 $action = $wgRequest->getVal( 'action' );
51 $remove = $wgRequest->getVal( 'remove' );
52 $id = $wgRequest->getArray( 'id' );
54 $uid = $wgUser->getID();
55 if( $wgEnotifWatchlist && $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) {
56 $wgUser->clearAllNotifications( $uid );
59 # Deleting items from watchlist
60 if(($action == 'submit') && isset($remove) && is_array($id)) {
61 $wgOut->addWikiText( wfMsg( 'removingchecked' ) );
62 $wgOut->addHTML( '<p>' );
63 foreach($id as $one) {
64 $t = Title
::newFromURL( $one );
65 if( !is_null( $t ) ) {
66 $wl = WatchedItem
::fromUserTitle( $wgUser, $t );
67 if( $wl->removeWatch() === false ) {
68 $wgOut->addHTML( "<br />\n" . wfMsg( 'couldntremove', htmlspecialchars($one) ) );
70 $wgOut->addHTML( ' (' . htmlspecialchars($one) . ')' );
73 $wgOut->addHTML( "<br />\n" . wfMsg( 'iteminvalidname', htmlspecialchars($one) ) );
76 $wgOut->addHTML( "done.</p>\n" );
79 if ( $wgUseWatchlistCache ) {
80 $memckey = "$wgDBname:watchlist:id:" . $wgUser->getId();
81 $cache_s = @$wgMemc->get( $memckey );
83 $wgOut->addWikiText( wfMsg('wlsaved') );
84 $wgOut->addHTML( $cache_s );
89 $dbr =& wfGetDB( DB_SLAVE
);
90 extract( $dbr->tableNames( 'page', 'revision', 'watchlist', 'recentchanges' ) );
92 $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
93 $res = $dbr->query( $sql, $fname );
94 $s = $dbr->fetchObject( $res );
96 # Patch *** A1 *** (see A2 below)
97 # adjust for page X, talk:page X, which are both stored separately, but treated together
98 $nitems = floor($s->n
/ 2);
102 $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
106 if( is_null($days) ||
!is_numeric($days) ) {
107 $big = 1000; /* The magical big */
109 # Set default cutoff shorter
110 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
112 $days = $defaults['days']; # default cutoff for shortlisters
115 $days = floatval($days);
118 // Dump everything here
119 $nondefaults = array();
121 wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults);
122 wfAppendToArrayIfNotDefault( 'hideOwn', $hideOwn, $defaults, $nondefaults);
123 wfAppendToArrayIfNotDefault( 'hideBots', $hideBots, $defaults, $nondefaults);
128 $npages = wfMsg( 'watchlistall1' );
130 $docutoff = "AND rev_timestamp > '" .
131 ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
134 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
135 $res = $dbr->query( $sql, $fname );
136 $s = $dbr->fetchObject( $res );
139 $npages = 40000 * $days;
143 /* Edit watchlist form */
144 if($wgRequest->getBool('edit') ||
$par == 'edit' ) {
145 $wgOut->addWikiText( wfMsg( 'watchlistcontains', $wgLang->formatNum( $nitems ) ) .
146 "\n\n" . wfMsg( 'watcheditlist' ) );
148 $wgOut->addHTML( '<form action=\'' .
149 $specialTitle->escapeLocalUrl( 'action=submit' ) .
150 "' method='post'>\n" );
153 # The following was proposed by KTurner 07.11.2004 to T.Gries
154 # $sql = "SELECT distinct (wl_namespace & ~1),wl_title FROM $watchlist WHERE wl_user=$uid";
155 $sql = "SELECT wl_namespace, wl_title, page_is_redirect FROM $page LEFT JOIN $watchlist ON wl_namespace = page_namespace AND wl_title = page_title WHERE wl_user=$uid";
157 $res = $dbr->query( $sql, $fname );
159 # Batch existence check
160 $linkBatch = new LinkBatch();
161 while( $row = $dbr->fetchObject( $res ) )
162 $linkBatch->addObj( Title
::makeTitleSafe( $row->wl_namespace
, $row->wl_title
) );
163 $linkBatch->execute();
164 if( $dbr->numRows( $res ) > 0 )
165 $dbr->dataSeek( $res, 0 ); # Let's do the time warp again!
167 $sk = $wgUser->getSkin();
170 while( $s = $dbr->fetchObject( $res ) ) {
171 $list[$s->wl_namespace
][$s->wl_title
] = $s->page_is_redirect
;
174 // TODO: Display a TOC
175 foreach($list as $ns => $titles) {
176 if (Namespace::isTalk($ns))
179 $wgOut->addHTML( '<h2>' . $wgContLang->getFormattedNsText( $ns ) . '</h2>' );
180 $wgOut->addHTML( '<ul>' );
181 foreach( $titles as $title => $redir ) {
182 $titleObj = Title
::makeTitle( $ns, $title );
183 if( is_null( $titleObj ) ) {
186 htmlspecialchars( $s->wl_title
) . '" in namespace ' . $s->wl_namespace
. " -->\n"
190 $titleText = $titleObj->getPrefixedText();
191 $pageLink = $sk->makeLinkObj( $titleObj );
192 $talkLink = $sk->makeLinkObj( $titleObj->getTalkPage(), $wgLang->getNsText( NS_TALK
) );
193 $checkbox = '<input type="checkbox" name="id[]" value="' . htmlspecialchars( $titleObj->getPrefixedText() ) . '" /> ' . ( $wgContLang->isRTL() ?
'‏' : '‎' );
195 $spanopen = '<span class="watchlistredir">';
196 $spanclosed = '</span>';
198 $spanopen = $spanclosed = '';
201 $wgOut->addHTML( "<li>{$checkbox}{$spanopen}{$pageLink}{$spanclosed} ({$talkLink})</li>\n" );
204 $wgOut->addHTML( '</ul>' );
207 "<input type='submit' name='remove' value=\"" .
208 htmlspecialchars( wfMsg( "removechecked" ) ) . "\" />\n" .
215 # If the watchlist is relatively short, it's simplest to zip
216 # down its entirety and then sort the results.
218 # If it's relatively long, it may be worth our while to zip
219 # through the time-sorted page list checking for watched items.
221 # Up estimate of watched items by 15% to compensate for talk pages...
223 $andHideOwn = $hideOwn ?
"AND (rc_user <> $uid)" : '';
224 if( $wgFilterRobotsWL ) {
225 $andHideBotsOptional = $hideBots ?
"AND (rc_bot = 0)" : '';
227 $andHideBotsOptional = "AND rc_this_oldid=page_latest";
231 # Show watchlist header
233 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
234 $header .= wfMsg( 'wlheader-enotif' ) . "\n";
236 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
237 $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
240 # TODO: Consider removing the third parameter
241 $header .= wfMsg( 'watchdetails', $wgLang->formatNum( $nitems ),
242 $wgLang->formatNum( $npages ), '',
243 $specialTitle->getFullUrl( 'edit=yes' ) );
244 $wgOut->addWikiText( $header );
246 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
247 $wgOut->addHTML( '<form action="' .
248 $specialTitle->escapeLocalUrl() .
249 '" method="post"><input type="submit" name="dummy" value="' .
250 htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
251 '" /><input type="hidden" name="reset" value="all" /></form>' .
256 rc_namespace page_namespace,rc_title page_title,
257 rc_comment rev_comment, rc_cur_id page_id,
258 rc_user rev_user,rc_user_text rev_user_text,
259 rc_timestamp rev_timestamp,rc_minor rev_minor_edit,
260 rc_this_oldid rev_id,
262 rc_new page_is_new,wl_notificationtimestamp
263 FROM $watchlist,$recentchanges,$page
265 AND wl_namespace=rc_namespace
266 AND wl_title=rc_title
267 AND rc_timestamp > '$cutoff'
268 AND rc_cur_id=page_id
271 ORDER BY rc_timestamp DESC";
273 $res = $dbr->query( $sql, $fname );
274 $numRows = $dbr->numRows( $res );
276 /* Start bottom header */
277 $wgOut->addHTML( "<hr />\n<p>" );
280 $wgOut->addWikiText( wfMsg( 'rcnote', $wgLang->formatNum( $numRows ),
281 $wgLang->formatNum( $days ) ) . '<br />' , false );
283 $wgOut->addWikiText( wfMsg( 'wlnote', $wgLang->formatNum( $numRows ),
284 $wgLang->formatNum( round($days*24) ) ) . '<br />' , false );
286 $wgOut->addHTML( "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n" );
288 $sk = $wgUser->getSkin();
289 $s = $sk->makeKnownLink(
290 $wgContLang->specialPage( 'Watchlist' ),
291 (0 == $hideOwn) ?
wfMsgHtml( 'wlhide' ) : wfMsgHtml( 'wlshow' ),
292 wfArrayToCGI( array('hideOwn' => 1-$hideOwn ), $nondefaults ) );
293 $wgOut->addHTML( wfMsgHtml( "wlhideshowown", $s ) );
295 if( $wgFilterRobotsWL ) {
296 $s = $sk->makeKnownLink(
297 $wgContLang->specialPage( 'Watchlist' ),
298 (0 == $hideBots) ?
wfMsgHtml( 'wlhide' ) : wfMsgHtml( 'wlshow' ),
299 wfArrayToCGI( array('hideBots' => 1-$hideBots ), $nondefaults ) );
300 $wgOut->addHTML( wfMsgHtml( "wlhideshowbots", " $s" ) );
303 if ( $numRows == 0 ) {
304 $wgOut->addWikitext( "<br />" . wfMsg( 'watchnochange' ), false );
305 $wgOut->addHTML( "</p>\n" );
309 $wgOut->addHTML( "</p>\n" );
310 /* End bottom header */
312 $list = ChangesList
::newFromUser( $wgUser );
314 $s = $list->beginRecentChangesList();
316 while ( $obj = $dbr->fetchObject( $res ) ) {
318 $rc = RecentChange
::newFromCurRow( $obj, $obj->rc_last_oldid
);
319 $rc->counter
= $counter++
;
321 if ( $wgShowUpdatedMarker ) {
322 $updated = $obj->wl_notificationtimestamp
;
324 // Same visual appearance as MW 1.4
328 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
329 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .wfStrencode($obj->page_title
). "' AND wl_namespace='{$obj->page_namespace}'" ;
330 $res3 = $dbr->query( $sql3, DB_READ
, $fname );
331 $x = $dbr->fetchObject( $res3 );
332 $rc->numberofWatchingusers
= $x->n
;
334 $rc->numberofWatchingusers
= 0;
337 $s .= $list->recentChangesLine( $rc, $updated );
339 $s .= $list->endRecentChangesList();
341 $dbr->freeResult( $res );
342 $wgOut->addHTML( $s );
344 if ( $wgUseWatchlistCache ) {
345 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
350 function wlHoursLink( $h, $page, $options = array() ) {
351 global $wgUser, $wgLang, $wgContLang;
352 $sk = $wgUser->getSkin();
353 $s = $sk->makeKnownLink(
354 $wgContLang->specialPage( $page ),
355 $wgLang->formatNum( $h ),
356 wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
360 function wlDaysLink( $d, $page, $options = array() ) {
361 global $wgUser, $wgLang, $wgContLang;
362 $sk = $wgUser->getSkin();
363 $s = $sk->makeKnownLink(
364 $wgContLang->specialPage( $page ),
365 ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
366 wfArrayToCGI( array('days' => $d), $options ) );
370 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
371 $hours = array( 1, 2, 6, 12 );
372 $days = array( 1, 3, 7 );
375 foreach( $hours as $h ) {
376 $hours[$i++
] = wlHoursLink( $h, $page, $options );
379 foreach( $days as $d ) {
380 $days[$i++
] = wlDaysLink( $d, $page, $options );
382 return wfMsg ('wlshowlast',
383 implode(' | ', $hours),
384 implode(' | ', $days),
385 wlDaysLink( 0, $page, $options ) );