5 * @subpackage SpecialPage
11 require_once( 'SpecialRecentchanges.php' );
12 require_once( 'WatchedItem.php' );
17 function wfSpecialWatchlist( $par ) {
18 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgRequest, $wgContLang;
19 global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname;
20 global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
21 global $wgEnotifWatchlist;
22 $fname = 'wfSpecialWatchlist';
24 $wgOut->setPagetitle( wfMsg( 'watchlist' ) );
25 $sub = 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,
44 $days = $wgRequest->getVal( 'days' );
45 $hideOwn = $wgRequest->getBool( 'hideOwn' );
48 $action = $wgRequest->getVal( 'action' );
49 $remove = $wgRequest->getVal( 'remove' );
50 $id = $wgRequest->getArray( 'id' );
52 $uid = $wgUser->getID();
53 if( $wgEnotifWatchlist && $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) {
54 $wgUser->clearAllNotifications( $uid );
57 # Deleting items from watchlist
58 if(($action == 'submit') && isset($remove) && is_array($id)) {
59 $wgOut->addWikiText( wfMsg( 'removingchecked' ) );
60 $wgOut->addHTML( '<p>' );
61 foreach($id as $one) {
62 $t = Title
::newFromURL( $one );
63 if( !is_null( $t ) ) {
64 $wl = WatchedItem
::fromUserTitle( $wgUser, $t );
65 if( $wl->removeWatch() === false ) {
66 $wgOut->addHTML( "<br />\n" . wfMsg( 'couldntremove', htmlspecialchars($one) ) );
68 $wgOut->addHTML( ' (' . htmlspecialchars($one) . ')' );
71 $wgOut->addHTML( "<br />\n" . wfMsg( 'iteminvalidname', htmlspecialchars($one) ) );
74 $wgOut->addHTML( "done.</p>\n" );
77 if ( $wgUseWatchlistCache ) {
78 $memckey = "$wgDBname:watchlist:id:" . $wgUser->getId();
79 $cache_s = @$wgMemc->get( $memckey );
81 $wgOut->addWikiText( wfMsg('wlsaved') );
82 $wgOut->addHTML( $cache_s );
87 $dbr =& wfGetDB( DB_SLAVE
);
88 extract( $dbr->tableNames( 'page', 'revision', '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', $hideOwn, $defaults, $nondefaults);
125 $npages = wfMsg( 'watchlistall1' );
127 $docutoff = "AND rev_timestamp > '" .
128 ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
131 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
132 $res = $dbr->query( $sql, $fname );
133 $s = $dbr->fetchObject( $res );
136 $npages = 40000 * $days;
140 /* Edit watchlist form */
141 if($wgRequest->getBool('edit') ||
$par == 'edit' ) {
142 $wgOut->addWikiText( wfMsg( 'watchlistcontains', $wgLang->formatNum( $nitems ) ) .
143 "\n\n" . wfMsg( 'watcheditlist' ) );
145 $wgOut->addHTML( '<form action=\'' .
146 $specialTitle->escapeLocalUrl( 'action=submit' ) .
147 "' method='post'>\n" );
150 # The following was proposed by KTurner 07.11.2004 to T.Gries
151 # $sql = "SELECT distinct (wl_namespace & ~1),wl_title FROM $watchlist WHERE wl_user=$uid";
152 $sql = "SELECT wl_namespace,wl_title FROM $watchlist WHERE wl_user=$uid";
154 $res = $dbr->query( $sql, $fname );
155 $sk = $wgUser->getSkin();
158 while( $s = $dbr->fetchObject( $res ) ) {
159 $list[$s->wl_namespace
][] = $s->wl_title
;
162 // TODO: Display a TOC
163 foreach($list as $ns => $titles) {
164 if (Namespace::isTalk($ns))
167 $wgOut->addHTML( '<h2>' . $wgContLang->getFormattedNsText( $ns ) . '</h2>' );
168 $wgOut->addHTML( '<ul>' );
169 foreach($titles as $title) {
170 $t = Title
::makeTitle( $ns, $title );
171 if( is_null( $t ) ) {
174 htmlspecialchars( $s->wl_title
) . '" in namespace ' . $s->wl_namespace
. " -->\n"
177 $t = $t->getPrefixedText();
179 '<li><input type="checkbox" name="id[]" value="' . htmlspecialchars($t) . '" />' .
180 $sk->makeLink( $t, $t ) .
185 $wgOut->addHTML( '</ul>' );
188 "<input type='submit' name='remove' value=\"" .
189 htmlspecialchars( wfMsg( "removechecked" ) ) . "\" />\n" .
196 # If the watchlist is relatively short, it's simplest to zip
197 # down its entirety and then sort the results.
199 # If it's relatively long, it may be worth our while to zip
200 # through the time-sorted page list checking for watched items.
202 # Up estimate of watched items by 15% to compensate for talk pages...
204 $andHideOwn = $hideOwn ?
"AND (rc_user <> $uid)" : '';
206 # Show watchlist header
208 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
209 $header .= wfMsg( 'wlheader-enotif' ) . "\n";
211 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
212 $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
215 # TODO: Consider removing the third parameter
216 $header .= wfMsg( 'watchdetails', $wgLang->formatNum( $nitems ),
217 $wgLang->formatNum( $npages ), '',
218 $specialTitle->getFullUrl( 'edit=yes' ) );
219 $wgOut->addWikiText( $header );
221 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
222 $wgOut->addHTML( '<form action="' .
223 $specialTitle->escapeLocalUrl() .
224 '" method="post"><input type="submit" name="dummy" value="' .
225 htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
226 '" /><input type="hidden" name="reset" value="all" /></form>' .
231 rc_namespace page_namespace,rc_title page_title,
232 rc_comment rev_comment, rc_cur_id page_id,
233 rc_user rev_user,rc_user_text rev_user_text,
234 rc_timestamp rev_timestamp,rc_minor rev_minor_edit,
235 rc_this_oldid rev_id,
237 rc_new page_is_new,wl_notificationtimestamp
238 FROM $watchlist,$recentchanges,$page
240 AND wl_namespace=rc_namespace
241 AND wl_title=rc_title
242 AND rc_timestamp > '$cutoff'
243 AND rc_cur_id=page_id
244 AND rc_this_oldid=page_latest
246 ORDER BY rc_timestamp DESC";
248 $res = $dbr->query( $sql, $fname );
249 $numRows = $dbr->numRows( $res );
251 /* Start bottom header */
252 $wgOut->addHTML( "<hr />\n<p>" );
255 $wgOut->addWikiText( wfMsg( 'rcnote', $wgLang->formatNum( $numRows ),
256 $wgLang->formatNum( $days ) ) . '<br />' , false );
258 $wgOut->addWikiText( wfMsg( 'wlnote', $wgLang->formatNum( $numRows ),
259 $wgLang->formatNum( round($days*24) ) ) . '<br />' , false );
261 $wgOut->addHTML( "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n" );
263 $sk = $wgUser->getSkin();
264 $s = $sk->makeKnownLink(
265 $wgContLang->specialPage( 'Watchlist' ),
266 (0 == $hideOwn) ?
wfMsgHtml( 'wlhide' ) : wfMsgHtml( 'wlshow' ),
267 wfArrayToCGI( array('hideOwn' => 1-$hideOwn ), $nondefaults ) );
269 $wgOut->addHTML( wfMsgHtml( "wlhideshowown", $s ) );
271 if ( $numRows == 0 ) {
272 $wgOut->addWikitext( "<br />" . wfMsg( 'watchnochange' ), false );
273 $wgOut->addHTML( "</p>\n" );
277 $wgOut->addHTML( "</p>\n" );
278 /* End bottom header */
280 $sk = $wgUser->getSkin();
281 $list =& new ChangesList( $sk );
282 $s = $list->beginRecentChangesList();
284 while ( $obj = $dbr->fetchObject( $res ) ) {
286 $rc = RecentChange
::newFromCurRow( $obj, $obj->rc_last_oldid
);
287 $rc->counter
= $counter++
;
289 if ( $wgShowUpdatedMarker ) {
290 $updated = $obj->wl_notificationtimestamp
;
292 // Same visual appearance as MW 1.4
296 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
297 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .wfStrencode($obj->page_title
). "' AND wl_namespace='{$obj->page_namespace}'" ;
298 $res3 = $dbr->query( $sql3, DB_READ
, $fname );
299 $x = $dbr->fetchObject( $res3 );
300 $rc->numberofWatchingusers
= $x->n
;
302 $rc->numberofWatchingusers
= 0;
305 $s .= $list->recentChangesLine( $rc, $updated );
307 $s .= $list->endRecentChangesList();
309 $dbr->freeResult( $res );
310 $wgOut->addHTML( $s );
312 if ( $wgUseWatchlistCache ) {
313 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
318 function wlHoursLink( $h, $page, $options = array() ) {
319 global $wgUser, $wgLang, $wgContLang;
320 $sk = $wgUser->getSkin();
321 $s = $sk->makeKnownLink(
322 $wgContLang->specialPage( $page ),
323 $wgLang->formatNum( $h ),
324 wfArrayToCGI( array('days' => ($h / 24.0)), $options ) );
328 function wlDaysLink( $d, $page, $options = array() ) {
329 global $wgUser, $wgLang, $wgContLang;
330 $sk = $wgUser->getSkin();
331 $s = $sk->makeKnownLink(
332 $wgContLang->specialPage( $page ),
333 ($d ?
$wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ),
334 wfArrayToCGI( array('days' => $d), $options ) );
338 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
339 $hours = array( 1, 2, 6, 12 );
340 $days = array( 1, 3, 7 );
343 foreach( $hours as $h ) {
344 $hours[$i++
] = wlHoursLink( $h, $page, $options );
347 foreach( $days as $d ) {
348 $days[$i++
] = wlDaysLink( $d, $page, $options );
350 return wfMsg ('wlshowlast',
351 implode(' | ', $hours),
352 implode(' | ', $days),
353 wlDaysLink( 0, $page, $options ) );