resourceloader: Avoid unnecessary xmlns attributes in ResourceLoaderImage
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 15 Jan 2019 19:43:35 +0000 (20:43 +0100)
committerVolkerE <volker.e@wikimedia.org>
Wed, 16 Jan 2019 02:22:45 +0000 (02:22 +0000)
We were creating the `<g>` element without specifying a namespace,
which caused the library to add `xmlns` attributes with the document's
default SVG namespace to elements that we appended underneath it.
(At least, that's what I think was happening.)

Specify the SVG namespace when creating it to avoid the mess and
reduce resulting file size.

Change-Id: Ida27494aeae9dece16f878c16cf9aa582e6deac3

includes/resourceloader/ResourceLoaderImage.php
tests/phpunit/data/resourceloader/def_variantize.svg

index b15efae..8cd5b19 100644 (file)
@@ -296,7 +296,7 @@ class ResourceLoaderImage {
                $dom->loadXML( file_get_contents( $this->getPath( $context ) ) );
                $root = $dom->documentElement;
                $titleNode = null;
-               $wrapper = $dom->createElement( 'g' );
+               $wrapper = $dom->createElementNS( 'http://www.w3.org/2000/svg', 'g' );
                // Reattach all direct children of the `<svg>` root node to the `<g>` wrapper
                while ( $root->firstChild ) {
                        $node = $root->firstChild;
index 009d805..641bb78 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
-<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><default:title xmlns:default="http://www.w3.org/2000/svg">remove</default:title><g fill="red">
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><title>remove</title><g fill="red">
     
-    <g xmlns:default="http://www.w3.org/2000/svg" id="remove">
+    <g id="remove">
         <path id="trash-can" d="M12 10h-1v6h1v-6zm-2 0h-1v6h1v-6zm4 0h-1v6h1v-6zm0-4v-1h-5v1h-3v3h1v7.966l1 1.031v-.074.077h6.984l.016-.018v.015l1-1.031v-7.966h1v-3h-3zm1 11h-7v-8h7v8zm1-9h-9v-1h9v1z"/>
     </g>
 </g></svg>