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 $fname = 'wfSpecialWatchlist';
23 $wgOut->setPagetitle( wfMsg( 'watchlist' ) );
24 $sub = wfMsg( 'watchlistsub', $wgUser->getName() );
25 $wgOut->setSubtitle( $sub );
26 $wgOut->setRobotpolicy( 'noindex,nofollow' );
28 $specialTitle = Title
::makeTitle( NS_SPECIAL
, 'Watchlist' );
30 if( $wgUser->isAnon() ) {
31 $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
36 $days = $wgRequest->getVal( 'days' );
37 $action = $wgRequest->getVal( 'action' );
38 $remove = $wgRequest->getVal( 'remove' );
39 $hideOwn = $wgRequest->getBool( 'hideOwn' );
40 $id = $wgRequest->getArray( 'id' );
42 $uid = $wgUser->getID();
43 if( $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) {
44 $wgUser->clearAllNotifications( $uid );
48 if(($action == 'submit') && isset($remove) && is_array($id)) {
49 $wgOut->addWikiText( wfMsg( 'removingchecked' ) );
50 $wgOut->addHTML( '<p>' );
51 foreach($id as $one) {
52 $t = Title
::newFromURL( $one );
53 if( !is_null( $t ) ) {
54 $wl = WatchedItem
::fromUserTitle( $wgUser, $t );
55 if( $wl->removeWatch() === false ) {
56 $wgOut->addHTML( "<br />\n" . wfMsg( 'couldntremove', htmlspecialchars($one) ) );
58 $wgOut->addHTML( ' (' . htmlspecialchars($one) . ')' );
61 $wgOut->addHTML( "<br />\n" . wfMsg( 'iteminvalidname', htmlspecialchars($one) ) );
64 $wgOut->addHTML( "done.</p>\n" );
67 if ( $wgUseWatchlistCache ) {
68 $memckey = "$wgDBname:watchlist:id:" . $wgUser->getId();
69 $cache_s = @$wgMemc->get( $memckey );
71 $wgOut->addWikiText( wfMsg('wlsaved') );
72 $wgOut->addHTML( $cache_s );
77 $dbr =& wfGetDB( DB_SLAVE
);
78 extract( $dbr->tableNames( 'page', 'revision', 'watchlist', 'recentchanges' ) );
80 $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
81 $res = $dbr->query( $sql, $fname );
82 $s = $dbr->fetchObject( $res );
84 # Patch *** A1 *** (see A2 below)
85 # adjust for page X, talk:page X, which are both stored separately, but treated together
86 # $nitems = $s->n / 2;
90 $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
94 if ( is_null( $days ) ) {
97 # Set default cutoff shorter
98 $days = (12.0 / 24.0); # 12 hours...
100 $days = 3; # longer cutoff for shortlisters
103 $days = floatval($days);
109 $npages = wfMsg( 'watchlistall1' );
111 $docutoff = "AND rev_timestamp > '" .
112 ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
114 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
115 $res = $dbr->query( $sql, $fname );
116 $s = $dbr->fetchObject( $res );
121 if($wgRequest->getBool('edit') ||
$par == 'edit' ) {
122 $wgOut->addWikiText( wfMsg( 'watchlistcontains', $wgLang->formatNum( $nitems ) ) .
123 "\n\n" . wfMsg( 'watcheditlist' ) );
125 $wgOut->addHTML( '<form action=\'' .
126 $specialTitle->escapeLocalUrl( 'action=submit' ) .
127 "' method='post'>\n" );
130 # The following was proposed by KTurner 07.11.2004 to T.Gries
131 # $sql = "SELECT distinct (wl_namespace & ~1),wl_title FROM $watchlist WHERE wl_user=$uid";
132 $sql = "SELECT wl_namespace,wl_title FROM $watchlist WHERE wl_user=$uid";
134 $res = $dbr->query( $sql, $fname );
135 $sk = $wgUser->getSkin();
138 while( $s = $dbr->fetchObject( $res ) ) {
139 $list[$s->wl_namespace
][] = $s->wl_title
;
142 // TODO: Display a t TOC
143 foreach($list as $ns => $titles) {
145 $wgOut->addHTML( '<h2>' . $wgContLang->getFormattedNsText( $ns ) . '</h2>' );
146 $wgOut->addHTML( '<ul>' );
147 foreach($titles as $title) {
148 $t = Title
::makeTitle( $ns, $title );
149 if( is_null( $t ) ) {
152 htmlspecialchars( $s->wl_title
) . '" in namespace ' . $s->wl_namespace
. " -->\n"
155 $t = $t->getPrefixedText();
157 '<li><input type="checkbox" name="id[]" value="' . htmlspecialchars($t) . '" />' .
158 $sk->makeLink( $t, $t ) .
163 $wgOut->addHTML( '</ul>' );
166 "<input type='submit' name='remove' value=\"" .
167 htmlspecialchars( wfMsg( "removechecked" ) ) . "\" />\n" .
174 # If the watchlist is relatively short, it's simplest to zip
175 # down its entirety and then sort the results.
177 # If it's relatively long, it may be worth our while to zip
178 # through the time-sorted page list checking for watched items.
180 # Up estimate of watched items by 15% to compensate for talk pages...
181 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
182 $x = 'rev_timestamp';
183 $y = wfMsg( 'watchmethod-recent' );
184 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
185 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
186 # $z = "wl_namespace=cur_namespace & ~1";
187 $z = 'wl_namespace=page_namespace';
189 $x = 'page_timestamp';
190 $y = wfMsg( 'watchmethod-list' );
191 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
192 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
193 # $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
194 $z = 'wl_namespace=page_namespace';
197 $andHideOwn = $hideOwn ?
"AND (rev_user <> $uid)" : '';
199 # Show watchlist header
201 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
202 $header .= wfMsg( 'wlheader-enotif' ) . "\n";
204 if ( $wgShowUpdatedMarker ) {
205 $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
208 $header .= wfMsg( 'watchdetails', $wgLang->formatNum( $nitems ),
209 $wgLang->formatNum( $npages ), $y,
210 $specialTitle->getFullUrl( 'edit=yes' ) );
211 $wgOut->addWikiText( $header );
213 if ( $wgShowUpdatedMarker ) {
214 $wgOut->addHTML( '<form action="' .
215 $specialTitle->escapeLocalUrl() .
216 '" method="post"><input type="submit" name="dummy" value="' .
217 htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
218 '" /><input type="hidden" name="reset" value="all" /></form>' .
222 $use_index = $dbr->useIndexClause( $x );
224 page_namespace,page_title,rev_comment, page_id,
225 rev_user,rev_user_text,rev_timestamp,rev_minor_edit,page_is_new,wl_notificationtimestamp
226 FROM $watchlist,$page,$revision $use_index
230 AND wl_title=page_title
231 AND page_latest=rev_id
233 ORDER BY rev_timestamp DESC";
236 $res = $dbr->query( $sql, $fname );
237 $numRows = $dbr->numRows( $res );
239 $note = wfMsg( 'rcnote', $wgLang->formatNum( $numRows ), $wgLang->formatNum( $days ) );
241 $note = wfMsg( 'wlnote', $wgLang->formatNum( $numRows ), $wgLang->formatNum( round($days*24) ) );
244 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
245 $note = wlCutoffLinks( $days );
246 $wgOut->addHTML( "{$note}\n" );
248 $sk = $wgUser->getSkin();
249 $s = $sk->makeKnownLink(
250 $wgContLang->specialPage( 'Watchlist' ),
251 (0 == $hideOwn) ?
wfMsg( 'wlhide' ) : wfMsg( 'wlshow' ),
252 'hideOwn=' . $wgLang->formatNum( 1-$hideOwn ) );
254 $note = wfMsg( "wlhideshowown", $s );
255 $wgOut->addHTML( "\n<br />{$note}\n<br />" );
257 if ( $numRows == 0 ) {
258 $wgOut->addHTML( '<p><i>' . wfMsg( 'watchnochange' ) . '</i></p>' );
262 $sk = $wgUser->getSkin();
263 $list =& new ChangesList( $sk );
264 $s = $list->beginRecentChangesList();
266 while ( $obj = $dbr->fetchObject( $res ) ) {
268 $rc = RecentChange
::newFromCurRow( $obj );
269 $rc->counter
= $counter++
;
271 if ( $wgShowUpdatedMarker ) {
272 $updated = $obj->wl_notificationtimestamp
;
274 // Same visual appearance as MW 1.4
278 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
279 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .wfStrencode($obj->page_title
). "' AND wl_namespace='{$obj->page_namespace}'" ;
280 $res3 = $dbr->query( $sql3, DB_READ
, $fname );
281 $x = $dbr->fetchObject( $res3 );
282 $rc->numberofWatchingusers
= $x->n
;
284 $rc->numberofWatchingusers
= 0;
287 $s .= $list->recentChangesLine( $rc, $updated );
289 $s .= $list->endRecentChangesList();
291 $dbr->freeResult( $res );
292 $wgOut->addHTML( $s );
294 if ( $wgUseWatchlistCache ) {
295 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
301 function wlHoursLink( $h, $page ) {
302 global $wgUser, $wgLang, $wgContLang;
303 $sk = $wgUser->getSkin();
304 $s = $sk->makeKnownLink(
305 $wgContLang->specialPage( $page ),
306 $wgLang->formatNum( $h ),
307 'days=' . ($h / 24.0) );
312 function wlDaysLink( $d, $page ) {
313 global $wgUser, $wgLang, $wgContLang;
314 $sk = $wgUser->getSkin();
315 $s = $sk->makeKnownLink(
316 $wgContLang->specialPage( $page ),
317 ($d ?
$wgLang->formatNum( $d ) : wfMsg( 'watchlistall2' ) ), "days=$d" );
321 function wlCutoffLinks( $days, $page = 'Watchlist' )
323 $hours = array( 1, 2, 6, 12 );
324 $days = array( 1, 3, 7 );
327 foreach( $hours as $h ) {
328 $hours[$i++
] = wlHoursLink( $h, $page );
331 foreach( $days as $d ) {
332 $days[$i++
] = wlDaysLink( $d, $page );
334 return wfMsg ('wlshowlast',
335 implode(' | ', $hours),
336 implode(' | ', $days),
337 wlDaysLink( 0, $page ) );