2 include_once( "SpecialRecentchanges.php" );
3 include_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 );
55 $sql = "SELECT COUNT(*) AS n FROM watchlist WHERE wl_user=$uid";
56 $res = wfQuery( $sql, DB_READ
);
57 $s = wfFetchObject( $res );
61 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
65 if ( ! isset( $days ) ) {
68 # Set default cutoff shorter
69 $days = (12.0 / 24.0); # 12 hours...
71 $days = 3; # longer cutoff for shortlisters
74 $days = floatval($days);
80 $npages = wfMsg( "all" );
82 $docutoff = "AND cur_timestamp > '" .
83 ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) )
85 $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'";
86 $res = wfQuery( $sql, DB_READ
);
87 $s = wfFetchObject( $res );
91 if(isset($_REQUEST['magic'])) {
92 $wgOut->addHTML( wfMsg( "watchlistcontains", $nitems ) .
93 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
95 $wgOut->addHTML( "<form action='" .
96 $specialTitle->getURL( "action=submit", true ) .
97 "' method='post'>\n" .
99 $sql = "SELECT wl_namespace,wl_title FROM watchlist WHERE wl_user=$uid";
100 $res = wfQuery( $sql, DB_READ
);
101 global $wgUser, $wgLang;
102 $sk = $wgUser->getSkin();
103 while( $s = wfFetchObject( $res ) ) {
104 $t = Title
::makeTitle( $s->wl_namespace
, $s->wl_title
);
105 $t = $t->getPrefixedText();
106 $wgOut->addHTML( "<li><input type='checkbox' name='id[]' value=\"" . htmlspecialchars($t) . "\">" .
107 $sk->makeKnownLink( $t, $t ) .
110 $wgOut->addHTML( "</ul>\n" .
111 "<input type='submit' name='remove' value='" .
112 wfMsg( "removechecked" ) . "'>\n" .
118 # If the watchlist is relatively short, it's simplest to zip
119 # down its entirety and then sort the results.
121 # If it's relatively long, it may be worth our while to zip
122 # through the time-sorted page list checking for watched items.
124 # Up estimate of watched items by 15% to compensate for talk pages...
125 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
126 $x = "cur_timestamp";
127 $y = wfMsg( "watchmethod-recent" );
128 $z = "wl_namespace=cur_namespace&65534";
130 $x = "name_title_timestamp";
131 $y = wfMsg( "watchmethod-list" );
132 $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
136 $wgOut->addHTML( "<i>" . wfMsg( "watchdetails", $nitems, $npages, $y,
137 $specialTitle->getURL( "magic=yes", true ) ) . "</i><br>\n" );
141 cur_namespace,cur_title,cur_comment, cur_id,
142 cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new
143 FROM watchlist,cur USE INDEX ($x)
146 AND wl_title=cur_title
148 ORDER BY cur_timestamp DESC";
151 $res = wfQuery( $sql, DB_READ
, $fname );
154 $note = wfMsg( "rcnote", $limit, $days );
156 $note = wfMsg( "wlnote", $limit, round($days*24) );
159 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
160 $note = wlCutoffLinks( $days, $limit );
161 $wgOut->addHTML( "{$note}\n" );
163 if ( wfNumRows( $res ) == 0 ) {
164 $wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
168 $sk = $wgUser->getSkin();
169 $s = $sk->beginRecentChangesList();
171 while ( $obj = wfFetchObject( $res ) ) {
173 $rc = RecentChange
::newFromCurRow( $obj );
174 $s .= $sk->recentChangesLine( $rc, true );
176 $s .= $sk->endRecentChangesList();
178 wfFreeResult( $res );
179 $wgOut->addHTML( $s );
181 if ( $wgUseWatchlistCache ) {
182 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
187 function wlHoursLink( $h, $page ) {
188 global $wgUser, $wgLang;
189 $sk = $wgUser->getSkin();
190 $s = $sk->makeKnownLink(
191 $wgLang->specialPage( $page ),
192 $h, "days=" . ($h / 24.0) );
197 function wlDaysLink( $d, $page ) {
198 global $wgUser, $wgLang;
199 $sk = $wgUser->getSkin();
200 $s = $sk->makeKnownLink(
201 $wgLang->specialPage( $page ),
202 ($d ?
$d : wfMsg( "all" ) ), "days=$d" );
206 function wlCutoffLinks( $days, $limit, $page = "Watchlist" )
208 $hours = array( 1, 2, 6, 12 );
209 $days = array( 1, 3, 7 );
212 foreach( $hours as $h ) {
213 $hours[$i++
] = wlHoursLink( $h, $page );
216 foreach( $days as $d ) {
217 $days[$i++
] = wlDaysLink( $d, $page );
219 return wfMsg ("wlshowlast",
220 implode(" | ", $hours),
221 implode(" | ", $days),
222 wlDaysLink( 0, $page ) );