X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/PostJob.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/PostJob.java index 4ee5c35..e32b44a 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/PostJob.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/PostJob.java @@ -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; @@ -16,6 +15,7 @@ import net.sourceforge.phpeclipse.wiki.actions.mediawiki.exceptions.UnexpectedAn import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; import net.sourceforge.phpeclipse.wiki.internal.Configuration; import net.sourceforge.phpeclipse.wiki.preferences.Util; +import net.sourceforge.phpeclipse.wiki.renderer.StringUtil; import net.sourceforge.phpeclipse.wiki.velocity.EditorText; import net.sourceforge.phpeclipse.wiki.xml.Page; import net.sourceforge.phpeclipse.wiki.xml.XStreamManager; @@ -83,14 +83,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 +121,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]; @@ -128,7 +134,7 @@ public class PostJob extends WorkspaceJob { wikiURLTitle = Util.getURLWikiName(file); String body = StoreWikipediaAction.getInputStreamAsString(is, wikipedia.getCharSet()); char ch; - boolean noContent = checkNoContent(body); + boolean noContent = StringUtil.checkNoContent(body); String srcBasePath = Util.getWikiTextsPath(file); String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH); @@ -158,7 +164,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) { @@ -230,43 +236,6 @@ public class PostJob extends WorkspaceJob { return Status.CANCEL_STATUS; } - /** - * @param body - * @param j - * @return - */ - private boolean checkNoContent(String body) { - char ch; - boolean noContent = true; - int j = 0; - try { - while (true) { - ch = body.charAt(j++); - if (!Character.isWhitespace(ch)) { - if (ch == '<' && body.charAt(j) == '!' && body.charAt(j + 1) == '-' && body.charAt(j + 2) == '-') { - // - j += 3; - while (true) { - ch = body.charAt(j++); - if (ch == '-' && body.charAt(j) == '-' && body.charAt(j + 1) == '>') { - j += 2; - break; - } - } - } else if (ch == '<' && body.charAt(j) == 'b' && body.charAt(j + 1) == 'r' && body.charAt(j + 2) == '>') { - //
- } else { - noContent = false; - break; - } - } - } - } catch (IndexOutOfBoundsException e) { - - } - return noContent; - } - public boolean isModal(Job job) { Boolean isModal = (Boolean) job.getProperty(IProgressConstants.PROPERTY_IN_DIALOG); if (isModal == null) {