-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathuserwatchlist.jsp
192 lines (174 loc) · 6.01 KB
/
userwatchlist.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!--
@(#)userwatchlist.jsp 0.02 31/08/2017
Copyright (C) 2015 - 20xx MER-C
This is free software: you are free to change and redistribute it under the
Affero GNU GPL version 3 or later, see <https://www.gnu.org/licenses/agpl.html>
for details. There is NO WARRANTY, to the extent permitted by law.
-->
<%@ include file="security.jspf" %>
<%
request.setAttribute("toolname", "User watchlist");
request.setAttribute("earliest_default", LocalDate.now(ZoneOffset.UTC).minusDays(30));
String inputpage = request.getParameter("page");
String inputpage_url = "";
String inputpage_attribute = "";
if (inputpage != null)
{
inputpage_url = ServletUtils.sanitizeForURL(inputpage);
inputpage_attribute = ServletUtils.sanitizeForAttribute(inputpage);
}
String temp = request.getParameter("skip");
int skip = (temp == null) ? 0 : Integer.parseInt(temp);
skip = Math.max(skip, 0);
boolean newonly = (request.getParameter("newonly") != null);
Wiki enWiki = sessions.sharedSession("en.wikipedia.org");
enWiki.setQueryLimit(30000); // 60 network requests
Users userUtils = Users.of(enWiki);
Revisions revisionUtils = Revisions.of(enWiki);
Pages pageUtils = Pages.of(enWiki);
%>
<%@ include file="datevalidate.jspf" %>
<%@ include file="header.jspf" %>
<p>
This tool retrieves contributions of a list of users. There is a limit of 50
users per request, though the list may be of indefinite length.
<p>
Syntax: one user per line, reason after # . Example:
<pre>
Example user # Copyright violations
// This is a comment
Someone # Spam
</pre>
<form action="./userwatchlist.jsp" method=GET>
<table>
<tr>
<td>Input page or category:
<td>
<input type=text size=50 name=page required value="<%= inputpage_attribute %>">
<%
if (inputpage != null)
{
out.print("(" + pageUtils.generatePageLink(inputpage, "visit") + " · ");
%>
<a href="<%= enWiki.getIndexPhpUrl() + "?action=edit&title=" + inputpage_url %>">edit</a>)
<%
}
%>
<tr><td>Show changes from:
<td><input type=date name=earliest value="<%= earliest %>"> to
<input type=date name=latest value="<%= latest %>"> (inclusive)
<tr><td>Show:
<td><input type=checkbox name=newonly id="newonly" value=1<%= newonly ? " checked" :
"" %>>
<label for="newonly">New pages only</label>
<tr><td>Skip:
<td><input type=number size=50 name=skip value="<%= skip %>">
</table>
<input type=submit value="Submit">
</form>
<%
if (inputpage == null)
{
%>
<%@ include file="footer.jspf" %>
<%
}
Map<String, String> input = new LinkedHashMap<>();
if (enWiki.namespace(inputpage) == Wiki.CATEGORY_NAMESPACE)
{
List<String> catmembers = enWiki.getCategoryMembers(inputpage);
for (String member : catmembers)
input.put(enWiki.removeNamespace(member), "");
}
else if (inputpage.matches("^User:.+/.+\\.(cs|j)s$"))
{
String us = inputpage.substring(5, inputpage.indexOf('/'));
Wiki.User us2 = enWiki.getUsers(List.of(us)).get(0);
if (us2 == null || !us2.isA("sysop"))
{
request.setAttribute("error", "TESTING WOOP WOOP WOOP!");
%>
<%@ include file="footer.jspf" %>
<%
}
String text = enWiki.getPageText(List.of(inputpage)).get(0);
if (text == null)
{
request.setAttribute("error", "ERROR: page "" + ServletUtils.sanitizeForHTML(inputpage) + "" does not exist!");
%>
<%@ include file="footer.jspf" %>
<%
}
// parse input
String[] lines = text.split("\n");
for (String user : lines)
{
// remove comments, parse reasons
user = user.trim();
if (user.contains("//"))
user = user.substring(0, user.indexOf("//")).trim();
int boundary = user.indexOf("#");
String reason = "";
if (boundary >= 0)
{
reason = user.substring(boundary + 1).trim();
user = user.substring(0, boundary).trim();
}
if (user.isEmpty())
continue;
input.put(user, reason);
}
}
else
{
request.setAttribute("error", "TESTING WOOP WOOP WOOP!");
%>
<%@ include file="footer.jspf" %>
<%
}
if (input.isEmpty())
{
request.setAttribute("error", "ERROR: no users found!");
%>
<%@ include file="footer.jspf" %>
<%
}
// top pagination
String requesturl = "./userwatchlist.jsp?page=" + inputpage_url + "&earliest=" + earliest
+ "&latest=" + latest + "&skip=";
out.println("<hr>");
out.println(ServletUtils.generatePagination(requesturl, skip, 50, input.size()));
// fetch contributions
Wiki.RequestHelper rh = enWiki.new RequestHelper()
.withinDateRange(earliest_odt, latest_odt);
if (newonly)
rh = rh.filterBy(Map.of("new", Boolean.TRUE));
List<String> users = new ArrayList<>(input.keySet());
List<String> userstofetch = users.subList(skip, Math.min(skip + 50, users.size()));
List<List<Wiki.Revision>> contribs = enWiki.contribs(userstofetch, null, rh);
for (int i = 0; i < userstofetch.size(); i++)
{
String user = userstofetch.get(i);
String reason = ServletUtils.sanitizeForHTML(input.get(user));
// user links
%>
<h3><%= user %></h3>
<p>
<ul>
<li>
<%
out.println(userUtils.generateHTMLSummaryLinks(user));
if (!reason.isEmpty())
out.println("<li><i>" + reason + "</i>");
out.println("</ul>");
// write contribs
List<Wiki.Revision> usercontribs = contribs.get(i);
if (usercontribs.isEmpty())
out.println("<p>No contributions within date range or user does not exist.");
else
out.println(revisionUtils.toHTML(usercontribs));
}
// end pagination
out.println(ServletUtils.generatePagination(requesturl, skip, 50, input.size()));
%>
<%@ include file="footer.jspf" %>