From 3e58041d81a569a7aed9f429cf94c9dc393bb913 Mon Sep 17 00:00:00 2001 From: axelcl Date: Thu, 6 Jan 2005 21:22:54 +0000 Subject: [PATCH] version 1.1.2b --- .../mediawiki/DownloadWikiLinkEditorAction.java | 2 +- .../mediawiki/DownloadWikibooksENAction.java | 23 +++++- .../actions/mediawiki/DownloadWikipediaAction.java | 3 +- .../mediawiki/DownloadWikipediaENAction.java | 20 ++++- .../wiki/actions/mediawiki/MediaWikiConnector.java | 86 +++++++++++++++++--- .../phpeclipse/wiki/editor/WikiEditorPlugin.java | 6 +- 6 files changed, 119 insertions(+), 21 deletions(-) diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikiLinkEditorAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikiLinkEditorAction.java index 38080a0..a45c2a3 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikiLinkEditorAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikiLinkEditorAction.java @@ -159,7 +159,7 @@ public final class DownloadWikiLinkEditorAction implements IEditorActionDelegate if (part != null && (part instanceof AbstractTextEditor)) { AbstractTextEditor newEditor = (AbstractTextEditor) part; word = Util.titleToDB(word); - String wikiText = MediaWikiConnector.getWikiText(word, "http://en.wikibooks.org/w/wiki.phtml"); + String wikiText = MediaWikiConnector.getWikiRawText(word, "http://en.wikibooks.org/w/wiki.phtml"); if (wikiText!=null) { IDocument doc = newEditor.getDocumentProvider().getDocument(newEditor.getEditorInput()); doc.set(wikiText); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java index 495db99..4f0a86c 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java @@ -1,12 +1,29 @@ package net.sourceforge.phpeclipse.wiki.actions.mediawiki; +import java.util.List; + +import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; import net.sourceforge.phpeclipse.wiki.internal.Configuration; import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy; public final class DownloadWikibooksENAction extends DownloadWikipediaAction { - protected Configuration getConfiguration(){ - ConfigurationWorkingCopy configuration = new ConfigurationWorkingCopy(); - configuration.setURL("http://en.wikibooks.org/w/wiki.phtml?title=$text.wikiname&action=edit"); + protected Configuration getConfiguration() { + List configs = WikiEditorPlugin.getConfigurations(); + ConfigurationWorkingCopy configuration = null; + // Wikipedia-en"" + + for (int i = 0; i < configs.size(); i++) { + configuration = (ConfigurationWorkingCopy) configs.get(i); + if (configuration.getName().equals("Wikibooks-en") && configuration.getType().equals("Wikipedia-Load Text")) { + break; + } else { + configuration = null; + } + } + if (configuration == null) { + // fall back, if user deleted configuration: + configuration = new ConfigurationWorkingCopy(); + configuration.setURL("http://en.wikibooks.org/w/index.php?title=$text.wikiname&action=raw"); + } return configuration; } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaAction.java index bf82b88..81ca70b 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaAction.java @@ -10,7 +10,6 @@ import net.sourceforge.phpeclipse.wiki.editor.WikiEditor; import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; import net.sourceforge.phpeclipse.wiki.internal.Configuration; import net.sourceforge.phpeclipse.wiki.internal.ConfigurationManager; -import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy; import net.sourceforge.phpeclipse.wiki.internal.IConfiguration; import net.sourceforge.phpeclipse.wiki.preferences.Util; import net.sourceforge.phpeclipse.wiki.velocity.EditorText; @@ -220,7 +219,7 @@ public class DownloadWikipediaAction implements IEditorActionDelegate { Configuration configuration = getConfiguration(); if (configuration != null && !configuration.equals("")) { String url = generateUrl(configuration, configuration.getURL(), wikiName); - String wikiContent = MediaWikiConnector.getWikiText(wikiName, url); + String wikiContent = MediaWikiConnector.getWikiRawText(wikiName, url); if (wikiContent != null) { IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()); doc.set(wikiContent); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java index 14dd2ae..33cc554 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java @@ -1,12 +1,28 @@ package net.sourceforge.phpeclipse.wiki.actions.mediawiki; +import java.util.List; + +import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; import net.sourceforge.phpeclipse.wiki.internal.Configuration; import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy; public final class DownloadWikipediaENAction extends DownloadWikipediaAction { protected Configuration getConfiguration(){ - ConfigurationWorkingCopy configuration = new ConfigurationWorkingCopy(); - configuration.setURL("http://en.wikipedia.org/w/wiki.phtml?title=$text.wikiname&action=edit"); + List configs = WikiEditorPlugin.getConfigurations(); + ConfigurationWorkingCopy configuration = null; + for (int i = 0; i < configs.size(); i++) { + configuration = (ConfigurationWorkingCopy) configs.get(i); + if (configuration.getName().equals("Wikipedia-en") && configuration.getType().equals("Wikipedia-Load Text")) { + break; + } else { + configuration = null; + } + } + if (configuration == null) { + // fall back, if user deleted configuration: + configuration = new ConfigurationWorkingCopy(); + configuration.setURL("http://en.wikipedia.org/w/wiki.phtml?title=$text.wikiname&action=raw"); + } return configuration; } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/MediaWikiConnector.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/MediaWikiConnector.java index b2e845e..2db9f21 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/MediaWikiConnector.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/MediaWikiConnector.java @@ -1,8 +1,6 @@ package net.sourceforge.phpeclipse.wiki.actions.mediawiki; -import java.io.IOException; import java.io.InputStream; -import java.io.StringReader; import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; @@ -27,15 +25,83 @@ public class MediaWikiConnector { * Get the text of a wikimedia Wiki-Description from en.wikipedia.org * */ - public static String getWikiText(String wikiDescriptor) { - return getWikiText(wikiDescriptor, null); + public static String getWikiRawText(String wikiDescriptor) { + return getWikiRawText(wikiDescriptor, null); } /** * Get the text of a wikimedia Wiki-Description * */ - public static String getWikiText(String wikiname, String urlStr) { + public static String getWikiRawText(String wikiname, String urlStr) { + // examples + // http://en.wikipedia.org/w/wiki.phtml?title=Main_Page&action=raw + // http://en.wikibooks.org/w/index.php?title=Programming:PHP:SQL_Injection&action=raw + // http://en.wikipedia.org/w/wiki.phtml?title=Talk:Division_by_zero&action=raw + HttpMethod method = null; + try { + if (urlStr == null) { + WikiEditorPlugin.getDefault().reportError("No Wikipedia URL configured", "URL-String == null"); + // urlStr = "http://en.wikipedia.org/w/wiki.phtml?title=" + wikiname + "&action=raw"; + } + URI uri = new URI(urlStr.toCharArray()); + + String schema = uri.getScheme(); + if ((schema == null) || (schema.equals(""))) { + schema = "http"; + } + Protocol protocol = Protocol.getProtocol(schema); + + HttpState state = new HttpState(); + + method = new GetMethod(uri.toString()); + String host = uri.getHost(); + int port = uri.getPort(); + + HttpConnection connection = new HttpConnection(host, port, protocol); + // timeout after 30 seconds + connection.setConnectionTimeout(30000); + connection.setProxyHost(System.getProperty("http.proxyHost")); + connection.setProxyPort(Integer.parseInt(System.getProperty("http.proxyPort", "80"))); + + if (System.getProperty("http.proxyUserName") != null) { + state.setProxyCredentials(null, null, new UsernamePasswordCredentials(System.getProperty("http.proxyUserName"), System + .getProperty("http.proxyPassword"))); + } + + if (connection.isProxied() && connection.isSecure()) { + method = new ConnectMethod(method); + } + + method.execute(state, connection); + + if (method.getStatusCode() == HttpStatus.SC_OK) { + // get the wiki text now: + String wikiText = method.getResponseBodyAsString(); + return wikiText; + // wrong text not always complete + // InputStream stream = method.getResponseBodyAsStream(); + // int byteLen = stream.available(); + // int count = 1; + // byte[] buffer = new byte[byteLen]; + // int len = 0; + // stream.read(buffer, 0, byteLen); + // String wikiText = new String(buffer); + // return wikiText; + // System.out.println(wikiText); + } + } catch (Throwable e) { + WikiEditorPlugin.log(e); + WikiEditorPlugin.getDefault().reportError("Exception occured", e.getMessage() + "\nSee stacktrace in /.metadata/.log file."); + } finally { + if (method != null) { + method.releaseConnection(); + } + } + return null; // no success in getting wiki text + } + + public static String getWikiEditTextarea(String wikiname, String urlStr) { // examples // http://en.wikipedia.org/w/wiki.phtml?title=Main_Page&action=edit // http://en.wikibooks.org/w/wiki.phtml?title=Programming:PHP:SQL_Injection&action=edit @@ -44,10 +110,10 @@ public class MediaWikiConnector { try { if (urlStr == null) { urlStr = "http://en.wikipedia.org/w/wiki.phtml?title=" + wikiname + "&action=edit"; - } -// else { -// urlStr = urlStr + "?title=" + wikiname + "&action=edit"; -// } + } + // else { + // urlStr = urlStr + "?title=" + wikiname + "&action=edit"; + // } URI uri = new URI(urlStr.toCharArray()); String schema = uri.getScheme(); @@ -86,7 +152,7 @@ public class MediaWikiConnector { byte[] buffer = new byte[byteLen]; stream.read(buffer, 0, byteLen); String wikiText = new String(buffer); -// String wikiText = method.getResponseBodyAsString(); + // String wikiText = method.getResponseBodyAsString(); int start = wikiText.indexOf("", start + 1); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java index 5dce1b6..fb22ed1 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java @@ -68,15 +68,15 @@ public class WikiEditorPlugin extends AbstractUIPlugin { public final static String EXPORT_CSS_URL = "__export_css_url"; - public final static String PREF_STRING_CONFIGURATIONS = "configurations"; + public final static String PREF_STRING_CONFIGURATIONS = "__configurations1"; public final static String CONFIG_MEMENTO = "" + "" + "" + "" + "" - + "" - + "" + + "" + + "" + "" + ""; -- 1.7.1