Page MenuHomePhabricator

support CSS patch to an existing SVG
Open, Needs TriagePublicFeature

Description

Feature summary (what you would like to be able to do and where):

I would like to be able to upload a kind of file which represented a CSS patch applied to an existing SVG.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):

Commons has thousands of locator maps. Here's an example (https://commons.wikimedia.org/wiki/File:Anglesey_in_Wales.svg):

image.png (768×642 px, 117 KB)

It shows Wales, broken down into unitary authorities, with one authority (Anglesey) drawn in red and the others in cream. Each of the other authorities has another similar map. Every other country in the world, and many and various regions, have similar sets of maps.

It should be possible to produce the same effect by uploading a file containing only

  • link to existing SVG
  • CSS block
  • optional metadata

such as

<css-patch target="Some hypothetical map of Wales.svg">
    <style>
         #anglesey { color: #700; }
    </style>
</css-patch>

the result of which would be to render the given SVG with the given style block included.

Benefits (why should this be implemented?):

Saves vast amounts of redundancy, and thus avoids denormalisation.. At present, every time there's a border change, all the locator maps have to be redrawn.

I think I could implement this, but first I want to ask whether it's a good idea.

Event Timeline

Bugreporter renamed this task from Add image type which is a CSS patch to an existing SVG to support CSS patch to an existing SVG.Jan 18 2025, 1:59 AM

This seems like stretching the purpose of the file upload / media handler system a bit. Some wikitext syntax would probably be a better way of adding arbitrary CSS to an SVG file? Maybe Charts or TemplateStyles could incorporate that.

Some wikitext syntax would probably be a better way of adding arbitrary CSS to an SVG file?

I see the point. I am concerned, though, that the CSS involved would be duplicated across the Template namespaces of every wiki that used the map, which would produce another instance of the denormalisation problem we're trying to solve.

A further thought:

Allowing arbitrary CSS is a (potential) security hole. It will also make the names of rendered files complex even for short amounts of CSS.

What if we simply work from a class son the root note of the SVG? Here's an example of what I mean:

The CSS in this file says simply

.regions path {
    fill: #fdfcea;
}

svg.anglesey .regions path#anglesey {
    fill: #770000;
}

So, regions should be cream-coloured *unless* it's the region id="anglesey" and the class="anglesey" property is set on the root svg node. Try taking it off.

This would allow some sort of machine-readable list of regions in the file, and a tool to choose which properties to set on the root node.

Thoughts?