Index: src/org/openstreetmap/josm/tools/ImageProvider.java
===================================================================
--- src/org/openstreetmap/josm/tools/ImageProvider.java	(Revision 3995)
+++ src/org/openstreetmap/josm/tools/ImageProvider.java	(Arbeitskopie)
@@ -15,6 +15,7 @@
 import java.awt.Toolkit;
 import java.awt.Transparency;
 import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -34,6 +35,13 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
 import org.openstreetmap.josm.io.MirroredInputStream;
 import org.openstreetmap.josm.plugins.PluginHandler;
+import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.helpers.XMLReaderFactory;
 
 /**
  * Helperclass to support the application with images.
@@ -79,8 +87,8 @@
         if (icon == null) {
             String ext = name.indexOf('.') != -1 ? "" : ".png";
             throw new NullPointerException(tr(
-            "Fatal: failed to locate image ''{0}''. This is a serious configuration problem. JOSM will stop working.",
-            name+ext));
+                    "Fatal: failed to locate image ''{0}''. This is a serious configuration problem. JOSM will stop working.",
+                    name+ext));
         }
         return icon;
     }
@@ -119,16 +127,98 @@
      *                  around certain issues.
      */
     public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, boolean sanitize) {
-        ImageWrapper iw = getIfAvailableImpl(dirs, id, subdir, name, archive);
-        if (iw == null)
-            return null;
-        if (sanitize && !iw.sanitized) {
-            iw.img = sanitize(iw.img);
-            iw.sanitized = true;
+        ImageIcon icon = new ImageIcon();
+        if (name.matches("^wiki(:[0-9]+)?://.*")) {
+            getIfAvailableWikiImpl(icon, dirs, id, name, sanitize);
+        } else {
+            ImageWrapper iw = getIfAvailableImpl(dirs, id, subdir, name, archive);
+            if (iw == null)
+                return null;
+            if (sanitize && !iw.sanitized) {
+                iw.img = sanitize(iw.img);
+                iw.sanitized = true;
+            }
+            icon.setImage(iw.img);
         }
-        return new ImageIcon(iw.img);
+        return icon;
     }
 
+    private static void getIfAvailableWikiImpl(final ImageIcon icon, Collection<String> dirs, String id, final String name, final boolean sanitize) {
+        ImageWrapper iw = cache.get(name);
+        if (iw != null) {
+            icon.setImage(iw.img);
+        } else {
+            // do not return null, since we will loose control over the icon object else
+            icon.setImage(getIfAvailable(dirs, id, null, "misc/no_icon.png", null, sanitize).getImage());
+
+            Main.worker.execute(new Runnable(){
+                public void run() {
+                    try {
+                        final String base = Main.pref.get("url.openstreetmap-wiki", "http://wiki.openstreetmap.org/wiki/File:");
+                        final String fn = name.substring(name.lastIndexOf('/') + 1);
+
+                        final XMLReader parser = XMLReaderFactory.createXMLReader();
+                        parser.setContentHandler(new DefaultHandler() {
+                            @Override
+                            public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+                                System.out.println();
+                                if (localName.equalsIgnoreCase("img")) {
+                                    String val = atts.getValue("src");
+                                    if (val.endsWith(fn)) {
+                                        try {
+                                            // mirror just the unscaled image..
+                                            MirroredInputStream is = new MirroredInputStream(val, new File(Main.pref.getPreferencesDir(),
+                                            "images").toString());
+
+                                            Image img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL());
+                                            int width = 0;
+                                            try {
+                                                // this allows definition of custom sizes via the icon-image url
+                                                width = Integer.parseInt(name.replaceFirst("^wiki:([0-9]+)?.*", "$1"));
+                                            } catch (Exception e) {
+                                                // use a default if left empty (e.g. wiki://Signet_Cycleroute.png)
+                                                width = 20;
+                                            }
+                                            img = img.getScaledInstance(width, -1, Image.SCALE_SMOOTH);
+
+                                            if (sanitize) {
+                                                img = sanitize(img);
+                                            }
+
+                                            // ..but put the scaled image into the cache
+                                            cache.put(name, new ImageWrapper(img, sanitize));
+
+                                            // finally, update the icon image that up to now displayed "no_icon"
+                                            icon.setImage(img);
+
+                                            throw new SAXException(); // done parsing, quit early
+                                        } catch (IOException e) {
+                                            System.out.println("INFO: fetching " + base + fn + "failed");
+                                        }
+                                    }
+                                }
+                            }
+                        });
+
+                        parser.setEntityResolver(new EntityResolver() {
+                            public InputSource resolveEntity (String publicId, String systemId) {
+                                return new InputSource(new ByteArrayInputStream(new byte[0]));
+                            }
+                        });
+                        parser.parse(new InputSource(new MirroredInputStream(
+                                base + fn,
+                                new File(Main.pref.getPreferencesDir(), "images").toString()
+                        )));
+                    } catch (Exception e) {
+                        if (!(e instanceof SAXException)) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
+            });
+        }
+    }
+
     private static ImageWrapper getIfAvailableImpl(Collection<String> dirs, String id, String subdir, String name, File archive) {
         if (name == null)
             return null;
