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 $dbr =& wfGetDB( DB_SLAVE
);
55 extract( $dbr->tableNames( 'cur', 'watchlist', 'recentchanges' ) );
57 $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
58 $res = $dbr->query( $sql );
59 $s = $dbr->fetchObject( $res );
62 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
66 if ( ! isset( $days ) ) {
69 # Set default cutoff shorter
70 $days = (12.0 / 24.0); # 12 hours...
72 $days = 3; # longer cutoff for shortlisters
75 $days = floatval($days);
81 $npages = wfMsg( "all" );
83 $docutoff = "AND cur_timestamp > '" .
84 ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) )
86 $sql = "SELECT COUNT(*) AS n FROM $cur WHERE cur_timestamp>'$cutoff'";
87 $res = $dbr->query( $sql );
88 $s = $dbr->fetchObject( $res );
93 if(isset($_REQUEST['magic'])) {
94 $wgOut->addHTML( wfMsg( "watchlistcontains", $wgLang->formatNum( $nitems ) ) .
95 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
97 $wgOut->addHTML( "<form action='" .
98 $specialTitle->escapeLocalUrl( "action=submit" ) .
99 "' method='post'>\n" .
101 $sql = "SELECT wl_namespace,wl_title FROM $watchlist WHERE wl_user=$uid";
102 $res = $dbr->query( $sql );
103 global $wgUser, $wgLang;
104 $sk = $wgUser->getSkin();
105 while( $s = $dbr->fetchObject( $res ) ) {
106 $t = Title
::makeTitle( $s->wl_namespace
, $s->wl_title
);
107 if( is_null( $t ) ) {
108 $wgOut->addHTML( '<!-- bad title "' . htmlspecialchars( $s->wl_title
) . '" in namespace ' . IntVal( $s->wl_namespace
) . " -->\n" );
110 $t = $t->getPrefixedText();
111 $wgOut->addHTML( "<li><input type='checkbox' name='id[]' value=\"" . htmlspecialchars($t) . "\" />" .
112 $sk->makeKnownLink( $t, $t ) .
116 $wgOut->addHTML( "</ul>\n" .
117 "<input type='submit' name='remove' value='" .
118 wfMsg( "removechecked" ) . "' />\n" .
124 # If the watchlist is relatively short, it's simplest to zip
125 # down its entirety and then sort the results.
127 # If it's relatively long, it may be worth our while to zip
128 # through the time-sorted page list checking for watched items.
130 # Up estimate of watched items by 15% to compensate for talk pages...
131 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
132 $x = "cur_timestamp";
133 $y = wfMsg( "watchmethod-recent" );
134 $z = "wl_namespace=cur_namespace&65534";
136 $x = "name_title_timestamp";
137 $y = wfMsg( "watchmethod-list" );
138 $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
142 $wgOut->addHTML( "<i>" . wfMsg( "watchdetails",
143 $wgLang->formatNum( $nitems ), $wgLang->formatNum( $npages ), $y,
144 $specialTitle->escapeLocalUrl( "magic=yes" ) ) . "</i><br />\n" );
146 $use_index = $dbr->useIndexClause( $x );
148 cur_namespace,cur_title,cur_comment, cur_id,
149 cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new
150 FROM $watchlist,$cur $use_index
153 AND wl_title=cur_title
155 ORDER BY cur_timestamp DESC";
158 $res = $dbr->query( $sql, $fname );
161 $note = wfMsg( "rcnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
163 $note = wfMsg( "wlnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( round($days*24) ) );
166 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
167 $note = wlCutoffLinks( $days, $limit );
168 $wgOut->addHTML( "{$note}\n" );
170 if ( $dbr->numRows( $res ) == 0 ) {
171 $wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
175 $sk = $wgUser->getSkin();
176 $s = $sk->beginRecentChangesList();
178 while ( $obj = $dbr->fetchObject( $res ) ) {
180 $rc = RecentChange
::newFromCurRow( $obj );
181 $rc->counter
= $counter++
;
182 $s .= $sk->recentChangesLine( $rc, true );
184 $s .= $sk->endRecentChangesList();
186 $dbr->freeResult( $res );
187 $wgOut->addHTML( $s );
189 if ( $wgUseWatchlistCache ) {
190 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
196 function wlHoursLink( $h, $page ) {
197 global $wgUser, $wgLang;
198 $sk = $wgUser->getSkin();
199 $s = $sk->makeKnownLink(
200 $wgLang->specialPage( $page ),
201 $wgLang->formatNum( $h ),
202 "days=" . ($h / 24.0) );
207 function wlDaysLink( $d, $page ) {
208 global $wgUser, $wgLang;
209 $sk = $wgUser->getSkin();
210 $s = $sk->makeKnownLink(
211 $wgLang->specialPage( $page ),
212 ($d ?
$wgLang->formatNum( $d ) : wfMsg( "all" ) ), "days=$d" );
216 function wlCutoffLinks( $days, $limit, $page = "Watchlist" )
218 $hours = array( 1, 2, 6, 12 );
219 $days = array( 1, 3, 7 );
222 foreach( $hours as $h ) {
223 $hours[$i++
] = wlHoursLink( $h, $page );
226 foreach( $days as $d ) {
227 $days[$i++
] = wlDaysLink( $d, $page );
229 return wfMsg ("wlshowlast",
230 implode(" | ", $hours),
231 implode(" | ", $days),
232 wlDaysLink( 0, $page ) );