5 * @subpackage SpecialPage
11 require_once( "SpecialRecentchanges.php" );
12 require_once( "WatchedItem.php" );
17 function wfSpecialWatchlist() {
18 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgRequest;
19 global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname;
20 $fname = "wfSpecialWatchlist";
22 $wgOut->setPagetitle( wfMsg( "watchlist" ) );
23 $sub = wfMsg( "watchlistsub", $wgUser->getName() );
24 $wgOut->setSubtitle( $sub );
25 $wgOut->setRobotpolicy( "noindex,nofollow" );
27 $specialTitle = Title
::makeTitle( NS_SPECIAL
, "Watchlist" );
29 $uid = $wgUser->getID();
31 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
36 $days = $wgRequest->getVal( 'days' );
37 $action = $wgRequest->getVal( 'action' );
38 $remove = $wgRequest->getVal( 'remove' );
39 $id = $wgRequest->getVal( 'id' );
41 if(($action == "submit") && isset($remove) && is_array($id)) {
42 $wgOut->addHTML( wfMsg( "removingchecked" ) );
43 foreach($id as $one) {
44 $t = Title
::newFromURL( $one );
45 if($t->getDBkey() != "") {
46 $wl = WatchedItem
::fromUserTitle( $wgUser, $t );
47 if( $wl->removeWatch() === false ) {
48 $wgOut->addHTML( "<br />\n" . wfMsg( "couldntremove", htmlspecialchars($one) ) );
50 $wgOut->addHTML( " (" . htmlspecialchars($one) . ")" );
53 $wgOut->addHTML( "<br />\n" . wfMsg( "iteminvalidname", htmlspecialchars($one) ) );
56 $wgOut->addHTML( "done.\n<p>" );
59 if ( $wgUseWatchlistCache ) {
60 $memckey = "$wgDBname:watchlist:id:" . $wgUser->getId();
61 $cache_s = @$wgMemc->get( $memckey );
63 $wgOut->addHTML( wfMsg("wlsaved") );
64 $wgOut->addHTML( $cache_s );
69 $dbr =& wfGetDB( DB_SLAVE
);
70 extract( $dbr->tableNames( 'cur', 'watchlist', 'recentchanges' ) );
72 $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
73 $res = $dbr->query( $sql );
74 $s = $dbr->fetchObject( $res );
77 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
81 if ( is_null( $days ) ) {
84 # Set default cutoff shorter
85 $days = (12.0 / 24.0); # 12 hours...
87 $days = 3; # longer cutoff for shortlisters
90 $days = floatval($days);
96 $npages = wfMsg( "all" );
98 $docutoff = "AND cur_timestamp > '" .
99 ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
101 $sql = "SELECT COUNT(*) AS n FROM $cur WHERE cur_timestamp>'$cutoff'";
102 $res = $dbr->query( $sql );
103 $s = $dbr->fetchObject( $res );
108 if(isset($_REQUEST['magic'])) {
109 $wgOut->addHTML( wfMsg( "watchlistcontains", $wgLang->formatNum( $nitems ) ) .
110 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
112 $wgOut->addHTML( "<form action='" .
113 $specialTitle->escapeLocalUrl( "action=submit" ) .
114 "' method='post'>\n" .
116 $sql = "SELECT wl_namespace,wl_title FROM $watchlist WHERE wl_user=$uid";
117 $res = $dbr->query( $sql );
118 $sk = $wgUser->getSkin();
119 while( $s = $dbr->fetchObject( $res ) ) {
120 $t = Title
::makeTitle( $s->wl_namespace
, $s->wl_title
);
121 if( is_null( $t ) ) {
122 $wgOut->addHTML( '<!-- bad title "' . htmlspecialchars( $s->wl_title
) . '" in namespace ' . IntVal( $s->wl_namespace
) . " -->\n" );
124 $t = $t->getPrefixedText();
125 $wgOut->addHTML( "<li><input type='checkbox' name='id[]' value=\"" . htmlspecialchars($t) . "\" />" .
126 $sk->makeLink( $t, $t ) .
130 $wgOut->addHTML( "</ul>\n" .
131 "<input type='submit' name='remove' value=\"" .
132 htmlspecialchars( wfMsg( "removechecked" ) ) . "\" />\n" .
138 # If the watchlist is relatively short, it's simplest to zip
139 # down its entirety and then sort the results.
141 # If it's relatively long, it may be worth our while to zip
142 # through the time-sorted page list checking for watched items.
144 # Up estimate of watched items by 15% to compensate for talk pages...
145 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
146 $x = "cur_timestamp";
147 $y = wfMsg( "watchmethod-recent" );
148 $z = "wl_namespace=cur_namespace&65534";
150 $x = "name_title_timestamp";
151 $y = wfMsg( "watchmethod-list" );
152 $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
156 $wgOut->addHTML( "<i>" . wfMsg( "watchdetails",
157 $wgLang->formatNum( $nitems ), $wgLang->formatNum( $npages ), $y,
158 $specialTitle->escapeLocalUrl( "magic=yes" ) ) . "</i><br />\n" );
160 $use_index = $dbr->useIndexClause( $x );
162 cur_namespace,cur_title,cur_comment, cur_id,
163 cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new
164 FROM $watchlist,$cur $use_index
167 AND wl_title=cur_title
169 ORDER BY cur_timestamp DESC";
172 $res = $dbr->query( $sql, $fname );
173 $numRows = $dbr->numRows( $res );
175 $note = wfMsg( "rcnote", $wgLang->formatNum( $numRows ), $wgLang->formatNum( $days ) );
177 $note = wfMsg( "wlnote", $wgLang->formatNum( $numRows ), $wgLang->formatNum( round($days*24) ) );
180 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
181 $note = wlCutoffLinks( $days );
182 $wgOut->addHTML( "{$note}\n" );
184 if ( $numRows == 0 ) {
185 $wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
189 $sk = $wgUser->getSkin();
190 $s = $sk->beginRecentChangesList();
192 while ( $obj = $dbr->fetchObject( $res ) ) {
194 $rc = RecentChange
::newFromCurRow( $obj );
195 $rc->counter
= $counter++
;
196 $s .= $sk->recentChangesLine( $rc, true );
198 $s .= $sk->endRecentChangesList();
200 $dbr->freeResult( $res );
201 $wgOut->addHTML( $s );
203 if ( $wgUseWatchlistCache ) {
204 $wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
210 function wlHoursLink( $h, $page ) {
211 global $wgUser, $wgLang, $wgContLang;
212 $sk = $wgUser->getSkin();
213 $s = $sk->makeKnownLink(
214 $wgContLang->specialPage( $page ),
215 $wgLang->formatNum( $h ),
216 "days=" . ($h / 24.0) );
221 function wlDaysLink( $d, $page ) {
222 global $wgUser, $wgLang, $wgContLang;
223 $sk = $wgUser->getSkin();
224 $s = $sk->makeKnownLink(
225 $wgContLang->specialPage( $page ),
226 ($d ?
$wgLang->formatNum( $d ) : wfMsg( "all" ) ), "days=$d" );
230 function wlCutoffLinks( $days, $page = "Watchlist" )
232 $hours = array( 1, 2, 6, 12 );
233 $days = array( 1, 3, 7 );
236 foreach( $hours as $h ) {
237 $hours[$i++
] = wlHoursLink( $h, $page );
240 foreach( $days as $d ) {
241 $days[$i++
] = wlDaysLink( $d, $page );
243 return wfMsg ("wlshowlast",
244 implode(" | ", $hours),
245 implode(" | ", $days),
246 wlDaysLink( 0, $page ) );