Esempio n. 1
0
 public boolean createUser(
     final String userName, final String realName, final String email, final String reason)
     throws IOException {
   final String[] headers = {"Requested-User", userName};
   final XML xml =
       request(
           headers,
           "createfijiwikiaccount",
           "name",
           userName,
           "email",
           email,
           "realname",
           realName,
           "reason",
           reason);
   final String error = getAttribute(xml.xpath("/api/error"), "info");
   if (error != null) {
     System.err.println("Error creating user " + userName + ": " + error);
     return false;
   }
   if (userName.equals(getAttribute(xml.xpath("/api/createfijiwikiaccount"), "created"))) {
     return true;
   }
   return false;
 }
Esempio n. 2
0
 public boolean userExists(final String name) throws IOException {
   final XML xml = query("list", "users", "ususers", name);
   final NodeList list = xml.xpath("/api/query/users/user");
   int count = list.getLength();
   for (int i = 0; i < count; i++) {
     final NamedNodeMap node = list.item(i).getAttributes();
     if (node != null && node.getNamedItem("missing") == null) return true;
   }
   return false;
 }
Esempio n. 3
0
 public boolean login(final String user, final String password) throws IOException {
   XML xml = request(null, "login", "lgname", user, "lgpassword", password);
   final String loginToken = getAttribute(xml.xpath("/api/login"), "token");
   if (loginToken == null) {
     System.err.println("Did not get a token!");
     return false;
   }
   xml = request(null, "login", "lgname", user, "lgpassword", password, "lgtoken", loginToken);
   final boolean result = "Success".equals(getAttribute(xml.xpath("/api/login"), "result"));
   currentUser = result ? user : null;
   return result;
 }
Esempio n. 4
0
 public boolean changeUploadPassword(final String password) throws IOException {
   if (currentUser == null)
     throw new IOException("Can only change the password for a logged-in user");
   System.err.println("action: changeuploadpassword");
   final XML xml = request(null, "changeuploadpassword", "password", password);
   final String error = getAttribute(xml.xpath("/api/error"), "info");
   if (error != null) {
     System.err.println("Error setting upload password for user '" + currentUser + "': " + error);
     return false;
   }
   final NodeList response = xml.xpath("/api/changeuploadpassword");
   final boolean result = "0".equals(getAttribute(response, "result"));
   if (!result) {
     System.err.println("a1: " + response.item(0));
     System.err.println("Error: " + getAttribute(response, "output"));
   }
   return result;
 }
Esempio n. 5
0
 public String getPageSource(final String title) throws IOException {
   final XML xml = query("titles", title, "export", "true", "exportnowrap", "true");
   return xml.cdata("/mediawiki/page/revision/text");
 }