2 require_once( "SpecialRecentchanges.php" );
3 require_once( "WatchedItem.php" );
5 function wfSpecialWatchlist()
7 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc;
8 global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname;
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 $sql = "SELECT COUNT(*) AS n FROM watchlist WHERE wl_user=$uid";
55 $res = wfQuery( $sql, DB_READ
);
56 $s = wfFetchObject( $res );
59 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
63 if ( ! isset( $days ) ) {
66 # Set default cutoff shorter
67 $days = (12.0 / 24.0); # 12 hours...
69 $days = 3; # longer cutoff for shortlisters
72 $days = floatval($days);
78 $npages = wfMsg( "all" );
80 $docutoff = "AND cur_timestamp > '" .
81 ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) )
83 $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'";
84 $res = wfQuery( $sql, DB_READ
);
85 $s = wfFetchObject( $res );
90 if(isset($_REQUEST['magic'])) {
91 $wgOut->addHTML( wfMsg( "watchlistcontains", $wgLang->formatNum( $nitems ) ) .
92 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
94 $wgOut->addHTML( "<form action='" .
95 $specialTitle->escapeLocalUrl( "action=submit" ) .
96 "' method='post'>\n" .
98 $sql = "SELECT wl_namespace,wl_title FROM watchlist WHERE wl_user=$uid";
99 $res = wfQuery( $sql, DB_READ
);
100 global $wgUser, $wgLang;
101 $sk = $wgUser->getSkin();
102 while( $s = wfFetchObject( $res ) ) {
103 $t = Title
::makeTitle( $s->wl_namespace
, $s->wl_title
);
104 if( is_null( $t ) ) {
105 $wgOut->addHTML( '<!-- bad title "' . htmlspecialchars( $s->wl_title
) . '" in namespace ' . IntVal( $s->wl_namespace
) . " -->\n" );
107 $t = $t->getPrefixedText();
108 $wgOut->addHTML( "<li><input type='checkbox' name='id[]' value=\"" . htmlspecialchars($t) . "\" />" .
109 $sk->makeKnownLink( $t, $t ) .
113 $wgOut->addHTML( "</ul>\n" .
114 "<input type='submit' name='remove' value='" .
115 wfMsg( "removechecked" ) . "' />\n" .
121 # If the watchlist is relatively short, it's simplest to zip
122 # down its entirety and then sort the results.
124 # If it's relatively long, it may be worth our while to zip
125 # through the time-sorted page list checking for watched items.
127 # Up estimate of watched items by 15% to compensate for talk pages...
128 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
129 $x = "cur_timestamp";
130 $y = wfMsg( "watchmethod-recent" );
131 $z = "wl_namespace=cur_namespace&65534";
133 $x = "name_title_timestamp";
134 $y = wfMsg( "watchmethod-list" );
135 $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
139 $wgOut->addHTML( "<i>" . wfMsg( "watchdetails",
140 $wgLang->formatNum( $nitems ), $wgLang->formatNum( $npages ), $y,
141 $specialTitle->escapeLocalUrl( "magic=yes" ) ) . "</i><br />\n" );
143 $use_index = wfUseIndexClause( $x, DB_READ
);
145 cur_namespace,cur_title,cur_comment, cur_id,
146 cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new
147 FROM watchlist,cur $use_index
150 AND wl_title=cur_title
152 ORDER BY cur_timestamp DESC";
155 $res = wfQuery( $sql, DB_READ
, $fname );
158 $note = wfMsg( "rcnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
160 $note = wfMsg( "wlnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( round($days*24) ) );
163 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
164 $note = wlCutoffLinks( $days, $limit );
165 $wgOut->addHTML( "{$note}\n" );
167 if ( wfNumRows( $res ) == 0 ) {
168 $wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
172 $sk = $wgUser->getSkin();
173 $s = $sk->beginRecentChangesList();
175 while ( $obj = wfFetchObject( $res ) ) {
177 $rc = RecentChange
::newFromCurRow( $obj );
178 $rc->counter
= $counter++
;
179 $s .= $sk->recentChangesLine( $rc, true );
181 $s .= $sk->endRecentChangesList();
183 wfFreeResult( $res );
184 $wgOut->addHTML( $s );
186 if ( $wgUseWatchlistCache ) {
187 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
193 function wlHoursLink( $h, $page ) {
194 global $wgUser, $wgLang;
195 $sk = $wgUser->getSkin();
196 $s = $sk->makeKnownLink(
197 $wgLang->specialPage( $page ),
198 $wgLang->formatNum( $h ),
199 "days=" . ($h / 24.0) );
204 function wlDaysLink( $d, $page ) {
205 global $wgUser, $wgLang;
206 $sk = $wgUser->getSkin();
207 $s = $sk->makeKnownLink(
208 $wgLang->specialPage( $page ),
209 ($d ?
$wgLang->formatNum( $d ) : wfMsg( "all" ) ), "days=$d" );
213 function wlCutoffLinks( $days, $limit, $page = "Watchlist" )
215 $hours = array( 1, 2, 6, 12 );
216 $days = array( 1, 3, 7 );
219 foreach( $hours as $h ) {
220 $hours[$i++
] = wlHoursLink( $h, $page );
223 foreach( $days as $d ) {
224 $days[$i++
] = wlDaysLink( $d, $page );
226 return wfMsg ("wlshowlast",
227 implode(" | ", $hours),
228 implode(" | ", $days),
229 wlDaysLink( 0, $page ) );