Added translation phrases in wlCutoffLinks().
[lhc/web/wiklou.git] / includes / SpecialWatchlist.php
1 <?
2 global $IP;
3 include_once( "$IP/SpecialRecentchanges.php" );
4
5 function wfSpecialWatchlist()
6 {
7 global $wgUser, $wgOut, $wgLang, $wgTitle;
8 global $days, $limit, $target; # From query string
9 $fname = "wfSpecialWatchlist";
10
11 $wgOut->setPagetitle( wfMsg( "watchlist" ) );
12 $sub = str_replace( "$1", $wgUser->getName(), wfMsg( "watchlistsub" ) );
13 $wgOut->setSubtitle( $sub );
14 $wgOut->setRobotpolicy( "noindex,nofollow" );
15
16 $uid = $wgUser->getID();
17 if( $uid == 0 ) {
18 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
19 return;
20 }
21
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 );
32 if($res === FALSE) {
33 $wgOut->addHTML( "<br />\n" . wfMsg( "couldntremove", htmlspecialchars($one) ) );
34 } else {
35 $wgOut->addHTML( " (" . htmlspecialchars($one) . ")" );
36 }
37 } else {
38 $wgOut->addHTML( "<br />\n" . wfMsg( "iteminvalidname", htmlspecialchars($one) ) );
39 }
40 }
41 $wgOut->addHTML( "done.\n<p>" );
42 }
43
44 $sql = "SELECT COUNT(*) AS n FROM watchlist WHERE wl_user=$uid";
45 $res = wfQuery( $sql );
46 $s = wfFetchObject( $res );
47 $nitems = $s->n;
48
49 if($nitems == 0) {
50 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
51 return;
52 }
53
54 if ( ! isset( $days ) ) {
55 $big = 250;
56 if($nitems > $big) {
57 # Set default cutoff shorter
58 $days = (1.0 / 24.0); # 1 hour...
59 } else {
60 $days = 0; # no time cutoff for shortlisters
61 }
62 } else {
63 $days = floatval($days);
64 }
65
66 if ( $days <= 0 ) {
67 $docutoff = '';
68 $cutoff = false;
69 $npages = wfMsg( "all" );
70 } else {
71 $docutoff = "AND cur_timestamp > '" .
72 ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) )
73 . "'";
74 $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'";
75 $res = wfQuery( $sql );
76 $s = wfFetchObject( $res );
77 $npages = $s->n;
78 }
79
80 if(isset($_REQUEST['magic'])) {
81 $wgOut->addHTML( wfMsg( "watchlistcontains", $nitems ) .
82 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
83
84 $wgOut->addHTML( "<form action='" .
85 wfLocalUrl( $wgLang->specialPage( "Watchlist" ), "action=submit" ) .
86 "' method='post'>\n" .
87 "<ul>\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 ) .
97 "</li>\n" );
98 }
99 $wgOut->addHTML( "</ul>\n" .
100 "<input type='submit' name='remove' value='" .
101 wfMsg( "removechecked" ) . "'>\n" .
102 "</form>\n" );
103
104 return;
105 }
106
107 # If the watchlist is relatively short, it's simplest to zip
108 # down its entirety and then sort the results.
109
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.
112
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";
118 } else {
119 $x = "name_title_timestamp";
120 $y = wfMsg( "watchmethod-list" );
121 $z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
122 }
123
124 $wgOut->addHTML( "<i>" . wfMsg( "watchdetails", $nitems, $npages, $y,
125 wfLocalUrl( $wgLang->specialPage("Watchlist"),"magic=yes" ) ) . "</i><br>\n" );
126
127
128 $sql = "SELECT
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)
132 WHERE wl_user=$uid
133 AND $z
134 AND wl_title=cur_title
135 $docutoff
136 ORDER BY cur_timestamp DESC";
137
138
139 $res = wfQuery( $sql, $fname );
140
141 if($days >= 1)
142 $note = wfMsg( "rcnote", $limit, $days );
143 elseif($days > 0)
144 $note = wfMsg( "wlnote", $limit, round($days*24) );
145 else
146 $note = "";
147 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
148 $note = wlCutoffLinks( $days, $limit );
149 $wgOut->addHTML( "{$note}\n" );
150
151 if ( wfNumRows( $res ) == 0 ) {
152 $wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
153 return;
154 }
155
156 $sk = $wgUser->getSkin();
157 $s = $sk->beginRecentChangesList();
158
159 while ( $obj = wfFetchObject( $res ) ) {
160 $ts = $obj->cur_timestamp;
161 $u = $obj->cur_user;
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 );
168 $watched = true;
169
170 $s .= $sk->recentChangesLine( $ts, $u, $ut, $ns, $ttl, $com, $me, $new, $watched );
171 }
172 $s .= $sk->endRecentChangesList();
173
174 wfFreeResult( $res );
175 $wgOut->addHTML( $s );
176 }
177
178
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) );
185 return $s;
186 }
187
188
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" );
195 return $s;
196 }
197
198 function wlCutoffLinks( $days, $limit, $page = "Watchlist" )
199 {
200 $hours = array( 1, 2, 6, 12 );
201 $days = array( 1, 3, 7 );
202 $cl = "";
203 $i = 0;
204 foreach( $hours as $h ) {
205 $hours[$i++] = wlHoursLink( $h, $page );
206 }
207 $i = 0;
208 foreach( $days as $d ) {
209 $days[$i++] = wlDaysLink( $d, $page );
210 }
211 return
212 wfMsg ("wlshowlast") .
213 implode(" | ", $hours) . wfMsg("wlhours") .
214 implode(" | ", $days) . wfMsg("wldays") .
215 wlDaysLink( 0, $page );
216 # $note = wfMsg( "rclinks", $cl, $dl, $mlink );
217 }
218
219 ?>