2 require_once( "SpecialRecentchanges.php" );
3 require_once( "WatchedItem.php" );
5 function wfSpecialWatchlist()
7 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgLoadBalancer;
8 global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname, $wgIsMySQL;
9 global $days, $limit, $target; # From query string
10 $fname = "wfSpecialWatchlist";
12 $wgOut->setPagetitle( wfMsg( "watchlist" ) );
13 $sub = wfMsg( "watchlistsub", $wgUser->getName() );
14 $wgOut->setSubtitle( $sub );
15 $wgOut->setRobotpolicy( "noindex,nofollow" );
17 $specialTitle = Title
::makeTitle( NS_SPECIAL
, "Watchlist" );
19 $uid = $wgUser->getID();
21 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
25 global $action,$remove,$id;
26 if(($action == "submit") && isset($remove) && is_array($id)) {
27 $wgOut->addHTML( wfMsg( "removingchecked" ) );
28 foreach($id as $one) {
29 $t = Title
::newFromURL( $one );
30 if($t->getDBkey() != "") {
31 $wl = WatchedItem
::fromUserTitle( $wgUser, $t );
32 if( $wl->removeWatch() === false ) {
33 $wgOut->addHTML( "<br />\n" . wfMsg( "couldntremove", htmlspecialchars($one) ) );
35 $wgOut->addHTML( " (" . htmlspecialchars($one) . ")" );
38 $wgOut->addHTML( "<br />\n" . wfMsg( "iteminvalidname", htmlspecialchars($one) ) );
41 $wgOut->addHTML( "done.\n<p>" );
44 if ( $wgUseWatchlistCache ) {
45 $memckey = "$wgDBname:watchlist:id:" . $wgUser->getId();
46 $cache_s = @$wgMemc->get( $memckey );
48 $wgOut->addHTML( wfMsg("wlsaved") );
49 $wgOut->addHTML( $cache_s );
54 $wgLoadBalancer->force(-1);
55 $sql = "SELECT COUNT(*) AS n FROM watchlist WHERE wl_user=$uid";
56 $res = wfQuery( $sql, DB_READ
);
57 $s = wfFetchObject( $res );
59 $wgLoadBalancer->force(0);
61 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
65 $wgLoadBalancer->force(-1);
67 if ( ! isset( $days ) ) {
70 # Set default cutoff shorter
71 $days = (12.0 / 24.0); # 12 hours...
73 $days = 3; # longer cutoff for shortlisters
76 $days = floatval($days);
82 $npages = wfMsg( "all" );
84 $docutoff = "AND cur_timestamp > '" .
85 ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) )
87 $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'";
88 $res = wfQuery( $sql, DB_READ
);
89 $s = wfFetchObject( $res );
94 if(isset($_REQUEST['magic'])) {
95 $wgOut->addHTML( wfMsg( "watchlistcontains", $wgLang->formatNum( $nitems ) ) .
96 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
98 $wgOut->addHTML( "<form action='" .
99 $specialTitle->escapeLocalUrl( "action=submit" ) .
100 "' method='post'>\n" .
102 $sql = "SELECT wl_namespace,wl_title FROM watchlist WHERE wl_user=$uid";
103 $res = wfQuery( $sql, DB_READ
);
104 global $wgUser, $wgLang;
105 $sk = $wgUser->getSkin();
106 while( $s = wfFetchObject( $res ) ) {
107 $t = Title
::makeTitle( $s->wl_namespace
, $s->wl_title
);
108 if( is_null( $t ) ) {
109 $wgOut->addHTML( '<!-- bad title "' . htmlspecialchars( $s->wl_title
) . '" in namespace ' . IntVal( $s->wl_namespace
) . " -->\n" );
111 $t = $t->getPrefixedText();
112 $wgOut->addHTML( "<li><input type='checkbox' name='id[]' value=\"" . htmlspecialchars($t) . "\" />" .
113 $sk->makeKnownLink( $t, $t ) .
117 $wgOut->addHTML( "</ul>\n" .
118 "<input type='submit' name='remove' value='" .
119 wfMsg( "removechecked" ) . "' />\n" .
122 $wgLoadBalancer->force(0);
126 # If the watchlist is relatively short, it's simplest to zip
127 # down its entirety and then sort the results.
129 # If it's relatively long, it may be worth our while to zip
130 # through the time-sorted page list checking for watched items.
132 # Up estimate of watched items by 15% to compensate for talk pages...
133 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
134 $x = "cur_timestamp";
135 $y = wfMsg( "watchmethod-recent" );
136 $z = "wl_namespace=cur_namespace&65534";
138 $x = "name_title_timestamp";
139 $y = wfMsg( "watchmethod-list" );
140 $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
144 $wgOut->addHTML( "<i>" . wfMsg( "watchdetails",
145 $wgLang->formatNum( $nitems ), $wgLang->formatNum( $npages ), $y,
146 $specialTitle->escapeLocalUrl( "magic=yes" ) ) . "</i><br />\n" );
148 $use_index=$wgIsMySQL?
"USE INDEX ($x)":"";
150 cur_namespace,cur_title,cur_comment, cur_id,
151 cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new
152 FROM watchlist,cur $use_index
155 AND wl_title=cur_title
157 ORDER BY cur_timestamp DESC";
160 $res = wfQuery( $sql, DB_READ
, $fname );
163 $note = wfMsg( "rcnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
165 $note = wfMsg( "wlnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( round($days*24) ) );
168 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
169 $note = wlCutoffLinks( $days, $limit );
170 $wgOut->addHTML( "{$note}\n" );
172 if ( wfNumRows( $res ) == 0 ) {
173 $wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
174 $wgLoadBalancer->force(0);
178 $sk = $wgUser->getSkin();
179 $s = $sk->beginRecentChangesList();
181 while ( $obj = wfFetchObject( $res ) ) {
183 $rc = RecentChange
::newFromCurRow( $obj );
184 $rc->counter
= $counter++
;
185 $s .= $sk->recentChangesLine( $rc, true );
187 $s .= $sk->endRecentChangesList();
189 wfFreeResult( $res );
190 $wgOut->addHTML( $s );
192 if ( $wgUseWatchlistCache ) {
193 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
196 $wgLoadBalancer->force(0);
200 function wlHoursLink( $h, $page ) {
201 global $wgUser, $wgLang;
202 $sk = $wgUser->getSkin();
203 $s = $sk->makeKnownLink(
204 $wgLang->specialPage( $page ),
205 $wgLang->formatNum( $h ),
206 "days=" . ($h / 24.0) );
211 function wlDaysLink( $d, $page ) {
212 global $wgUser, $wgLang;
213 $sk = $wgUser->getSkin();
214 $s = $sk->makeKnownLink(
215 $wgLang->specialPage( $page ),
216 ($d ?
$wgLang->formatNum( $d ) : wfMsg( "all" ) ), "days=$d" );
220 function wlCutoffLinks( $days, $limit, $page = "Watchlist" )
222 $hours = array( 1, 2, 6, 12 );
223 $days = array( 1, 3, 7 );
226 foreach( $hours as $h ) {
227 $hours[$i++
] = wlHoursLink( $h, $page );
230 foreach( $days as $d ) {
231 $days[$i++
] = wlDaysLink( $d, $page );
233 return wfMsg ("wlshowlast",
234 implode(" | ", $hours),
235 implode(" | ", $days),
236 wlDaysLink( 0, $page ) );