2 include_once( "SpecialRecentchanges.php" );
3 include_once( "WatchedItem.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 = wfMsg( "watchlistsub", $wgUser->getName() );
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 $wl = WatchedItem
::fromUserTitle( $wgUser, $t );
29 if( $wl->removeWatch() === false ) {
30 $wgOut->addHTML( "<br />\n" . wfMsg( "couldntremove", htmlspecialchars($one) ) );
32 $wgOut->addHTML( " (" . htmlspecialchars($one) . ")" );
35 $wgOut->addHTML( "<br />\n" . wfMsg( "iteminvalidname", htmlspecialchars($one) ) );
38 $wgOut->addHTML( "done.\n<p>" );
41 $sql = "SELECT COUNT(*) AS n FROM watchlist WHERE wl_user=$uid";
42 $res = wfQuery( $sql, DB_READ
);
43 $s = wfFetchObject( $res );
47 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
51 if ( ! isset( $days ) ) {
54 # Set default cutoff shorter
55 $days = (12.0 / 24.0); # 12 hours...
57 $days = 0; # no time cutoff for shortlisters
60 $days = floatval($days);
66 $npages = wfMsg( "all" );
68 $docutoff = "AND cur_timestamp > '" .
69 ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) )
71 $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'";
72 $res = wfQuery( $sql, DB_READ
);
73 $s = wfFetchObject( $res );
77 if(isset($_REQUEST['magic'])) {
78 $wgOut->addHTML( wfMsg( "watchlistcontains", $nitems ) .
79 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
81 $wgOut->addHTML( "<form action='" .
82 wfLocalUrl( $wgLang->specialPage( "Watchlist" ), "action=submit" ) .
83 "' method='post'>\n" .
85 $sql = "SELECT wl_namespace,wl_title FROM watchlist WHERE wl_user=$uid";
86 $res = wfQuery( $sql, DB_READ
);
87 global $wgUser, $wgLang;
88 $sk = $wgUser->getSkin();
89 while( $s = wfFetchObject( $res ) ) {
90 $t = Title
::makeTitle( $s->wl_namespace
, $s->wl_title
);
91 $t = $t->getPrefixedText();
92 $wgOut->addHTML( "<li><input type='checkbox' name='id[]' value=\"" . htmlspecialchars($t) . "\">" .
93 $sk->makeKnownLink( $t, $t ) .
96 $wgOut->addHTML( "</ul>\n" .
97 "<input type='submit' name='remove' value='" .
98 wfMsg( "removechecked" ) . "'>\n" .
104 # If the watchlist is relatively short, it's simplest to zip
105 # down its entirety and then sort the results.
107 # If it's relatively long, it may be worth our while to zip
108 # through the time-sorted page list checking for watched items.
110 # Up estimate of watched items by 15% to compensate for talk pages...
111 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
112 $x = "cur_timestamp";
113 $y = wfMsg( "watchmethod-recent" );
114 $z = "wl_namespace=cur_namespace&65534";
116 $x = "name_title_timestamp";
117 $y = wfMsg( "watchmethod-list" );
118 $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
121 $wgOut->addHTML( "<i>" . wfMsg( "watchdetails", $nitems, $npages, $y,
122 wfLocalUrl( $wgLang->specialPage("Watchlist"),"magic=yes" ) ) . "</i><br>\n" );
126 cur_namespace,cur_title,cur_comment,
127 cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new
128 FROM watchlist,cur USE INDEX ($x)
131 AND wl_title=cur_title
133 ORDER BY cur_timestamp DESC";
136 $res = wfQuery( $sql, DB_READ
, $fname );
139 $note = wfMsg( "rcnote", $limit, $days );
141 $note = wfMsg( "wlnote", $limit, round($days*24) );
144 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
145 $note = wlCutoffLinks( $days, $limit );
146 $wgOut->addHTML( "{$note}\n" );
148 if ( wfNumRows( $res ) == 0 ) {
149 $wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
153 $sk = $wgUser->getSkin();
154 $s = $sk->beginRecentChangesList();
156 while ( $obj = wfFetchObject( $res ) ) {
157 $ts = $obj->cur_timestamp
;
159 $ut = $obj->cur_user_text
;
160 $ns = $obj->cur_namespace
;
161 $ttl = $obj->cur_title
;
162 $com = $obj->cur_comment
;
163 $me = ( $obj->cur_minor_edit
> 0 );
164 $new = ( $obj->cur_is_new
> 0 );
167 $s .= $sk->recentChangesLine( $ts, $u, $ut, $ns, $ttl, $com, $me, $new, $watched );
169 $s .= $sk->endRecentChangesList();
171 wfFreeResult( $res );
172 $wgOut->addHTML( $s );
176 function wlHoursLink( $h, $page ) {
177 global $wgUser, $wgLang;
178 $sk = $wgUser->getSkin();
179 $s = $sk->makeKnownLink(
180 $wgLang->specialPage( $page ),
181 $h, "days=" . ($h / 24.0) );
186 function wlDaysLink( $d, $page ) {
187 global $wgUser, $wgLang;
188 $sk = $wgUser->getSkin();
189 $s = $sk->makeKnownLink(
190 $wgLang->specialPage( $page ),
191 ($d ?
$d : wfMsg( "all" ) ), "days=$d" );
195 function wlCutoffLinks( $days, $limit, $page = "Watchlist" )
197 $hours = array( 1, 2, 6, 12 );
198 $days = array( 1, 3, 7 );
201 foreach( $hours as $h ) {
202 $hours[$i++
] = wlHoursLink( $h, $page );
205 foreach( $days as $d ) {
206 $days[$i++
] = wlDaysLink( $d, $page );
208 return wfMsg ("wlshowlast",
209 implode(" | ", $hours),
210 implode(" | ", $days),
211 wlDaysLink( 0, $page ) );