Handle the new "wpEditToken" input parameter for upload
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / actions / mediawiki / post / PostJob.java
index 4ee5c35..7726ecc 100644 (file)
@@ -2,7 +2,6 @@ package net.sourceforge.phpeclipse.wiki.actions.mediawiki.post;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.io.StringWriter;
 import java.util.HashMap;
 
@@ -83,14 +82,14 @@ public class PostJob extends WorkspaceJob {
     return template;
   }
 
-  private void uploadWiki(String timestamp, String body, MediaWikiConnector connector, String actionUrl, String wikiName)
-      throws UnexpectedAnswerException, MethodException, PageNotEditableException, InterruptedException {
+  private void uploadWiki(String timestamp, String editToken, String body, MediaWikiConnector connector, String actionUrl,
+      String wikiName) throws UnexpectedAnswerException, MethodException, PageNotEditableException, InterruptedException {
 
     String url = generateUrl(configuration.getURL(), wikiName);
     //      System.out.println(timestamp);
     Content content = new Content(timestamp, body);
 
-    connector.store(wikipedia, actionUrl, wikiName, content, "", false, false);
+    connector.store(wikipedia, editToken, actionUrl, wikiName, content, "", false, false);
 
   }
 
@@ -121,6 +120,12 @@ public class PostJob extends WorkspaceJob {
       connector = new MediaWikiConnector();
       success = connector.login(wikipedia, actionUrl, user, password, false);
       if (success) {
+        String editToken = connector.loadEditToken(actionUrl, wikipedia.getCharSet(), "plog4u.org bot");
+        if (editToken == null) {
+          console.println("Edit token not found: running in unsave update mode");
+        } else {
+          console.println("Using edit token: " + editToken);
+        }
         for (int i = 0; i < files.length; i++) {
           try {
             file = files[i];
@@ -158,7 +163,7 @@ public class PostJob extends WorkspaceJob {
               console.println("File: " + file.getLocation().toString() + "\n==>upload not allowed; Wiki text contains no content");
             } else {
               monitor.subTask("Upload: " + file.getLocation().toString());
-              uploadWiki(timestamp, body, connector, actionUrl, wikiURLTitle);
+              uploadWiki(timestamp, editToken, body, connector, actionUrl, wikiURLTitle);
             }
 
           } catch (CoreException e1) {