コード例 #1
0
ファイル: MediaWikiClient.java プロジェクト: vnnavarro/imagej
 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;
 }
コード例 #2
0
ファイル: MediaWikiClient.java プロジェクト: vnnavarro/imagej
 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;
 }
コード例 #3
0
ファイル: MediaWikiClient.java プロジェクト: vnnavarro/imagej
 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;
 }
コード例 #4
0
ファイル: MediaWikiClient.java プロジェクト: vnnavarro/imagej
 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;
 }
コード例 #5
0
ファイル: MediaWikiClient.java プロジェクト: vnnavarro/imagej
 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");
 }