3 include_once( "$IP/SpecialRecentchanges.php" );
5 function wfSpecialWatchlist()
7 global $wgUser, $wgOut, $wgLang, $wgTitle;
8 global $days, $limit, $target; # From query string
9 $fname = "wfSpecialWatchlist";
11 $wgOut->setPagetitle( wfMsg( "watchlist" ) );
12 $sub = str_replace( "$1", $wgUser->getName(), wfMsg( "watchlistsub" ) );
13 $wgOut->setSubtitle( $sub );
14 $wgOut->setRobotpolicy( "noindex,nofollow" );
16 $uid = $wgUser->getID();
18 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
22 global $action,$remove,$id;
23 if(($action == "submit") && isset($remove) && is_array($id)) {
24 $wgOut->addHTML( wfMsg( "removingchecked" ) );
25 foreach($id as $one) {
26 $t = Title
::newFromURL( $one );
27 if($t->getDBkey() != "") {
28 $sql = "DELETE FROM watchlist WHERE wl_user=$uid AND " .
29 "wl_namespace=" . $t->getNamespace() . " AND " .
30 "wl_title='" . wfStrencode( $t->getDBkey() ) . "'";
31 $res = wfQuery( $sql );
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 $sql = "SELECT COUNT(*) AS n FROM watchlist WHERE wl_user=$uid";
45 $res = wfQuery( $sql );
46 $s = wfFetchObject( $res );
50 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
54 if ( ! isset( $days ) ) {
57 # Set default cutoff shorter
58 $days = (1.0 / 24.0); # 1 hour...
60 $days = 0; # no time cutoff for shortlisters
63 $days = floatval($days);
69 $npages = wfMsg( "all" );
71 $docutoff = "AND cur_timestamp > '" .
72 ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) )
74 $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'";
75 $res = wfQuery( $sql );
76 $s = wfFetchObject( $res );
80 if(isset($_REQUEST['magic'])) {
81 $wgOut->addHTML( wfMsg( "watchlistcontains", $nitems ) .
82 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
84 $wgOut->addHTML( "<form action='" .
85 wfLocalUrl( $wgLang->specialPage( "Watchlist" ), "action=submit" ) .
86 "' method='post'>\n" .
88 $sql = "SELECT wl_namespace,wl_title FROM watchlist WHERE wl_user=$uid";
89 $res = wfQuery( $sql );
90 global $wgUser, $wgLang;
91 $sk = $wgUser->getSkin();
92 while( $s = wfFetchObject( $res ) ) {
93 $t = Title
::makeTitle( $s->wl_namespace
, $s->wl_title
);
94 $t = $t->getPrefixedText();
95 $wgOut->addHTML( "<li><input type='checkbox' name='id[]' value=\"" . htmlspecialchars($t) . "\">" .
96 $sk->makeKnownLink( $t, $t ) .
99 $wgOut->addHTML( "</ul>\n" .
100 "<input type='submit' name='remove' value='" .
101 wfMsg( "removechecked" ) . "'>\n" .
107 # If the watchlist is relatively short, it's simplest to zip
108 # down its entirety and then sort the results.
110 # If it's relatively long, it may be worth our while to zip
111 # through the time-sorted page list checking for watched items.
113 # Up estimate of watched items by 15% to compensate for talk pages...
114 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
115 $x = "cur_timestamp";
116 $y = wfMsg( "watchmethod-recent" );
117 $z = "wl_namespace=cur_namespace&65534";
119 $x = "name_title_timestamp";
120 $y = wfMsg( "watchmethod-list" );
121 $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
124 $wgOut->addHTML( "<i>" . wfMsg( "watchdetails", $nitems, $npages, $y,
125 wfLocalUrl( $wgLang->specialPage("Watchlist"),"magic=yes" ) ) . "</i><br>\n" );
129 cur_namespace,cur_title,cur_comment,
130 cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new
131 FROM watchlist,cur USE INDEX ($x)
134 AND wl_title=cur_title
136 ORDER BY cur_timestamp DESC";
139 $res = wfQuery( $sql, $fname );
142 $note = wfMsg( "rcnote", $limit, $days );
144 $note = wfMsg( "wlnote", $limit, round($days*24) );
147 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
148 $note = wlCutoffLinks( $days, $limit );
149 $wgOut->addHTML( "{$note}\n" );
151 if ( wfNumRows( $res ) == 0 ) {
152 $wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
156 $sk = $wgUser->getSkin();
157 $s = $sk->beginRecentChangesList();
159 while ( $obj = wfFetchObject( $res ) ) {
160 $ts = $obj->cur_timestamp
;
162 $ut = $obj->cur_user_text
;
163 $ns = $obj->cur_namespace
;
164 $ttl = $obj->cur_title
;
165 $com = $obj->cur_comment
;
166 $me = ( $obj->cur_minor_edit
> 0 );
167 $new = ( $obj->cur_is_new
> 0 );
170 $s .= $sk->recentChangesLine( $ts, $u, $ut, $ns, $ttl, $com, $me, $new, $watched );
172 $s .= $sk->endRecentChangesList();
174 wfFreeResult( $res );
175 $wgOut->addHTML( $s );
179 function wlHoursLink( $h, $page ) {
180 global $wgUser, $wgLang;
181 $sk = $wgUser->getSkin();
182 $s = $sk->makeKnownLink(
183 $wgLang->specialPage( $page ),
184 $h, "days=" . ($h / 24.0) );
189 function wlDaysLink( $d, $page ) {
190 global $wgUser, $wgLang;
191 $sk = $wgUser->getSkin();
192 $s = $sk->makeKnownLink(
193 $wgLang->specialPage( $page ),
194 ($d ?
$d : wfMsg( "all" ) ), "days=$d" );
198 function wlCutoffLinks( $days, $limit, $page = "Watchlist" )
200 $hours = array( 1, 2, 6, 12 );
201 $days = array( 1, 3, 7 );
204 foreach( $hours as $h ) {
205 $hours[$i++
] = wlHoursLink( $h, $page );
208 foreach( $days as $d ) {
209 $days[$i++
] = wlDaysLink( $d, $page );
213 implode(" | ", $hours) . " hours " .
214 implode(" | ", $days) . " days " .
215 wlDaysLink( 0, $page );
216 # $note = wfMsg( "rclinks", $cl, $dl, $mlink );