Skip to content

Commit e9b48d3

Browse files
authored
Merge pull request #47 from Choco31415/development
Fixes README, #45, #46.
2 parents 3d793c3 + bd57daa commit e9b48d3

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

README.md

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ To set up JavaMediawikiBot for an IDE, run `./gradlew eclipse` or `./gradlew ide
1010

1111
### Making a Wiki Family
1212

13-
A wiki family is a group of wikis that a bot can see and edit. It also
14-
contains information pertinent to the wikis.
13+
A wiki family is a group of wikis that a bot knows about, and hence can edit. It also stores wiki specific information.
1514

1615
To make a new wiki family, simply run `src/WikiBot/MediawikiData/FamilyGenerator.java`.
1716
This can be done via your IDE (console required), or through the command line:
@@ -33,22 +32,29 @@ these two classes:
3332

3433
When extending a class, the constructor must include either:
3534

36-
`
37-
super(String family, String homeWikiLanguage)
38-
super(File family, String homeWikiLanguage)
39-
`
35+
`super(String family, String homeWikiLanguage)`
4036

41-
`family` specifies a wiki family file. A bot may then access the wikis in the family file. A String `family` refers to a default included wiki family, and must be "Scratch", "DwarfFortress", or "Wikipedia". A File `family` simply must point to a wiki family file.
37+
`super(File family, String homeWikiLanguage)`
38+
39+
`family` specifies a wiki family file. A bot may then access the wikis in the family file. A String `family` refers to a default included wiki family, and must be "Scratch", "DwarfFortress", or "Wikipedia". A File `family` must point to a local wiki family file.
4240

4341
`homeWikiLanguage` specifies the default wiki of a bot.
4442

4543
### Coding the bot.
4644

47-
Half of the API commands are recommended used raw, half are not. This can be checked in the command's class documentation.
45+
JavaMediawikiBot offers two ways to accomplish what you want.
46+
47+
GenericBot methods are abstractions of the Mediawiki API, and are mostly for querying data.
48+
49+
APIcommand classes are also abstractions to the Mediawiki API, and are meant to be used as
50+
Objects. For example:
4851

49-
If a command is recommended used raw, then simply run `APIcommand(APIcommand command)`.
52+
```
53+
APIcommand command = new AppendText(loc, "\n[[de:Scratch Katze]]", "This page needs an interwiki. ^.^ ");
54+
proposeEdit(command);
55+
```
5056

51-
If a command is not recommended user raw, then use GenericBot methods.
57+
Half of the API commands are recommended used raw, half are not. This can be checked in the command's class documentation. If not recommended used raw, use GenericBot methods instead.
5258

5359
### Tips
5460

@@ -77,18 +83,4 @@ Useful bot methods and bot settings may be found in various places.
7783

7884
`src/WikiBot/core/NetworkingBase.java`
7985

80-
* For logger methods.
81-
82-
JavaMediawikiBot uses several classes to store data. A few classes that store general information include:
83-
84-
`src/WikiBot/ContentRep/Revision.java`
85-
86-
* This class stores information on page revisions.
87-
88-
`src/WikiBot/ContentRep/ImageInfo.java`
89-
90-
* This class stores information on images. This might or might not include: direct url, dimension, size, ect...
91-
92-
`src/WikiBot/ContentRep/PageLocation.java`
93-
94-
* This class stores information on how to find a page. Spefically, it contains the page title and wiki.
86+
* For logging + networking methods.

src/main/java/WikiBot/Core/GenericBot.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public SimplePage getWikiSimplePage(PageLocation loc) {
164164
public boolean doesPageExist(PageLocation loc) {
165165
JsonNode serverOutput = getWikiPageJsonCode(loc);
166166

167-
return !serverOutput.has("missing");
167+
return serverOutput.findValue("missing") == null; // If contains missing tag, the page is missing.
168168
}
169169

170170
private JsonNode getWikiPageJsonCode(PageLocation loc) {
@@ -1696,7 +1696,7 @@ private String APIcommandPOST(APIcommand command) {
16961696
//Send the command!
16971697
response = getPOST(baseURL + "/api.php?", keys, values);
16981698
try {
1699-
String serverOutput = EntityUtils.toString(response);
1699+
String serverOutput = removeBOM(EntityUtils.toString(response));
17001700

17011701
return serverOutput;
17021702
} catch (org.apache.http.ParseException | IOException e) {
@@ -1726,7 +1726,7 @@ private String APIcommandHttpEntity(APIcommand command) {
17261726
HttpEntity response = getPOST(url, entity);
17271727

17281728
try {
1729-
String serverOutput = EntityUtils.toString(response);
1729+
String serverOutput = removeBOM(EntityUtils.toString(response));
17301730

17311731
return serverOutput;
17321732
} catch (org.apache.http.ParseException | IOException e) {
@@ -1786,7 +1786,7 @@ protected String getToken(APIcommand command) {
17861786

17871787
String token = "";
17881788
try {
1789-
String serverOutput = EntityUtils.toString(entity);
1789+
String serverOutput = removeBOM(EntityUtils.toString(entity));
17901790

17911791
logFinest("Received token response: " + serverOutput);
17921792

src/main/java/WikiBot/Core/NetworkingBase.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import javax.net.ssl.SSLHandshakeException;
2222

23+
import org.apache.http.Header;
2324
import org.apache.http.HttpEntity;
2425
import org.apache.http.HttpResponse;
2526
import org.apache.http.NameValuePair;
@@ -61,6 +62,9 @@ public class NetworkingBase extends javax.swing.JPanel {
6162
private HttpClient httpclient;
6263
private HttpClientContext context;
6364

65+
//Special characters.
66+
private static final String UTF8_BOM = "\uFEFF";
67+
6468
//Instantiation.
6569
public NetworkingBase() {
6670
httpclient = HttpClientBuilder.create().build();
@@ -208,6 +212,7 @@ protected String[] getURL(String ur, boolean unescapeHTML4) throws IOException {
208212
if (unescapeHTML4) {
209213
inputLine = StringEscapeUtils.unescapeHtml4(StringEscapeUtils.unescapeHtml4(inputLine));
210214
}
215+
inputLine = removeBOM(inputLine);
211216

212217
page.add(inputLine);
213218
}
@@ -313,6 +318,16 @@ public String URLdecode(String url) {
313318
}
314319
}
315320

321+
public String removeBOM(String text) {
322+
String toReturn = text;
323+
324+
if (text.startsWith(UTF8_BOM)) {
325+
toReturn = toReturn.substring(1);
326+
}
327+
328+
return toReturn;
329+
}
330+
316331
/**
317332
* Log these cookies using the log() method.
318333
* @param cookies

0 commit comments

Comments
 (0)