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->addHTML( wfMsg( "nowatchlist" ) );
37 $days = $wgRequest->getVal( 'days' );
38 $action = $wgRequest->getVal( 'action' );
39 $remove = $wgRequest->getVal( 'remove' );
40 $id = $wgRequest->getArray( 'id' );
42 $wgOut->addHTML( wfMsg( "email_notification_infotext" ) );
44 if( $wgRequest->getVal( 'reset' ) == 'all' ) {
45 $wgUser->clearAllNotifications();
48 if(($action == "submit") && isset($remove) && is_array($id)) {
49 $wgOut->addHTML( wfMsg( "removingchecked" ) );
50 foreach($id as $one) {
51 $t = Title
::newFromURL( $one );
52 if($t->getDBkey() != "") {
53 $wl = WatchedItem
::fromUserTitle( $wgUser, $t );
54 if( $wl->removeWatch() === false ) {
55 $wgOut->addHTML( "<br />\n" . wfMsg( "couldntremove", htmlspecialchars($one) ) );
57 $wgOut->addHTML( " (" . htmlspecialchars($one) . ")" );
60 $wgOut->addHTML( "<br />\n" . wfMsg( "iteminvalidname", htmlspecialchars($one) ) );
63 $wgOut->addHTML( "done.\n<p>" );
66 if ( $wgUseWatchlistCache ) {
67 $memckey = "$wgDBname:watchlist:id:" . $wgUser->getId();
68 $cache_s = @$wgMemc->get( $memckey );
70 $wgOut->addHTML( wfMsg("wlsaved") );
71 $wgOut->addHTML( $cache_s );
76 $dbr =& wfGetDB( DB_SLAVE
);
77 extract( $dbr->tableNames( 'cur', 'watchlist', 'recentchanges' ) );
79 $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
80 $res = $dbr->query( $sql, $fname );
81 $s = $dbr->fetchObject( $res );
83 # Patch *** A1 *** (see A2 below)
84 # adjust for page X, talk:page X, which are both stored separately, but treated together
85 # $nitems = $s->n / 2;
89 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
93 if ( is_null( $days ) ) {
96 # Set default cutoff shorter
97 $days = (12.0 / 24.0); # 12 hours...
99 $days = 3; # longer cutoff for shortlisters
102 $days = floatval($days);
108 $npages = wfMsg( "all" );
110 $docutoff = "AND cur_timestamp > '" .
111 ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
113 $sql = "SELECT COUNT(*) AS n FROM $cur WHERE cur_timestamp>'$cutoff'";
114 $res = $dbr->query( $sql, $fname );
115 $s = $dbr->fetchObject( $res );
120 if(isset($_REQUEST['magic'])) {
121 $wgOut->addHTML( wfMsg( "watchlistcontains", $wgLang->formatNum( $nitems ) ) .
122 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
124 $wgOut->addHTML( "<form action='" .
125 $specialTitle->escapeLocalUrl( "action=submit" ) .
126 "' 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();
136 while( $s = $dbr->fetchObject( $res ) ) {
137 $t = Title
::makeTitle( $s->wl_namespace
, $s->wl_title
);
138 if( is_null( $t ) ) {
139 $wgOut->addHTML( '<!-- bad title "' . htmlspecialchars( $s->wl_title
) . '" in namespace ' . IntVal( $s->wl_namespace
) . " -->\n" );
141 $t = $t->getPrefixedText();
142 $wgOut->addHTML( "<li><input type='checkbox' name='id[]' value=\"" . htmlspecialchars($t) . "\" />" .
143 $sk->makeLink( $t, $t ) .
147 $wgOut->addHTML( "</ul>\n" .
148 "<input type='submit' name='remove' value=\"" .
149 htmlspecialchars( wfMsg( "removechecked" ) ) . "\" />\n" .
155 # If the watchlist is relatively short, it's simplest to zip
156 # down its entirety and then sort the results.
158 # If it's relatively long, it may be worth our while to zip
159 # through the time-sorted page list checking for watched items.
161 # Up estimate of watched items by 15% to compensate for talk pages...
162 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
163 $x = "cur_timestamp";
164 $y = wfMsg( "watchmethod-recent" );
165 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
166 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
167 # $z = "wl_namespace=cur_namespace & ~1";
168 $z = "wl_namespace=cur_namespace";
170 $x = "name_title_timestamp";
171 $y = wfMsg( "watchmethod-list" );
172 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
173 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
174 # $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
175 $z = "wl_namespace=cur_namespace";
179 $wgOut->addHTML( "<i>" . wfMsg( "watchdetails",
180 $wgLang->formatNum( $nitems ), $wgLang->formatNum( $npages ), $y,
181 $specialTitle->escapeLocalUrl( "magic=yes" ) ) . "</i><br />\n" );
183 $use_index = $dbr->useIndexClause( $x );
185 cur_namespace,cur_title,cur_comment, cur_id,
186 cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new,wl_notificationtimestamp
187 FROM $watchlist,$cur $use_index
190 AND wl_title=cur_title
192 ORDER BY cur_timestamp DESC";
195 $res = $dbr->query( $sql, $fname );
196 $numRows = $dbr->numRows( $res );
198 $note = wfMsg( "rcnote", $wgLang->formatNum( $numRows ), $wgLang->formatNum( $days ) );
200 $note = wfMsg( "wlnote", $wgLang->formatNum( $numRows ), $wgLang->formatNum( round($days*24) ) );
203 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
204 $note = wlCutoffLinks( $days );
205 $wgOut->addHTML( "{$note}\n" );
207 if ( $numRows == 0 ) {
208 $wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
212 $sk = $wgUser->getSkin();
213 $list =& new ChangesList( $sk );
214 $s = $list->beginRecentChangesList();
216 while ( $obj = $dbr->fetchObject( $res ) ) {
218 $rc = RecentChange
::newFromCurRow( $obj );
219 $rc->counter
= $counter++
;
221 if ($wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' )) {
222 $rc->notificationtimestamp
= $obj->wl_notificationtimestamp
;
224 $rc->notificationtimestamp
= false;
227 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
228 $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" .wfStrencode($obj->cur_title
). "' AND wl_namespace='{$obj->cur_namespace}'" ;
229 $res3 = $dbr->query( $sql3, DB_READ
, $fname );
230 $x = $dbr->fetchObject( $res3 );
231 $rc->numberofWatchingusers
= $x->n
;
233 $rc->numberofWatchingusers
= 0;
236 $s .= $list->recentChangesLine( $rc, true);
238 $s .= $list->endRecentChangesList();
240 $dbr->freeResult( $res );
241 $wgOut->addHTML( $s );
243 if ( $wgUseWatchlistCache ) {
244 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
250 function wlHoursLink( $h, $page ) {
251 global $wgUser, $wgLang, $wgContLang;
252 $sk = $wgUser->getSkin();
253 $s = $sk->makeKnownLink(
254 $wgContLang->specialPage( $page ),
255 $wgLang->formatNum( $h ),
256 "days=" . ($h / 24.0) );
261 function wlDaysLink( $d, $page ) {
262 global $wgUser, $wgLang, $wgContLang;
263 $sk = $wgUser->getSkin();
264 $s = $sk->makeKnownLink(
265 $wgContLang->specialPage( $page ),
266 ($d ?
$wgLang->formatNum( $d ) : wfMsg( "all" ) ), "days=$d" );
270 function wlCutoffLinks( $days, $page = "Watchlist" )
272 $hours = array( 1, 2, 6, 12 );
273 $days = array( 1, 3, 7 );
276 foreach( $hours as $h ) {
277 $hours[$i++
] = wlHoursLink( $h, $page );
280 foreach( $days as $d ) {
281 $days[$i++
] = wlDaysLink( $d, $page );
283 return wfMsg ("wlshowlast",
284 implode(" | ", $hours),
285 implode(" | ", $days),
286 wlDaysLink( 0, $page ) );