From 956dd867145d2bb94b2798efb119504ba097a02b Mon Sep 17 00:00:00 2001 From: Abbe98 Date: Sun, 23 Jan 2022 13:41:23 +0100 Subject: [PATCH] bump wiki.java to resolve http upload error --- src/org/wikipedia/Wiki.java | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/org/wikipedia/Wiki.java b/src/org/wikipedia/Wiki.java index 65fea8c..6b864b8 100644 --- a/src/org/wikipedia/Wiki.java +++ b/src/org/wikipedia/Wiki.java @@ -1349,6 +1349,24 @@ public Map getSiteStatistics() throws IOException ret.put("jobs", Integer.parseInt(parseAttribute(text, "jobs", 0))); // job queue length return ret; } + + /** + * Require the given extension be installed on this wiki, or throw an + * UnsupportedOperationException if it isn't. + * @param extension the name of the extension to check + * @throws UnsupportedOperationException if that extension is not + * installed on this wiki + * @throws UncheckedIOException if the site info cache is not populated + * and a network error occurs when populating it + * @since 0.37 + */ + public void requiresExtension(String extension) + { + if (!installedExtensions().contains(extension)) + throw new UnsupportedOperationException("Extension \"" + extension + + "\" is not installed on " + getDomain() + ". " + + "Please check the extension name and [[Special:Version]]."); + } /** * Renders the specified wiki markup as HTML by passing it to the MediaWiki @@ -8110,7 +8128,7 @@ public String makeApiCall(Map getparams, Map pos boolean isPOST = (postparams != null && !postparams.isEmpty()); StringBuilder stringPostBody = new StringBuilder(); boolean multipart = false; - ArrayList multipartPostBody = new ArrayList<>(); + ByteArrayOutputStream multipartPostBody = new ByteArrayOutputStream(); String boundary = "----------NEXT PART----------"; if (isPOST) { @@ -8132,18 +8150,18 @@ public String makeApiCall(Map getparams, Map pos for (Map.Entry entry : postparams.entrySet()) { Object value = entry.getValue(); - multipartPostBody.add((nextpart + entry.getKey() + "\"").getBytes(StandardCharsets.UTF_8)); + multipartPostBody.write((nextpart + entry.getKey() + "\"").getBytes(StandardCharsets.UTF_8)); if (value instanceof String) - multipartPostBody.add(("Content-Type: text/plain; charset=UTF-8\r\n\r\n" + (String)value + "\r\n") + multipartPostBody.write(("Content-Type: text/plain; charset=UTF-8\r\n\r\n" + (String)value + "\r\n") .getBytes(StandardCharsets.UTF_8)); else if (value instanceof byte[]) { - multipartPostBody.add("Content-Type: application/octet-stream\r\n\r\n".getBytes(StandardCharsets.UTF_8)); - multipartPostBody.add((byte[])value); - multipartPostBody.add("\r\n".getBytes(StandardCharsets.UTF_8)); + multipartPostBody.write("Content-Type: application/octet-stream\r\n\r\n".getBytes(StandardCharsets.UTF_8)); + multipartPostBody.write((byte[])value); + multipartPostBody.write("\r\n".getBytes(StandardCharsets.UTF_8)); } } - multipartPostBody.add((boundary + "--\r\n").getBytes(StandardCharsets.UTF_8)); + multipartPostBody.write((boundary + "--\r\n").getBytes(StandardCharsets.UTF_8)); } else { @@ -8171,7 +8189,7 @@ else if (value instanceof byte[]) if (isPOST) { if (multipart) - connection = connection.POST(HttpRequest.BodyPublishers.ofByteArrays(multipartPostBody)) + connection = connection.POST(HttpRequest.BodyPublishers.ofByteArray(multipartPostBody.toByteArray())) .header("Content-Type", "multipart/form-data; boundary=" + boundary); else connection = connection.POST(HttpRequest.BodyPublishers.ofString(stringPostBody.toString()))