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 $days = $wgRequest->getVal( 'days' );
38 $action = $wgRequest->getVal( 'action' );
39 $remove = $wgRequest->getVal( 'remove' );
40 $hideOwn = $wgRequest->getBool( 'hideOwn' );
41 $id = $wgRequest->getArray( 'id' );
43 $uid = $wgUser->getID();
44 if( $wgEnotifWatchlist && $wgRequest->getVal( 'reset' ) && $wgRequest->wasPosted() ) {
45 $wgUser->clearAllNotifications( $uid );
49 if(($action == 'submit') && isset($remove) && is_array($id)) {
50 $wgOut->addWikiText( wfMsg( 'removingchecked' ) );
51 $wgOut->addHTML( '<p>' );
52 foreach($id as $one) {
53 $t = Title
::newFromURL( $one );
54 if( !is_null( $t ) ) {
55 $wl = WatchedItem
::fromUserTitle( $wgUser, $t );
56 if( $wl->removeWatch() === false ) {
57 $wgOut->addHTML( "<br />\n" . wfMsg( 'couldntremove', htmlspecialchars($one) ) );
59 $wgOut->addHTML( ' (' . htmlspecialchars($one) . ')' );
62 $wgOut->addHTML( "<br />\n" . wfMsg( 'iteminvalidname', htmlspecialchars($one) ) );
65 $wgOut->addHTML( "done.</p>\n" );
68 if ( $wgUseWatchlistCache ) {
69 $memckey = "$wgDBname:watchlist:id:" . $wgUser->getId();
70 $cache_s = @$wgMemc->get( $memckey );
72 $wgOut->addWikiText( wfMsg('wlsaved') );
73 $wgOut->addHTML( $cache_s );
78 $dbr =& wfGetDB( DB_SLAVE
);
79 extract( $dbr->tableNames( 'page', 'revision', 'watchlist', 'recentchanges' ) );
81 $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
82 $res = $dbr->query( $sql, $fname );
83 $s = $dbr->fetchObject( $res );
85 # Patch *** A1 *** (see A2 below)
86 # adjust for page X, talk:page X, which are both stored separately, but treated together
87 # $nitems = $s->n / 2;
91 $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
95 if ( is_null( $days ) ) {
98 # Set default cutoff shorter
99 $days = (12.0 / 24.0); # 12 hours...
101 $days = 3; # longer cutoff for shortlisters
104 $days = floatval($days);
110 $npages = wfMsg( 'watchlistall1' );
112 $docutoff = "AND rev_timestamp > '" .
113 ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
115 $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
116 $res = $dbr->query( $sql, $fname );
117 $s = $dbr->fetchObject( $res );
122 if($wgRequest->getBool('edit') ||
$par == 'edit' ) {
123 $wgOut->addWikiText( wfMsg( 'watchlistcontains', $wgLang->formatNum( $nitems ) ) .
124 "\n\n" . wfMsg( 'watcheditlist' ) );
126 $wgOut->addHTML( '<form action=\'' .
127 $specialTitle->escapeLocalUrl( 'action=submit' ) .
128 "' method='post'>\n" );
131 # The following was proposed by KTurner 07.11.2004 to T.Gries
132 # $sql = "SELECT distinct (wl_namespace & ~1),wl_title FROM $watchlist WHERE wl_user=$uid";
133 $sql = "SELECT wl_namespace,wl_title FROM $watchlist WHERE wl_user=$uid";
135 $res = $dbr->query( $sql, $fname );
136 $sk = $wgUser->getSkin();
139 while( $s = $dbr->fetchObject( $res ) ) {
140 $list[$s->wl_namespace
][] = $s->wl_title
;
143 // TODO: Display a TOC
144 foreach($list as $ns => $titles) {
145 if (Namespace::isTalk($ns))
148 $wgOut->addHTML( '<h2>' . $wgContLang->getFormattedNsText( $ns ) . '</h2>' );
149 $wgOut->addHTML( '<ul>' );
150 foreach($titles as $title) {
151 $t = Title
::makeTitle( $ns, $title );
152 if( is_null( $t ) ) {
155 htmlspecialchars( $s->wl_title
) . '" in namespace ' . $s->wl_namespace
. " -->\n"
158 $t = $t->getPrefixedText();
160 '<li><input type="checkbox" name="id[]" value="' . htmlspecialchars($t) . '" />' .
161 $sk->makeLink( $t, $t ) .
166 $wgOut->addHTML( '</ul>' );
169 "<input type='submit' name='remove' value=\"" .
170 htmlspecialchars( wfMsg( "removechecked" ) ) . "\" />\n" .
177 # If the watchlist is relatively short, it's simplest to zip
178 # down its entirety and then sort the results.
180 # If it's relatively long, it may be worth our while to zip
181 # through the time-sorted page list checking for watched items.
183 # Up estimate of watched items by 15% to compensate for talk pages...
184 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
185 $x = 'rev_timestamp';
186 $y = wfMsg( 'watchmethod-recent' );
187 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
188 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
189 # $z = "wl_namespace=cur_namespace & ~1";
190 $z = 'wl_namespace=page_namespace';
192 $x = 'page_timestamp';
193 $y = wfMsg( 'watchmethod-list' );
194 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
195 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
196 # $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
197 $z = 'wl_namespace=page_namespace';
200 $andHideOwn = $hideOwn ?
"AND (rev_user <> $uid)" : '';
202 # Show watchlist header
204 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
205 $header .= wfMsg( 'wlheader-enotif' ) . "\n";
207 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
208 $header .= wfMsg( 'wlheader-showupdated' ) . "\n";
211 $header .= wfMsg( 'watchdetails', $wgLang->formatNum( $nitems / 2 ),
212 $wgLang->formatNum( $npages ), $y,
213 $specialTitle->getFullUrl( 'edit=yes' ) );
214 $wgOut->addWikiText( $header );
216 if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) {
217 $wgOut->addHTML( '<form action="' .
218 $specialTitle->escapeLocalUrl() .
219 '" method="post"><input type="submit" name="dummy" value="' .
220 htmlspecialchars( wfMsg( 'enotif_reset' ) ) .
221 '" /><input type="hidden" name="reset" value="all" /></form>' .
225 $use_index = $dbr->useIndexClause( $x );
227 page_namespace,page_title,rev_comment, page_id,
228 rev_user,rev_user_text,rev_timestamp,rev_minor_edit,rev_id,page_is_new,wl_notificationtimestamp
229 FROM $watchlist,$page,$revision $use_index
233 AND wl_title=page_title
234 AND page_latest=rev_id
236 ORDER BY rev_timestamp DESC";
239 $res = $dbr->query( $sql, $fname );
240 $numRows = $dbr->numRows( $res );
242 $note = wfMsg( 'rcnote', $wgLang->formatNum( $numRows ), $wgLang->formatNum( $days ) );
244 $note = wfMsg( 'wlnote', $wgLang->formatNum( $numRows ), $wgLang->formatNum( round($days*24) ) );
247 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
248 $note = wlCutoffLinks( $days );
249 $wgOut->addHTML( "{$note}\n" );
251 $sk = $wgUser->getSkin();
252 $s = $sk->makeKnownLink(
253 $wgContLang->specialPage( 'Watchlist' ),
254 (0 == $hideOwn) ?
wfMsg( 'wlhide' ) : wfMsg( 'wlshow' ),
255 'hideOwn=' . $wgLang->formatNum( 1-$hideOwn ) );
257 $note = wfMsg( "wlhideshowown", $s );
258 $wgOut->addHTML( "\n<br />{$note}\n<br />" );
260 if ( $numRows == 0 ) {
261 $wgOut->addHTML( '<p><i>' . wfMsg( 'watchnochange' ) . '</i></p>' );
265 $sk = $wgUser->getSkin();
266 $list =& new ChangesList( $sk );
267 $s = $list->beginRecentChangesList();
269 while ( $obj = $dbr->fetchObject( $res ) ) {
271 $rc = RecentChange
::newFromCurRow( $obj );
272 $rc->counter
= $counter++
;
274 if ( $wgShowUpdatedMarker ) {
275 $updated = $obj->wl_notificationtimestamp
;
277 // Same visual appearance as MW 1.4
281 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
282 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .wfStrencode($obj->page_title
). "' AND wl_namespace='{$obj->page_namespace}'" ;
283 $res3 = $dbr->query( $sql3, DB_READ
, $fname );
284 $x = $dbr->fetchObject( $res3 );
285 $rc->numberofWatchingusers
= $x->n
;
287 $rc->numberofWatchingusers
= 0;
290 $s .= $list->recentChangesLine( $rc, $updated );
292 $s .= $list->endRecentChangesList();
294 $dbr->freeResult( $res );
295 $wgOut->addHTML( $s );
297 if ( $wgUseWatchlistCache ) {
298 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
304 function wlHoursLink( $h, $page ) {
305 global $wgUser, $wgLang, $wgContLang;
306 $sk = $wgUser->getSkin();
307 $s = $sk->makeKnownLink(
308 $wgContLang->specialPage( $page ),
309 $wgLang->formatNum( $h ),
310 'days=' . ($h / 24.0) );
315 function wlDaysLink( $d, $page ) {
316 global $wgUser, $wgLang, $wgContLang;
317 $sk = $wgUser->getSkin();
318 $s = $sk->makeKnownLink(
319 $wgContLang->specialPage( $page ),
320 ($d ?
$wgLang->formatNum( $d ) : wfMsg( 'watchlistall2' ) ), "days=$d" );
324 function wlCutoffLinks( $days, $page = 'Watchlist' )
326 $hours = array( 1, 2, 6, 12 );
327 $days = array( 1, 3, 7 );
330 foreach( $hours as $h ) {
331 $hours[$i++
] = wlHoursLink( $h, $page );
334 foreach( $days as $d ) {
335 $days[$i++
] = wlDaysLink( $d, $page );
337 return wfMsg ('wlshowlast',
338 implode(' | ', $hours),
339 implode(' | ', $days),
340 wlDaysLink( 0, $page ) );