5 * @subpackage SpecialPage
11 require_once( 'SpecialRecentchanges.php' );
12 require_once( 'WatchedItem.php' );
17 function wfSpecialWatchlist() {
18 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgRequest;
19 global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname;
20 global $wgEnotif, $wgShowUpdatedMarker, $wgRCShowWatchingUsers;
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 $uid = $wgUser->getID();
32 $wgOut->addWikiText( wfMsg( 'nowatchlist' ) );
37 $days = $wgRequest->getVal( 'days' );
38 $action = $wgRequest->getVal( 'action' );
39 $remove = $wgRequest->getVal( 'remove' );
40 $id = $wgRequest->getArray( 'id' );
42 $wgOut->addWikiText( wfMsg( 'email_notification_infotext' ) );
44 if( $wgRequest->getVal( 'reset' ) == 'all' ) {
45 $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($t->getDBkey() != '') {
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( 'all' );
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(isset($_REQUEST['magic'])) {
122 $wgOut->addWikiText( wfMsg( 'watchlistcontains', $wgLang->formatNum( $nitems ) ) .
123 '<p>' . wfMsg( 'watcheditlist' ) . "</p>\n" );
125 $wgOut->addHTML( '<form action=\'' .
126 $specialTitle->escapeLocalUrl( 'action=submit' ) .
127 "' 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();
137 while( $s = $dbr->fetchObject( $res ) ) {
138 $t = Title
::makeTitle( $s->wl_namespace
, $s->wl_title
);
139 if( is_null( $t ) ) {
140 $wgOut->addHTML( '<!-- bad title "' . htmlspecialchars( $s->wl_title
) . '" in namespace ' . IntVal( $s->wl_namespace
) . " -->\n" );
142 $t = $t->getPrefixedText();
143 $wgOut->addHTML( '<li><input type="checkbox" name="id[]" value="' . htmlspecialchars($t) . '" />' .
144 $sk->makeLink( $t, $t ) .
148 $wgOut->addHTML( "</ul>\n" .
149 "<input type='submit' name='remove' value=\"" .
150 htmlspecialchars( wfMsg( "removechecked" ) ) . "\" />\n" .
156 # If the watchlist is relatively short, it's simplest to zip
157 # down its entirety and then sort the results.
159 # If it's relatively long, it may be worth our while to zip
160 # through the time-sorted page list checking for watched items.
162 # Up estimate of watched items by 15% to compensate for talk pages...
163 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
164 $x = 'rev_timestamp';
165 $y = wfMsg( 'watchmethod-recent' );
166 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
167 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
168 # $z = "wl_namespace=cur_namespace & ~1";
169 $z = 'wl_namespace=page_namespace';
171 $x = 'page_timestamp';
172 $y = wfMsg( 'watchmethod-list' );
173 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
174 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
175 # $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
176 $z = 'wl_namespace=page_namespace';
180 $wgOut->addHTML( '<i>' . wfMsg( 'watchdetails',
181 $wgLang->formatNum( $nitems ), $wgLang->formatNum( $npages ), $y,
182 $specialTitle->escapeLocalUrl( 'magic=yes' ) ) . "</i><br />\n" );
184 $use_index = $dbr->useIndexClause( $x );
186 page_namespace,page_title,rev_comment, page_id,
187 rev_user,rev_user_text,rev_timestamp,rev_minor_edit,page_is_new,wl_notificationtimestamp
188 FROM $watchlist,$page,$revision $use_index
191 AND wl_title=page_title
192 AND page_latest=rev_id
194 ORDER BY rev_timestamp DESC";
197 $res = $dbr->query( $sql, $fname );
198 $numRows = $dbr->numRows( $res );
200 $note = wfMsg( 'rcnote', $wgLang->formatNum( $numRows ), $wgLang->formatNum( $days ) );
202 $note = wfMsg( 'wlnote', $wgLang->formatNum( $numRows ), $wgLang->formatNum( round($days*24) ) );
205 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
206 $note = wlCutoffLinks( $days );
207 $wgOut->addHTML( "{$note}\n" );
209 if ( $numRows == 0 ) {
210 $wgOut->addHTML( '<p><i>' . wfMsg( 'watchnochange' ) . '</i></p>' );
214 $sk = $wgUser->getSkin();
215 $list =& new ChangesList( $sk );
216 $s = $list->beginRecentChangesList();
218 while ( $obj = $dbr->fetchObject( $res ) ) {
220 $rc = RecentChange
::newFromCurRow( $obj );
221 $rc->counter
= $counter++
;
223 if ($wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' )) {
224 $rc->notificationtimestamp
= $obj->wl_notificationtimestamp
;
226 $rc->notificationtimestamp
= false;
229 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
230 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .wfStrencode($obj->cur_title
). "' AND wl_namespace='{$obj->cur_namespace}'" ;
231 $res3 = $dbr->query( $sql3, DB_READ
, $fname );
232 $x = $dbr->fetchObject( $res3 );
233 $rc->numberofWatchingusers
= $x->n
;
235 $rc->numberofWatchingusers
= 0;
238 $s .= $list->recentChangesLine( $rc, true);
240 $s .= $list->endRecentChangesList();
242 $dbr->freeResult( $res );
243 $wgOut->addHTML( $s );
245 if ( $wgUseWatchlistCache ) {
246 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
252 function wlHoursLink( $h, $page ) {
253 global $wgUser, $wgLang, $wgContLang;
254 $sk = $wgUser->getSkin();
255 $s = $sk->makeKnownLink(
256 $wgContLang->specialPage( $page ),
257 $wgLang->formatNum( $h ),
258 'days=' . ($h / 24.0) );
263 function wlDaysLink( $d, $page ) {
264 global $wgUser, $wgLang, $wgContLang;
265 $sk = $wgUser->getSkin();
266 $s = $sk->makeKnownLink(
267 $wgContLang->specialPage( $page ),
268 ($d ?
$wgLang->formatNum( $d ) : wfMsg( 'all' ) ), "days=$d" );
272 function wlCutoffLinks( $days, $page = 'Watchlist' )
274 $hours = array( 1, 2, 6, 12 );
275 $days = array( 1, 3, 7 );
278 foreach( $hours as $h ) {
279 $hours[$i++
] = wlHoursLink( $h, $page );
282 foreach( $days as $d ) {
283 $days[$i++
] = wlDaysLink( $d, $page );
285 return wfMsg ('wlshowlast',
286 implode(' | ', $hours),
287 implode(' | ', $days),
288 wlDaysLink( 0, $page ) );