Skip to content

Commit

Permalink
Decompiled Fastily's class files
Browse files Browse the repository at this point in the history
  • Loading branch information
Rillke committed Jun 1, 2015
0 parents commit bbce5d4
Show file tree
Hide file tree
Showing 19 changed files with 4,904 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.class
*.jar
*.lnk
.DS_Store
sources.txt
4 changes: 4 additions & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fbot, ft:
http://commons.wikimedia.org/wiki/User:{{{?}}}
- Fastily [original source]
- Rillke [fixing some decompilation glitches, use API login]
62 changes: 62 additions & 0 deletions LICENSE.fbot.cc-by-sa-3.0.txt

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Manifest-Version: 1.0
Created-By: 1.6.0_35 (Apple Inc.)
Main-Class: org.ft.Up

24 changes: 24 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

# How to recursively find all files that match a pattern
ALL_JAVAS := $(call rwildcard,org/,*.java)

all: up
up: compile up.jar
@echo "Done!"

compile:
javac $(ALL_JAVAS)

up.jar:
jar cmf MANIFEST.MF up.jar org

clean: FRC
-rm *.jar

# This pseudo target causes all targets that depend on FRC
# to be remade even in case a file with the name of the target exists.
# This works with any make implementation under the assumption that
# there is no file FRC in the current directory.
FRC:
197 changes: 197 additions & 0 deletions org/fbot/Fbot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
* Decompiled with CFR 0_101.
*/
package org.fbot;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import javax.security.auth.login.FailedLoginException;
import javax.security.auth.login.LoginException;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import org.fbot.FbotUtil;
import org.wikipedia.Wiki;

public class Fbot {
private Fbot() {
}

public static void loginAndSetPrefs(Wiki wiki, String user, char[] p) {
wiki.setThrottle(1);
wiki.setMaxLag(-1);
int i = 0;
boolean success = false;
do {
try {
wiki.login(user, p);
success = true;
continue;
}
catch (IOException e) {
System.out.println("Encountered IOException. This was try #" + i);
short s = (short)(i + 1);
i = s;
if (s <= 8) continue;
System.exit(1);
continue;
}
catch (FailedLoginException e) {
e.printStackTrace();
System.exit(1);
}
} while (!success);
}

public static void loginPX(Wiki wiki, String user) throws FileNotFoundException {
HashMap<String, String> c = FbotUtil.buildReasonCollection("./px");
String px = c.get(user);
if (px == null) {
throw new UnsupportedOperationException("Did not find a Username in the specified file matching String value in user param");
}
Fbot.loginAndSetPrefs(wiki, user, px.toCharArray());
}

public static void guiLogin(Wiki wiki) {
JTextField u = new JTextField(12);
JPasswordField px = new JPasswordField(12);
JPanel pl = FbotUtil.buildForm("Login", new JLabel("Username:", 11), u, new JLabel("Password:", 11), px);
if (JOptionPane.showConfirmDialog(null, pl, "Login", 2, -1) != 0) {
System.exit(0);
}
Fbot.loginAndSetPrefs(wiki, u.getText().trim(), px.getPassword());
wiki.setThrottle(5);
}

public static String getRedirectTarget(String redirect, Wiki wiki) throws IOException {
String text = wiki.getPageText(redirect).trim();
if (text.matches("(?si)^#(redirect)\\s*?\\[\\[.+?\\]\\].*?")) {
return text.substring(text.indexOf("[[") + 2, text.indexOf("]]"));
}
throw new UnsupportedOperationException("Parameter passed in is not a redirect page!");
}

public static boolean exists(String page, Wiki wiki) throws IOException {
return (Boolean)wiki.getPageInfo(page).get("exists");
}

public static void dbrDump(String page, String[] list, String headerText, String footerText, Wiki wiki) throws LoginException, IOException {
String dump = String.valueOf(headerText) + " This report last updated as of ~~~~~\n";
for (String s : list) {
dump = String.valueOf(dump) + "*[[:" + s + "]]\n";
}
dump = String.valueOf(dump) + "\n" + footerText;
wiki.edit(page, dump, "Updating list");
}

public static String[] listNamespaceSort(String[] list, int namespace, Wiki wiki) throws IOException {
ArrayList<String> l = new ArrayList<String>();
for (String s : list) {
if (wiki.namespace(s) != namespace) continue;
l.add(s);
}
return l.toArray(new String[0]);
}

public static String[] arrayNuke(String[] list, String reason, String talkReason, Wiki wiki) {
ArrayList<String> f = new ArrayList<String>();
for (String s : list) {
try {
wiki.delete(s, reason);
}
catch (Throwable e) {
f.add(s);
continue;
}
if (talkReason == null) continue;
try {
wiki.delete(wiki.getTalkPage(s), talkReason);
continue;
}
catch (Throwable e) {
// empty catch block
}
}
return f.toArray(new String[0]);
}

public static void addTextList(String[] pages, String text, String summary, Wiki wiki) {
for (String page : pages) {
try {
wiki.edit(page, String.valueOf(wiki.getPageText(text)) + text, summary);
continue;
}
catch (Throwable e) {
e.printStackTrace();
}
}
}

public static void fileReplace(String[] list, String file, String replacement, String summary, Wiki wiki) {
file = file.replace((CharSequence)"_", (CharSequence)" ");
String regex = "(?i)(" + file + "|" + file.replace((CharSequence)" ", (CharSequence)"_") + ")";
for (String page : list) {
try {
wiki.edit(page, wiki.getPageText(page).replaceAll(regex, replacement), summary);
continue;
}
catch (Throwable e) {
e.printStackTrace();
}
}
}

public static Wiki wikiFactory(String u, char[] p, String domain) {
Wiki wiki = new Wiki(domain);
Fbot.loginAndSetPrefs(wiki, u, p);
return wiki;
}

public static void downloadFile(String title, String localpath, Wiki wiki) throws IOException, FileNotFoundException {
FileOutputStream fos = new FileOutputStream(localpath);
fos.write(wiki.getImage(title));
fos.close();
}

public static void superAction(Wiki wiki, String page, String reason, String code) throws LoginException, IOException {
boolean success = false;
int i = 0;
do {
try {
if (code.equals("delete")) {
wiki.delete(page, reason);
} else if (code.equals("upload")) {
wiki.upload(new File(page), page, reason, "");
} else {
throw new UnsupportedOperationException(String.valueOf(code) + " is not a valid code!");
}
success = true;
continue;
}
catch (LoginException e) {
throw e;
}
catch (IOException e) {
int n = i;
i = (short)(n + 1);
if (n > 4) {
throw e;
}
e.printStackTrace();
System.err.println("Network error? Try: " + i + " of 5");
continue;
}
catch (Exception e) {
e.printStackTrace();
}
} while (!success);
}
}

97 changes: 97 additions & 0 deletions org/fbot/FbotParse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Decompiled with CFR 0_101.
*/
package org.fbot;

import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.wikipedia.Wiki;

public class FbotParse {
private FbotParse() {
}

public static String getRedirectsAsRegex(String template, Wiki wiki) throws IOException {
String r = "(?si)\\{{2}?\\s*?(Template:)??\\s*?(" + FbotParse.namespaceStrip(template);
for (String str : wiki.whatLinksHere(template, true, 10)) {
r = String.valueOf(r) + "|" + FbotParse.namespaceStrip(str);
}
r = String.valueOf(r) + ").*?\\}{2}?";
return r;
}

public static boolean allowBots(String text, String user) {
return !text.matches("(?i).*?\\{\\{(nobots|bots\\|(allow=none|deny=(.*?" + user + ".*?|all)|optout=all))\\}\\}.*?");
}

public static void templateReplace(String template, String replacementText, String reason, Wiki wiki) throws IOException {
String[] list = wiki.whatTranscludesHere(template, new int[0]);
if (template.startsWith("Template:")) {
template = FbotParse.namespaceStrip(template);
}
for (String page : list) {
try {
wiki.edit(page, wiki.getPageText(page).replaceAll("(?i)(" + template + ")", replacementText), reason);
continue;
}
catch (Throwable e) {
e.printStackTrace();
}
}
}

public static String namespaceStrip(String title) {
int i = title.indexOf(":");
if (i > 0) {
return title.substring(i + 1);
}
return title;
}

public static String getTemplateParam(String template, int number) {
try {
return FbotParse.templateParamStrip(template.split("\\|")[number]);
}
catch (ArrayIndexOutOfBoundsException e) {
return null;
}
}

public static String getTemplateParam(String template, String param) {
ArrayList<String> f = new ArrayList<String>();
for (String s : template.split("\\|")) {
f.add(s.trim());
}
for (String p : f) {
if (!p.startsWith(param)) continue;
return FbotParse.templateParamStrip(p);
}
return null;
}

public static String templateParamStrip(String p) {
int i = p.indexOf("=");
if (i == -1) {
return p;
}
return p.substring(i + 1).replace((CharSequence)"}}", (CharSequence)"").trim();
}

public static String parseTemplateFromPage(String text, String template, boolean redirects, Wiki wiki) throws IOException {
if (redirects) {
return FbotParse.parseFromPageRegex(text, FbotParse.getRedirectsAsRegex("Template:" + template, wiki));
}
return FbotParse.parseFromPageRegex(text, "(?si)\\{\\{\\s*?(Template:)??\\s*?(" + template + ").*?\\}\\}");
}

public static String parseFromPageRegex(String text, String regex) {
Matcher m = Pattern.compile(regex).matcher((CharSequence)text);
if (m.find()) {
return text.substring(m.start(), m.end());
}
return null;
}
}

Loading

0 comments on commit bbce5d4

Please sign in to comment.