Index: applications/editors/josm/plugins/tag2link/resources/tag2link_sources.xml
===================================================================
--- applications/editors/josm/plugins/tag2link/resources/tag2link_sources.xml	(revision 26920)
+++ applications/editors/josm/plugins/tag2link/resources/tag2link_sources.xml	(revision 26921)
@@ -31,13 +31,13 @@
        </rule>
     </source>
-	
-	<source name="Wikipedia">
-	   <rule>
-	       <condition k="wikipedia(?::([\p{Lower}]{2,}))?" />
-           <link name="View %name% article" href="http://%k.1:en%.wikipedia.org/wiki/%v%" />
-	   </rule>
-	</source>
-	
-	<!-- Only for France -->
+    
+    <source name="Wikipedia">
+       <rule>
+           <condition k="wikipedia(?::([\p{Lower}]{2,}))?" v="(?:([\p{Lower}]{2,}):)?(.*)" />
+           <link name="View %name% article" href="http://%k.1:v.1:en%.wikipedia.org/wiki/%v.2:v.1%" />
+       </rule>
+    </source>
+    
+    <!-- Only for France -->
     
     <source name="SANDRE" country-code="FR">
Index: applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkConstants.java
===================================================================
--- applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkConstants.java	(revision 26920)
+++ applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkConstants.java	(revision 26921)
@@ -31,5 +31,5 @@
 	 * File encoding.
 	 */
-	public static final String ENCODING = "UTF-8";
+	public static final String UTF8_ENCODING = "UTF-8";
 	
 	/**
Index: applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java
===================================================================
--- applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java	(revision 26920)
+++ applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java	(revision 26921)
@@ -16,8 +16,12 @@
 package org.openstreetmap.josm.plugins.tag2link;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.IPrimitive;
 import org.openstreetmap.josm.plugins.tag2link.data.Link;
 import org.openstreetmap.josm.plugins.tag2link.data.Rule;
@@ -40,5 +44,14 @@
     }
     
-    public static Collection<Link> getLinks(OsmPrimitive p) {
+    private static String findValue(String arg, Collection<MatchingTag> matchingTags) {
+		for (MatchingTag tag : matchingTags) {
+			if (tag.params.containsKey(arg)) {
+				return tag.params.get(arg);
+			}
+		}
+		return null;
+    }
+    
+    public static Collection<Link> getLinks(IPrimitive p) {
         Collection<Link> result = new ArrayList<Link>();
         for (Source source : sources) {
@@ -49,7 +62,37 @@
                     	Link copy = new Link(link);
                     	copy.name = copy.name.replaceAll("%name%", source.name);
-                    	MatchingTag firstTag = eval.matchingTags.iterator().next();
-                    	copy.url = copy.url.replaceAll("%k%", firstTag.key)
-                    			           .replaceAll("%v%", firstTag.value);
+						Matcher m = Pattern.compile("%([^%]*)%").matcher(copy.url);
+						while (m.find()) {
+							String arg = m.group(1);
+							String val = findValue(arg, eval.matchingTags);
+							if (val == null && arg.contains(":")) {
+								String[] vars = arg.split(":");
+								for (int i = 0; val == null && i < vars.length-1; i++) {
+									val = findValue(vars[i], eval.matchingTags);
+								}
+								if (val == null) {
+									// Default value
+									val = vars[vars.length-1];
+								}
+							}
+							if (val != null) {
+								try {
+									// Special hack for Wikipedia that prevents spaces being replaced by "+" characters, but by "_"
+									if (copy.url.contains("wikipedia.")) {
+										val = val.replaceAll(" ", "_");
+									}
+									// Encode param to be included in the URL, except if it is the URL itself !
+									if (!m.group().equals(copy.url)) {
+										val = URLEncoder.encode(val, UTF8_ENCODING);
+									}
+									// Finally replace parameter
+									copy.url = copy.url.replaceFirst(m.group(), val);
+								} catch (UnsupportedEncodingException e) {
+									e.printStackTrace();
+								}
+							} else {
+								System.err.println("Invalid argument: "+arg);
+							}
+						}
                     	result.add(copy);
                     }
Index: applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/action/OpenLinkAction.java
===================================================================
--- applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/action/OpenLinkAction.java	(revision 26920)
+++ applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/action/OpenLinkAction.java	(revision 26921)
@@ -16,5 +16,5 @@
     
     public OpenLinkAction(Link link) {
-        super(tr(link.name), ICON_24, tr("Launch browser with information about the selected object"), null, true);
+        super(tr(link.name), ICON_24, tr("Launch browser with information about the selected object"), null, false);
         this.url = link.url;
     }
@@ -22,4 +22,5 @@
     @Override
     public void actionPerformed(ActionEvent e) {
+    	System.out.println("Opening "+url);
         OpenBrowser.displayUrl(url);
     }
Index: applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Rule.java
===================================================================
--- applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Rule.java	(revision 26920)
+++ applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Rule.java	(revision 26921)
@@ -7,5 +7,5 @@
 import java.util.regex.Matcher;
 
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.IPrimitive;
 
 public class Rule {
@@ -16,13 +16,25 @@
         public String key;
         public String value;
-        public final Map<String, String> params = new HashMap<String, String>();
-        public MatchingTag(String key, String value) {
+        public final Map<String, String> params;
+        private String prefix;
+        public MatchingTag(String key, String value, String prefix) {
         	this.key = key;
         	this.value = value;
+        	this.params = new HashMap<String, String>();
+        	this.prefix = prefix;
+        	addKeyValueParams();
         }
-        public void addParams(Matcher m, String prefix) {
+        public void addParams(Matcher m, String paramName) {
     		for (int i = 1; i<=m.groupCount(); i++) {
-    			this.params.put(prefix+i, m.group(i));
+    			params.put(prefix+paramName+"."+i, m.group(i));
     		}
+        }
+        private void addKeyValueParams() {
+        	params.put("k", key);
+        	params.put("v", value);
+        	if (!prefix.isEmpty()) {
+            	params.put(prefix+"k", key);
+            	params.put(prefix+"v", value);
+        	}
         }
     }
@@ -35,5 +47,5 @@
     }
     
-    public EvalResult evaluates(OsmPrimitive p) {
+    public EvalResult evaluates(IPrimitive p) {
         EvalResult result = new EvalResult();
         Map<String, String> tags = p.getKeys();
@@ -43,11 +55,11 @@
                 if (keyMatcher.matches()) {
                 	String idPrefix = c.id == null ? "" : c.id+".";
-            		MatchingTag tag = new MatchingTag(key, tags.get(key));
-            		tag.addParams(keyMatcher, idPrefix+"k.");
+            		MatchingTag tag = new MatchingTag(key, tags.get(key), idPrefix);
+            		tag.addParams(keyMatcher, "k");
                 	boolean matchingTag = true;
                 	if (c.valPattern != null) {
                 		Matcher valMatcher = c.valPattern.matcher(tag.value);
                 		if (valMatcher.matches()) {
-                			tag.addParams(valMatcher, idPrefix+"v.");
+                			tag.addParams(valMatcher, "v");
                 		} else {
                 			matchingTag = false;
Index: applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/io/SourcesReader.java
===================================================================
--- applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/io/SourcesReader.java	(revision 26920)
+++ applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/io/SourcesReader.java	(revision 26921)
@@ -37,5 +37,5 @@
         try {
             InputStream is = SourcesReader.class.getResourceAsStream(XML_LOCATION);
-            InputStreamReader ir = UTFInputStreamReader.create(is, ENCODING);
+            InputStreamReader ir = UTFInputStreamReader.create(is, UTF8_ENCODING);
             XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ir);
             result.addAll(new SourcesReader(parser).parseDoc());
Index: applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/AbstractIPrimitivePopupListener.java
===================================================================
--- applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/AbstractIPrimitivePopupListener.java	(revision 26921)
+++ applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/AbstractIPrimitivePopupListener.java	(revision 26921)
@@ -0,0 +1,44 @@
+//    JOSM tag2link plugin.
+//    Copyright (C) 2011 Don-vip & FrViPofm
+//
+//    This program is free software: you can redistribute it and/or modify
+//    it under the terms of the GNU General Public License as published by
+//    the Free Software Foundation, either version 3 of the License, or
+//    (at your option) any later version.
+//
+//    This program is distributed in the hope that it will be useful,
+//    but WITHOUT ANY WARRANTY; without even the implied warranty of
+//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//    GNU General Public License for more details.
+//
+//    You should have received a copy of the GNU General Public License
+//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+package org.openstreetmap.josm.plugins.tag2link.listeners;
+
+import javax.swing.JPopupMenu;
+import javax.swing.event.PopupMenuEvent;
+
+import org.openstreetmap.josm.data.osm.IPrimitive;
+import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.plugins.tag2link.Tag2LinkRuleChecker;
+import org.openstreetmap.josm.plugins.tag2link.data.Link;
+
+public abstract class AbstractIPrimitivePopupListener extends AbstractPopupListener {
+
+    protected AbstractIPrimitivePopupListener(MapFrame frame) {
+        super(frame);
+    }
+
+    protected abstract IPrimitive getFirstSelectedPrimitive();
+    
+    @Override
+    public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
+        IPrimitive p = getFirstSelectedPrimitive();
+        if (p != null) {
+            JPopupMenu popup = (JPopupMenu) e.getSource();
+            for (Link link : Tag2LinkRuleChecker.getLinks(p)) {
+                addLink(popup, link);
+            }
+        }
+    }
+}
Index: applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/AbstractOsmPrimitivePopupListener.java
===================================================================
--- applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/AbstractOsmPrimitivePopupListener.java	(revision 26920)
+++ 	(revision )
@@ -1,44 +1,0 @@
-//    JOSM tag2link plugin.
-//    Copyright (C) 2011 Don-vip & FrViPofm
-//
-//    This program is free software: you can redistribute it and/or modify
-//    it under the terms of the GNU General Public License as published by
-//    the Free Software Foundation, either version 3 of the License, or
-//    (at your option) any later version.
-//
-//    This program is distributed in the hope that it will be useful,
-//    but WITHOUT ANY WARRANTY; without even the implied warranty of
-//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//    GNU General Public License for more details.
-//
-//    You should have received a copy of the GNU General Public License
-//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-package org.openstreetmap.josm.plugins.tag2link.listeners;
-
-import javax.swing.JPopupMenu;
-import javax.swing.event.PopupMenuEvent;
-
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.gui.MapFrame;
-import org.openstreetmap.josm.plugins.tag2link.Tag2LinkRuleChecker;
-import org.openstreetmap.josm.plugins.tag2link.data.Link;
-
-public abstract class AbstractOsmPrimitivePopupListener extends AbstractPopupListener {
-
-    protected AbstractOsmPrimitivePopupListener(MapFrame frame) {
-        super(frame);
-    }
-
-    protected abstract OsmPrimitive getFirstSelectedPrimitive();
-    
-    @Override
-    public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
-        OsmPrimitive p = getFirstSelectedPrimitive();
-        if (p != null) {
-            JPopupMenu popup = (JPopupMenu) e.getSource();
-            for (Link link : Tag2LinkRuleChecker.getLinks(p)) {
-                addLink(popup, link);
-            }
-        }
-    }
-}
Index: applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/MembershipPopupListener.java
===================================================================
--- applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/MembershipPopupListener.java	(revision 26920)
+++ applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/MembershipPopupListener.java	(revision 26921)
@@ -16,8 +16,8 @@
 package org.openstreetmap.josm.plugins.tag2link.listeners;
 
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.IPrimitive;
 import org.openstreetmap.josm.gui.MapFrame;
 
-public class MembershipPopupListener extends AbstractOsmPrimitivePopupListener {
+public class MembershipPopupListener extends AbstractIPrimitivePopupListener {
 
     public MembershipPopupListener(MapFrame frame) {
@@ -26,7 +26,6 @@
 
     @Override
-    protected OsmPrimitive getFirstSelectedPrimitive() {
-        // TODO Auto-generated method stub
-        return null;
+    protected IPrimitive getFirstSelectedPrimitive() {
+        return frame.propertiesDialog.getSelectedMembershipRelations().iterator().next();
     }
 }
Index: applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/RelationPopupListener.java
===================================================================
--- applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/RelationPopupListener.java	(revision 26920)
+++ applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/RelationPopupListener.java	(revision 26921)
@@ -16,8 +16,8 @@
 package org.openstreetmap.josm.plugins.tag2link.listeners;
 
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.IPrimitive;
 import org.openstreetmap.josm.gui.MapFrame;
 
-public class RelationPopupListener extends AbstractOsmPrimitivePopupListener {
+public class RelationPopupListener extends AbstractIPrimitivePopupListener {
 
     public RelationPopupListener(MapFrame frame) {
@@ -26,5 +26,5 @@
 
     @Override
-    protected OsmPrimitive getFirstSelectedPrimitive() {
+    protected IPrimitive getFirstSelectedPrimitive() {
         return frame.relationListDialog.getSelectedRelations().iterator().next();
     }
Index: applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/SelectionPopupListener.java
===================================================================
--- applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/SelectionPopupListener.java	(revision 26920)
+++ applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/SelectionPopupListener.java	(revision 26921)
@@ -16,8 +16,8 @@
 package org.openstreetmap.josm.plugins.tag2link.listeners;
 
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.IPrimitive;
 import org.openstreetmap.josm.gui.MapFrame;
 
-public class SelectionPopupListener extends AbstractOsmPrimitivePopupListener {
+public class SelectionPopupListener extends AbstractIPrimitivePopupListener {
 
     public SelectionPopupListener(MapFrame frame) {
@@ -26,5 +26,5 @@
 
     @Override
-    protected OsmPrimitive getFirstSelectedPrimitive() {
+    protected IPrimitive getFirstSelectedPrimitive() {
         return frame.selectionListDialog.getSelectedPrimitives().iterator().next();
     }
