From: axelcl Date: Sat, 8 Jan 2005 18:56:07 +0000 (+0000) Subject: Implemeted action for uploading Wikipedia articles (thanks to D.Wunsch) X-Git-Url: http://secure.phpeclipse.com Implemeted action for uploading Wikipedia articles (thanks to D.Wunsch) Problems: - timestamp is used wrong at the moment; - wiki locale not configurable by users at the moment --- 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 a45c2a3..bbfd7a7 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 @@ -1,7 +1,13 @@ 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; 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 4f0a86c..6d1d966 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,4 +1,9 @@ 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; 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 81ca70b..cdbff14 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 @@ -1,11 +1,16 @@ 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; @@ -16,15 +21,7 @@ import net.sourceforge.phpeclipse.wiki.velocity.EditorText; 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; @@ -38,7 +35,6 @@ 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.internal.ide.IDEWorkbenchPlugin; import org.eclipse.ui.texteditor.AbstractTextEditor; public class DownloadWikipediaAction implements IEditorActionDelegate { @@ -49,55 +45,7 @@ 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 createFolder. - * - * @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 = ""; - byte[] buffer = newText.getBytes(); - ByteArrayInputStream source = new ByteArrayInputStream(buffer); - file.create(source, true, null); - } + public void dispose() { } 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 33cc554..b1f7b54 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,4 +1,9 @@ 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; 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 deleted file mode 100644 index 2db9f21..0000000 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/MediaWikiConnector.java +++ /dev/null @@ -1,178 +0,0 @@ -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 MediaWikiConnector.java - */ -public class MediaWikiConnector { - - /** - * Get the text of a wikimedia Wiki-Description from en.wikipedia.org - * - */ - 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("", start + 1); - if (start != (-1)) { - int end = wikiText.indexOf(""); - 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 - } -} - diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/AbstractWikipedia.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/AbstractWikipedia.java new file mode 100644 index 0000000..d793be7 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/AbstractWikipedia.java @@ -0,0 +1,135 @@ +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 diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/IWikipedia.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/IWikipedia.java new file mode 100644 index 0000000..4d95cb8 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/IWikipedia.java @@ -0,0 +1,78 @@ +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 diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikiProperties.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikiProperties.java new file mode 100644 index 0000000..2ea10d1 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikiProperties.java @@ -0,0 +1,56 @@ +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 diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikiPropertiesDE.properties b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikiPropertiesDE.properties new file mode 100644 index 0000000..a377c11 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikiPropertiesDE.properties @@ -0,0 +1,13 @@ +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.* diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikiPropertiesEN.properties b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikiPropertiesEN.properties new file mode 100644 index 0000000..6cbff3d --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikiPropertiesEN.properties @@ -0,0 +1,13 @@ +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.* diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikipediaDE.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikipediaDE.java new file mode 100644 index 0000000..2ff3d0b --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikipediaDE.java @@ -0,0 +1,36 @@ +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 diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikipediaEN.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikipediaEN.java new file mode 100644 index 0000000..d63d445 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/config/WikipediaEN.java @@ -0,0 +1,35 @@ +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 diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/MethodException.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/MethodException.java new file mode 100644 index 0000000..021ed3f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/MethodException.java @@ -0,0 +1,33 @@ +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(); + } +} diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/NetworkException.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/NetworkException.java new file mode 100644 index 0000000..0390903 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/NetworkException.java @@ -0,0 +1,29 @@ +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); + } +} diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/PageNotEditableException.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/PageNotEditableException.java new file mode 100644 index 0000000..1b334df --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/PageNotEditableException.java @@ -0,0 +1,33 @@ +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); + } +} diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UnexpectedAnswerException.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UnexpectedAnswerException.java new file mode 100644 index 0000000..448db4b --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UnexpectedAnswerException.java @@ -0,0 +1,33 @@ +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(); + } +} diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UnsupportedURLException.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UnsupportedURLException.java new file mode 100644 index 0000000..b1331cc --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UnsupportedURLException.java @@ -0,0 +1,33 @@ +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); + } +} diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UnsupportedWikiException.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UnsupportedWikiException.java new file mode 100644 index 0000000..856d4e8 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UnsupportedWikiException.java @@ -0,0 +1,32 @@ +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); + } +} diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UploadForbiddenException.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UploadForbiddenException.java new file mode 100644 index 0000000..991b282 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/exceptions/UploadForbiddenException.java @@ -0,0 +1,34 @@ +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); + } +} diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/StoreWikipediaAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/StoreWikipediaAction.java new file mode 100644 index 0000000..3d3ad4f --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/StoreWikipediaAction.java @@ -0,0 +1,199 @@ +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