package net.sourceforge.phpeclipse.wiki.actions.mediawiki;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
import java.io.ByteArrayInputStream;
+import net.sourceforge.phpeclipse.wiki.actions.mediawiki.connect.MediaWikiConnector;
import net.sourceforge.phpeclipse.wiki.editor.WikiEditor;
import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
import net.sourceforge.phpeclipse.wiki.preferences.Util;
package net.sourceforge.phpeclipse.wiki.actions.mediawiki;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
import java.util.List;
package net.sourceforge.phpeclipse.wiki.actions.mediawiki;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
-import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import net.sourceforge.phpeclipse.wiki.actions.mediawiki.connect.MediaWikiConnector;
import net.sourceforge.phpeclipse.wiki.editor.WikiEditor;
import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
import net.sourceforge.phpeclipse.wiki.internal.Configuration;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceStatus;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.dialogs.ListSelectionDialog;
import org.eclipse.ui.internal.dialogs.ListContentProvider;
-import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.texteditor.AbstractTextEditor;
public class DownloadWikipediaAction implements IEditorActionDelegate {
private IWorkbenchWindow window;
- private void createFolder(IFolder folderHandle, IProgressMonitor monitor) throws CoreException {
- try {
- // Create the folder resource in the workspace
- // Recursive to create any folders which do not exist already
- if (!folderHandle.exists()) {
- IContainer parent = folderHandle.getParent();
- if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
- createFolder((IFolder) parent, monitor);
- }
- folderHandle.create(false, true, monitor);
- }
- } catch (CoreException e) {
- // If the folder already existed locally, just refresh to get contents
- if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
- folderHandle.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 500));
- else
- throw e;
- }
- }
-
- /**
- * Creates a folder resource handle for the folder with the given workspace path. This method does not create the folder resource;
- * this is the responsibility of <code>createFolder</code>.
- *
- * @param folderPath
- * the path of the folder resource to create a handle for
- * @return the new folder resource handle
- * @see #createFolder
- */
- private IFolder createFolderHandle(IPath folderPath) {
- return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(folderPath);
- }
-
- private void createNewFileIfNeeded(IFile file, String word) throws CoreException {
- if (!file.exists()) {
- createWikiFile(file, word);
- }
- }
-
- private void createWikiFile(IFile file, String word) throws CoreException {
- IContainer parent = file.getParent();
- if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
- createFolder((IFolder) parent, null);
- }
- String newText = "<!--" + word + "-->";
- byte[] buffer = newText.getBytes();
- ByteArrayInputStream source = new ByteArrayInputStream(buffer);
- file.create(source, true, null);
- }
+
public void dispose() {
}
package net.sourceforge.phpeclipse.wiki.actions.mediawiki;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
import java.util.List;
+++ /dev/null
-package net.sourceforge.phpeclipse.wiki.actions.mediawiki;
-
-import java.io.InputStream;
-
-import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
-
-import org.apache.commons.httpclient.ConnectMethod;
-import org.apache.commons.httpclient.HttpConnection;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.URI;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.protocol.Protocol;
-
-/**
- * This class gets the wikitext from a wikipedia edit page
- *
- * The basic coding was copied from the commons-httpclient example <code>MediaWikiConnector.java</code>
- */
-public class MediaWikiConnector {
-
- /**
- * Get the text of a wikimedia Wiki-Description from <code>en.wikipedia.org</code>
- *
- */
- public static String getWikiRawText(String wikiDescriptor) {
- return getWikiRawText(wikiDescriptor, null);
- }
-
- /**
- * Get the text of a wikimedia Wiki-Description
- *
- */
- 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
- // http://en.wikipedia.org/w/wiki.phtml?title=Talk:Division_by_zero&action=edit
- HttpMethod method = null;
- try {
- if (urlStr == null) {
- urlStr = "http://en.wikipedia.org/w/wiki.phtml?title=" + wikiname + "&action=edit";
- }
- // else {
- // urlStr = urlStr + "?title=" + wikiname + "&action=edit";
- // }
- 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);
-
- 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 textareas wiki text now:
- InputStream stream = method.getResponseBodyAsStream();
- int byteLen = stream.available();
- int count = 1;
- byte[] buffer = new byte[byteLen];
- stream.read(buffer, 0, byteLen);
- String wikiText = new String(buffer);
- // String wikiText = method.getResponseBodyAsString();
- int start = wikiText.indexOf("<textarea");
- if (start != (-1)) {
- start = wikiText.indexOf(">", start + 1);
- if (start != (-1)) {
- int end = wikiText.indexOf("</textarea>");
- wikiText = wikiText.substring(start + 1, end);
- }
- }
- return wikiText;
- // System.out.println(wikiText);
-
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (method != null) {
- method.releaseConnection();
- }
- }
- return null; // no success in getting wiki text
- }
-}
-
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.config;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+public abstract class AbstractWikipedia implements IWikipedia {
+ private WikiProperties fProperties;
+
+ protected AbstractWikipedia(WikiProperties properties) {
+ this.fProperties = properties;
+ }
+
+ /**
+ * @return Returns the actionPath.
+ */
+ public String getActionPath() {
+ return fProperties.getString("actionPath");
+ }
+
+ /**
+ * @return Returns the actionPath2.
+ */
+ public String getActionPath2() {
+ return fProperties.getString("actionPath2");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.sourceforge.phpeclipse.wiki.actions.mediawiki.config.IWikipedia#getActionUrl()
+ */
+ public String getActionUrl() {
+ return getBaseURL() + getActionPath();
+ }
+
+ /**
+ * @return Returns the baseURL.
+ */
+ public String getBaseURL() {
+ return fProperties.getString("baseURL");
+ }
+
+ /**
+ * @return Returns the charSet.
+ */
+ public String getCharSet() {
+ return fProperties.getString("charSet");
+ }
+
+ /**
+ * @return Returns the loginNoUser.
+ */
+ public String getLoginNoUser() {
+ return fProperties.getString("loginNoUser");
+ }
+
+ /**
+ * @return Returns the loginSuccess.
+ */
+ public String getLoginSuccess() {
+ return fProperties.getString("loginSuccess");
+ }
+
+ /**
+ * @return Returns the loginTitle.
+ */
+ public String getLoginTitle() {
+ return fProperties.getString("specialNs")+ ":Userlogin";
+ }
+
+ /**
+ * @return Returns the loginWrongPw.
+ */
+ public String getLoginWrongPw() {
+ return fProperties.getString("loginWrongPw");
+ }
+
+ /**
+ * @return Returns the logoutSuccess.
+ */
+ public String getLogoutSuccess() {
+ return fProperties.getString("logoutSuccess");
+ }
+
+ /**
+ * @return Returns the logoutTitle.
+ */
+ public String getLogoutTitle() {
+ return fProperties.getString("specialNs")+ ":Userlogout";
+ }
+
+ /**
+ * @return Returns the metaNs.
+ */
+ public String getMetaNs() {
+ return fProperties.getString("metaNs");
+ }
+
+ /**
+ * @return Returns the readPath.
+ */
+ public String getReadPath() {
+ return fProperties.getString("readPath");
+ }
+
+ /**
+ * @return Returns the specialNs.
+ */
+ public String getSpecialNs() {
+ return fProperties.getString("specialNs");
+ }
+
+ /**
+ * @return Returns the uploadNoLogin.
+ */
+ public String getUploadNoLogin() {
+ return fProperties.getString("uploadNoLogin");
+ }
+
+ /**
+ * @return Returns the uploadSuccess.
+ */
+ public String getUploadSuccess() {
+ return fProperties.getString("uploadSuccess");
+ }
+
+ /**
+ * @return Returns the uploadTitle.
+ */
+ public String getUploadTitle() {
+ return fProperties.getString("specialNs")+ ":Upload";
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.config;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+public interface IWikipedia {
+
+ /**
+ * @return Returns the actionPath.
+ */
+ public String getActionPath();
+ /**
+ * @return Returns the actionPath2.
+ */
+ public String getActionPath2();
+ /**
+ * @return Returns the baseURL.
+ */
+ public String getBaseURL();
+ /**
+ * @return Returns the charSet.
+ */
+ public String getCharSet();
+ /**
+ * @return Returns the loginNoUser.
+ */
+ public String getLoginNoUser();
+ /**
+ * @return Returns the loginSuccess.
+ */
+ public String getLoginSuccess();
+ /**
+ * @return Returns the loginTitle.
+ */
+ public String getLoginTitle();
+ /**
+ * @return Returns the loginWrongPw.
+ */
+ public String getLoginWrongPw();
+ /**
+ * @return Returns the logoutSuccess.
+ */
+ public String getLogoutSuccess();
+ /**
+ * @return Returns the logoutTitle.
+ */
+ public String getLogoutTitle();
+ /**
+ * @return Returns the metaNs.
+ */
+ public String getMetaNs();
+ /**
+ * @return Returns the nameSpaces.
+ */
+ public String[] getNameSpaces();
+ /**
+ * @return Returns the readPath.
+ */
+ public String getReadPath();
+ /**
+ * @return Returns the specialNs.
+ */
+ public String getSpecialNs();
+ /**
+ * @return Returns the uploadNoLogin.
+ */
+ public String getUploadNoLogin();
+ /**
+ * @return Returns the uploadSuccess.
+ */
+ public String getUploadSuccess();
+ /**
+ * @return Returns the uploadTitle.
+ */
+ public String getUploadTitle();
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.config;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class WikiProperties {
+
+ private static final String PACKAGE_NAME = WikiProperties.class.getPackage().getName();
+
+ private String RESOURCE_BUNDLE = null;
+
+ private ResourceBundle fgResourceBundle = null;
+
+ protected WikiProperties(String locale) {
+ RESOURCE_BUNDLE = PACKAGE_NAME + ".WikiProperties" + locale;
+ fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
+ }
+
+ public String getString(String key) {
+ try {
+ return fgResourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+
+ /**
+ * Gets a string from the resource bundle and formats it with the argument
+ *
+ * @param key
+ * the string used to get the bundle value, must not be null
+ */
+ public String getFormattedString(String key, Object arg) {
+ return MessageFormat.format(getString(key), new Object[] { arg });
+ }
+
+ /**
+ * Gets a string from the resource bundle and formats it with arguments
+ */
+ public String getFormattedString(String key, Object[] args) {
+ return MessageFormat.format(getString(key), args);
+ }
+
+ // test code
+// public static void main(String[] args) {
+// WikiProperties p = new WikiProperties("EN");
+// System.out.println(p.getString("uploadNoLogin"));
+// }
+
+}
\ No newline at end of file
--- /dev/null
+baseURL=http://de.wikipedia.org
+actionPath=/w/index.php
+actionPath2=/w/wiki.phtml
+readPath=/wiki/
+charSet=UTF-8
+specialNs=Spezial
+metaNs=Wikipedia
+loginSuccess=(?s).*?Du bist jetzt als ".*?" bei Wikipedia angemeldet.*
+loginWrongPw=(?s).*?Das Passwort ist falsch.*? Bitte versuche es erneut.*
+loginNoUser=(?s).*?Der Benutzername \".*?\" existiert nicht.*?Überprüfen Sie die Schreibweise, oder melden Sie sich als neuer Benutzer an.*
+logoutSuccess=(?s).*?Du bist nun abgemeldet.*?Du kannst die Wikipedia jetzt weiter mit deiner IP-Adresse benutzen, oder dich unter demselben oder einem anderen Benutzernamen wieder anmelden.*
+uploadSuccess=(?s).*?Erfolgreich hochgeladen.*
+uploadNoLogin=(?s).*?Sie müssen .*?angemeldet sein.*?um Dateien hochladen zu können.*
--- /dev/null
+baseURL=http://en.wikipedia.org
+actionPath=/w/index.php
+actionPath2=/w/wiki.phtml
+readPath=/wiki/
+charSet=ISO-8859-1
+specialNs=Special
+metaNs=Wikipedia
+loginSuccess=(?s).*?You are now logged in to .*? as ".*?".*
+loginWrongPw=(?s).*?The password you entered is incorrect.*? Please try again.*
+loginNoUser=(?s).*?There is no user by the name \".*?\".*?Check your spelling, or use the form below to create a new user account.*? If there is no form below, account creation is temporarily disabled.*? In this case, please accept our apologies and try again later.*
+logoutSuccess=(?s).*?You are now logged out.*? This computer may be used to browse and edit Wikipedia without a user name, or for another user to log on.*? Note that some pages may continue to be displayed as if you were still logged in; this can be fixed by clearing your browser cache.*
+uploadSuccess=(?s).*?Successful upload.*
+uploadNoLogin=(?s).*?You must be .*?logged in.*?to upload files.*
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.config;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+
+public class WikipediaDE extends AbstractWikipedia {
+
+ final private static String[] nameSpaces = new String[] { "Media", "Spezial", "", "Diskussion", "Benutzer",
+ "Benutzer Diskussion", "Wikipedia", "Wikipedia Diskussion", "Bild", "Bild Diskussion", "MediaWiki", "MediaWiki Diskussion",
+ "Vorlage", "Vorlage Diskussion", "Hilfe", "Hilfe Diskussion", "Kategorie", "Kategorie Diskussion" };
+
+ private static WikipediaDE instance = new WikipediaDE();
+
+ /*
+ * Get the singleton instance
+ */
+ public static IWikipedia getInstance() {
+ return instance;
+ }
+
+ // private constructor
+ private WikipediaDE() {
+ super(new WikiProperties("DE"));
+ }
+
+ /**
+ * @return Returns the nameSpaces.
+ */
+ public String[] getNameSpaces() {
+ return nameSpaces;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.config;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+public class WikipediaEN extends AbstractWikipedia {
+
+ final private static String[] nameSpaces = new String[] { "Media", "Special", "", "Talk", "User", "User talk", "Wikipedia",
+ "Wikipedia talk", "Image", "Image talk", "MediaWiki", "MediaWiki talk", "Template", "Template talk", "Help", "Help talk",
+ "Category", "Category talk" };
+
+ private static WikipediaEN instance = new WikipediaEN();
+
+ /*
+ * Get the singleton instance
+ */
+ public static IWikipedia getInstance() {
+ return instance;
+ }
+
+ // private constructor
+ private WikipediaEN() {
+ super(new WikiProperties("EN"));
+ }
+
+ /**
+ * @return Returns the nameSpaces.
+ */
+ public String[] getNameSpaces() {
+ return nameSpaces;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.exceptions;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+/**
+ * this Exception is thrown, when the underlying HttpClient throws an Exception
+ */
+public class MethodException extends NetworkException {
+ /** Constructs a new exception with null as its detail message. */
+ public MethodException() {
+ super();
+ }
+
+ /** Constructs a new exception with the specified detail message. */
+ public MethodException(String message) {
+ super(message);
+ }
+
+ /** Constructs a new exception with the specified detail message and cause. */
+ public MethodException(String message, Throwable cause) {
+ super(message);
+ }
+
+ /** Constructs a new exception with the specified cause and a detail
+ message of (cause==null ? null : cause.toString()) (which
+ typically contains the class and detail message of cause). */
+ public MethodException(Throwable cause) {
+ super();
+ }
+}
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.exceptions;
+
+/**
+ * base class for Exceptions thrown when something has gone wrong with the networking
+ *
+ */
+public abstract class NetworkException extends Exception {
+ /** Constructs a new exception with null as its detail message. */
+ public NetworkException() {
+ super();
+ }
+
+ /** Constructs a new exception with the specified detail message. */
+ public NetworkException(String message) {
+ super(message);
+ }
+
+ /** Constructs a new exception with the specified detail message and cause. */
+ public NetworkException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /** Constructs a new exception with the specified cause and a detail
+ message of (cause==null ? null : cause.toString()) (which
+ typically contains the class and detail message of cause). */
+ public NetworkException(Throwable cause) {
+ super(cause);
+ }
+}
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.exceptions;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+/**
+ * a Page can not be edited
+ */
+public class PageNotEditableException extends NetworkException {
+ /** Constructs a new exception with null as its detail message. */
+ public PageNotEditableException() {
+ super();
+ }
+
+ /** Constructs a new exception with the specified detail message. */
+ public PageNotEditableException(String message) {
+ super(message);
+ }
+
+ /** Constructs a new exception with the specified detail message and cause. */
+ public PageNotEditableException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /** Constructs a new exception with the specified cause and a detail
+ message of (cause==null ? null : cause.toString()) (which
+ typically contains the class and detail message of cause). */
+ public PageNotEditableException(Throwable cause) {
+ super(cause);
+ }
+}
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.exceptions;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+/**
+ * this Exception is thrown, when the connection to a server returns unexpected values
+ */
+public class UnexpectedAnswerException extends NetworkException {
+ /** Constructs a new exception with null as its detail message. */
+ public UnexpectedAnswerException() {
+ super();
+ }
+
+ /** Constructs a new exception with the specified detail message. */
+ public UnexpectedAnswerException(String message) {
+ super(message);
+ }
+
+ /** Constructs a new exception with the specified detail message and cause. */
+ public UnexpectedAnswerException(String message, Throwable cause) {
+ super(message);
+ }
+
+ /** Constructs a new exception with the specified cause and a detail
+ message of (cause==null ? null : cause.toString()) (which
+ typically contains the class and detail message of cause). */
+ public UnexpectedAnswerException(Throwable cause) {
+ super();
+ }
+}
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.exceptions;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+/**
+ * this URL does not belong to a supported Site
+ */
+public class UnsupportedURLException extends NetworkException {
+ /** Constructs a new exception with null as its detail message. */
+ public UnsupportedURLException() {
+ super();
+ }
+
+ /** Constructs a new exception with the specified detail message. */
+ public UnsupportedURLException(String message) {
+ super(message);
+ }
+
+ /** Constructs a new exception with the specified detail message and cause. */
+ public UnsupportedURLException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /** Constructs a new exception with the specified cause and a detail
+ message of (cause==null ? null : cause.toString()) (which
+ typically contains the class and detail message of cause). */
+ public UnsupportedURLException(Throwable cause) {
+ super(cause);
+ }
+}
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.exceptions;
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+/**
+ * this wiki is not supported
+ */
+public class UnsupportedWikiException extends NetworkException {
+ /** Constructs a new exception with null as its detail message. */
+ public UnsupportedWikiException() {
+ super();
+ }
+
+ /** Constructs a new exception with the specified detail message. */
+ public UnsupportedWikiException(String message) {
+ super(message);
+ }
+
+ /** Constructs a new exception with the specified detail message and cause. */
+ public UnsupportedWikiException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /** Constructs a new exception with the specified cause and a detail
+ message of (cause==null ? null : cause.toString()) (which
+ typically contains the class and detail message of cause). */
+ public UnsupportedWikiException(Throwable cause) {
+ super(cause);
+ }
+}
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.exceptions;
+
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+/**
+ * a File cannot be uploaded
+ */
+public class UploadForbiddenException extends NetworkException {
+ /** Constructs a new exception with null as its detail message. */
+ public UploadForbiddenException() {
+ super();
+ }
+
+ /** Constructs a new exception with the specified detail message. */
+ public UploadForbiddenException(String message) {
+ super(message);
+ }
+
+ /** Constructs a new exception with the specified detail message and cause. */
+ public UploadForbiddenException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /** Constructs a new exception with the specified cause and a detail
+ message of (cause==null ? null : cause.toString()) (which
+ typically contains the class and detail message of cause). */
+ public UploadForbiddenException(Throwable cause) {
+ super(cause);
+ }
+}
--- /dev/null
+package net.sourceforge.phpeclipse.wiki.actions.mediawiki.post;
+
+//Parts of this sources are copied and modified from the jEdit Wikipedia plugin:
+//http://www.djini.de/software/wikipedia/index.html
+//
+//The modified sources are available under the "Common Public License"
+//with permission from the original author: Daniel Wunsch
+
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import net.sourceforge.phpeclipse.wiki.actions.mediawiki.config.IWikipedia;
+import net.sourceforge.phpeclipse.wiki.actions.mediawiki.config.WikipediaDE;
+import net.sourceforge.phpeclipse.wiki.actions.mediawiki.connect.Content;
+import net.sourceforge.phpeclipse.wiki.actions.mediawiki.connect.MediaWikiConnector;
+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.IConfiguration;
+import net.sourceforge.phpeclipse.wiki.preferences.Util;
+import net.sourceforge.phpeclipse.wiki.velocity.EditorText;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.window.Window;
+import org.eclipse.ui.IEditorActionDelegate;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.eclipse.ui.internal.dialogs.ListContentProvider;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+
+public class StoreWikipediaAction implements IEditorActionDelegate {
+
+ private AbstractTextEditor fEditor;
+
+ private EditorText text;
+
+ private IWorkbenchWindow window;
+
+ public void dispose() {
+ }
+
+ public String generateUrl(Configuration config, String template, String wikiname) {
+
+ /* first, we init the runtime engine. Defaults are fine. */
+
+ try {
+ Velocity.init();
+
+ /* lets make a Context and put data into it */
+
+ VelocityContext context = new VelocityContext();
+
+ context.put("config", config);
+ text.clear();
+ text.setWikiname(wikiname);
+ context.put("text", text);
+
+ /* lets make our own string to render */
+ StringWriter w = new StringWriter();
+ w = new StringWriter();
+ Velocity.evaluate(context, w, "mystring", template);
+ return w.toString();
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return template;
+ }
+
+ protected Configuration getConfiguration() {
+ List allConfigsList = ConfigurationManager.getInstance().getConfigurations();
+ ArrayList configsList = new ArrayList();
+ for (int i = 0; i < allConfigsList.size(); i++) {
+ IConfiguration temp = (IConfiguration) allConfigsList.get(i);
+ if (temp.getType().equals(WikiEditorPlugin.WIKIPEDIA_SET_TEXT)) {
+ configsList.add(temp);
+ }
+ }
+ Collections.sort(configsList);
+ Configuration configuration = null;
+ ListSelectionDialog listSelectionDialog = new ListSelectionDialog(WikiEditorPlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getShell(), configsList, new ListContentProvider(), new LabelProvider(),
+ "Select the refresh URL.");
+ listSelectionDialog.setTitle("Multiple active configuration found");
+ if (listSelectionDialog.open() == Window.OK) {
+ Object[] locations = listSelectionDialog.getResult();
+ if (locations != null) {
+ for (int i = 0; i < locations.length; i++) {
+ configuration = (Configuration) locations[i];
+ break;
+ }
+ }
+ }
+ return configuration;
+ }
+
+ public IDocument getDocument() {
+ IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
+ return doc;
+ }
+
+ private String getWikiFile(IFile file) {
+ return Util.getFileWikiName(file, WikiEditorPlugin.HTML_OUTPUT_PATH);
+ }
+
+ public void init(IWorkbenchWindow window) {
+ this.window = window;
+ }
+
+ void openWikiFile(IFile cfile) {
+ String wikiName = getWikiFile(cfile);
+ try {
+ if (fEditor != null) {
+ selectWiki(wikiName);
+ }
+ } catch (Exception e) {
+ }
+
+ }
+
+ public void openWikiLinkOnSelection() {
+ IDocument doc = getDocument();
+ ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
+ int pos = selection.getOffset();
+ IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput();
+ openWikiFile(ei.getFile());
+ }
+
+ public void run(IAction action) {
+ if (fEditor == null) {
+ IEditorPart targetEditor = window.getActivePage().getActiveEditor();
+ if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
+ fEditor = (AbstractTextEditor) targetEditor;
+ }
+ }
+ if (fEditor != null) {
+ openWikiLinkOnSelection();
+ }
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if (selection.isEmpty()) {
+ return;
+ }
+ if (selection instanceof TextSelection) {
+ action.setEnabled(true);
+ return;
+ }
+ if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) {
+ action.setEnabled(window.getActivePage().getActivePart().getClass().equals(WikiEditor.class));
+ }
+ }
+
+ private void selectWiki(String wikiName) {
+ Configuration configuration = getConfiguration();
+ if (configuration != null && !configuration.equals("")) {
+ try {
+ IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
+ String url = generateUrl(configuration, configuration.getURL(), wikiName);
+ IWikipedia w = WikipediaDE.getInstance();
+ MediaWikiConnector connector = new MediaWikiConnector();
+ Date d = new Date();
+
+ Content content = new Content(String.valueOf(d.getTime()), doc.get());
+ boolean success = connector.login(w, configuration.getURL(), configuration.getUser(), configuration.getPassword(), false);
+ if (success) {
+ connector.store(w, configuration.getURL(), wikiName, content, "", false, false);
+ connector.logout(w, configuration.getURL());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ WikiEditorPlugin.getDefault()
+ .reportError("Exception occured", e.getMessage() + "\nSee stacktrace in /.metadata/.log file.");
+ }
+ }
+ }
+
+ public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+ if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
+ fEditor = (AbstractTextEditor) targetEditor;
+ text = new EditorText(targetEditor);
+ }
+ }
+}
\ No newline at end of file