Re-enable toc
[lhc/web/wiklou.git] / includes / SpecialWatchlist.php
1 <?
2 include_once( "SpecialRecentchanges.php" );
3 include_once( "WatchedItem.php" );
4
5 function wfSpecialWatchlist()
6 {
7 global $wgUser, $wgOut, $wgLang, $wgTitle;
8 global $days, $limit, $target; # From query string
9 $days = $_REQUEST["days"];
10 $limit = $_REQUEST["limit"];
11 $target = $_REQUEST["target"];
12
13 $fname = "wfSpecialWatchlist";
14
15 $wgOut->setPagetitle( wfMsg( "watchlist" ) );
16 $sub = wfMsg( "watchlistsub", $wgUser->getName() );
17 $wgOut->setSubtitle( $sub );
18 $wgOut->setRobotpolicy( "noindex,nofollow" );
19
20 $uid = $wgUser->getID();
21 if( $uid == 0 ) {
22 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
23 return;
24 }
25
26 global $action,$remove,$id;
27 if(($action == "submit") && isset($remove) && is_array($id)) {
28 $wgOut->addHTML( wfMsg( "removingchecked" ) );
29 foreach($id as $one) {
30 $t = Title::newFromURL( $one );
31 if($t->getDBkey() != "") {
32 $wl = WatchedItem::fromUserTitle( $wgUser, $t );
33 if( $wl->removeWatch() === false ) {
34 $wgOut->addHTML( "<br />\n" . wfMsg( "couldntremove", htmlspecialchars($one) ) );
35 } else {
36 $wgOut->addHTML( " (" . htmlspecialchars($one) . ")" );
37 }
38 } else {
39 $wgOut->addHTML( "<br />\n" . wfMsg( "iteminvalidname", htmlspecialchars($one) ) );
40 }
41 }
42 $wgOut->addHTML( "done.\n<p>" );
43 }
44
45 $sql = "SELECT COUNT(*) AS n FROM watchlist WHERE wl_user=$uid";
46 $res = wfQuery( $sql, DB_READ );
47 $s = wfFetchObject( $res );
48 $nitems = $s->n;
49
50 if($nitems == 0) {
51 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
52 return;
53 }
54
55 if ( ! isset( $days ) ) {
56 $big = 250;
57 if($nitems > $big) {
58 # Set default cutoff shorter
59 $days = (1.0 / 24.0); # 1 hour...
60 } else {
61 $days = 0; # no time cutoff for shortlisters
62 }
63 } else {
64 $days = floatval($days);
65 }
66
67 if ( $days <= 0 ) {
68 $docutoff = '';
69 $cutoff = false;
70 $npages = wfMsg( "all" );
71 } else {
72 $docutoff = "AND cur_timestamp > '" .
73 ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) )
74 . "'";
75 $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'";
76 $res = wfQuery( $sql, DB_READ );
77 $s = wfFetchObject( $res );
78 $npages = $s->n;
79 }
80
81 if(isset($_REQUEST['magic'])) {
82 $wgOut->addHTML( wfMsg( "watchlistcontains", $nitems ) .
83 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
84
85 $wgOut->addHTML( "<form action='" .
86 wfLocalUrl( $wgLang->specialPage( "Watchlist" ), "action=submit" ) .
87 "' method='post'>\n" .
88 "<ul>\n" );
89 $sql = "SELECT wl_namespace,wl_title FROM watchlist WHERE wl_user=$uid";
90 $res = wfQuery( $sql, DB_READ );
91 global $wgUser, $wgLang;
92 $sk = $wgUser->getSkin();
93 while( $s = wfFetchObject( $res ) ) {
94 $t = Title::makeTitle( $s->wl_namespace, $s->wl_title );
95 $t = $t->getPrefixedText();
96 $wgOut->addHTML( "<li><input type='checkbox' name='id[]' value=\"" . htmlspecialchars($t) . "\">" .
97 $sk->makeKnownLink( $t, $t ) .
98 "</li>\n" );
99 }
100 $wgOut->addHTML( "</ul>\n" .
101 "<input type='submit' name='remove' value='" .
102 wfMsg( "removechecked" ) . "'>\n" .
103 "</form>\n" );
104
105 return;
106 }
107
108 # If the watchlist is relatively short, it's simplest to zip
109 # down its entirety and then sort the results.
110
111 # If it's relatively long, it may be worth our while to zip
112 # through the time-sorted page list checking for watched items.
113
114 # Up estimate of watched items by 15% to compensate for talk pages...
115 if( $cutoff && ( $nitems*1.15 > $npages ) ) {
116 $x = "cur_timestamp";
117 $y = wfMsg( "watchmethod-recent" );
118 $z = "wl_namespace=cur_namespace&65534";
119 } else {
120 $x = "name_title_timestamp";
121 $y = wfMsg( "watchmethod-list" );
122 $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
123 }
124
125 $wgOut->addHTML( "<i>" . wfMsg( "watchdetails", $nitems, $npages, $y,
126 wfLocalUrl( $wgLang->specialPage("Watchlist"),"magic=yes" ) ) . "</i><br>\n" );
127
128
129 $sql = "SELECT
130 cur_namespace,cur_title,cur_comment,
131 cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new
132 FROM watchlist,cur USE INDEX ($x)
133 WHERE wl_user=$uid
134 AND $z
135 AND wl_title=cur_title
136 $docutoff
137 ORDER BY cur_timestamp DESC";
138
139
140 $res = wfQuery( $sql, DB_READ, $fname );
141
142 if($days >= 1)
143 $note = wfMsg( "rcnote", $limit, $days );
144 elseif($days > 0)
145 $note = wfMsg( "wlnote", $limit, round($days*24) );
146 else
147 $note = "";
148 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
149 $note = wlCutoffLinks( $days, $limit );
150 $wgOut->addHTML( "{$note}\n" );
151
152 if ( wfNumRows( $res ) == 0 ) {
153 $wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
154 return;
155 }
156
157 $sk = $wgUser->getSkin();
158 $s = $sk->beginRecentChangesList();
159
160 while ( $obj = wfFetchObject( $res ) ) {
161 $ts = $obj->cur_timestamp;
162 $u = $obj->cur_user;
163 $ut = $obj->cur_user_text;
164 $ns = $obj->cur_namespace;
165 $ttl = $obj->cur_title;
166 $com = $obj->cur_comment;
167 $me = ( $obj->cur_minor_edit > 0 );
168 $new = ( $obj->cur_is_new > 0 );
169 $watched = true;
170
171 $s .= $sk->recentChangesLine( $ts, $u, $ut, $ns, $ttl, $com, $me, $new, $watched );
172 }
173 $s .= $sk->endRecentChangesList();
174
175 wfFreeResult( $res );
176 $wgOut->addHTML( $s );
177 }
178
179
180 function wlHoursLink( $h, $page ) {
181 global $wgUser, $wgLang;
182 $sk = $wgUser->getSkin();
183 $s = $sk->makeKnownLink(
184 $wgLang->specialPage( $page ),
185 $h, "days=" . ($h / 24.0) );
186 return $s;
187 }
188
189
190 function wlDaysLink( $d, $page ) {
191 global $wgUser, $wgLang;
192 $sk = $wgUser->getSkin();
193 $s = $sk->makeKnownLink(
194 $wgLang->specialPage( $page ),
195 ($d ? $d : wfMsg( "all" ) ), "days=$d" );
196 return $s;
197 }
198
199 function wlCutoffLinks( $days, $limit, $page = "Watchlist" )
200 {
201 $hours = array( 1, 2, 6, 12 );
202 $days = array( 1, 3, 7 );
203 $cl = "";
204 $i = 0;
205 foreach( $hours as $h ) {
206 $hours[$i++] = wlHoursLink( $h, $page );
207 }
208 $i = 0;
209 foreach( $days as $d ) {
210 $days[$i++] = wlDaysLink( $d, $page );
211 }
212 return wfMsg ("wlshowlast",
213 implode(" | ", $hours),
214 implode(" | ", $days),
215 wlDaysLink( 0, $page ) );
216 }
217
218 ?>