Brian Wolff has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/91784


Change subject: Extract list of languages svg is translated into.
......................................................................

Extract list of languages svg is translated into.

SVG files support having different renderings based on language.
We support changing the rendering language, but we offer no
discoverability of what languages are available.

Long term Jarry's TranslateSVG will hopefully be used and have
all the associated awesomeness. In the mean time, we should
probably have some indication on the image page what languages
are available for the SVG. This is step 1 (extract the language).
I expect to follow this up with a commit adding some sort of
simple selector on the image page.

As an aside, it should be noted, this only detects languages
if its in the first $wgSVGMetadataCutoff (256 kb). This is a
compromise to avoid OOM on huge SVG files.

Change-Id: I2a462270fe63eb3e3023419eddc8b06f5a617ab5
---
M includes/media/SVGMetadataExtractor.php
1 file changed, 18 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/84/91784/1

diff --git a/includes/media/SVGMetadataExtractor.php 
b/includes/media/SVGMetadataExtractor.php
index 2e33bb9..9d6c8e1 100644
--- a/includes/media/SVGMetadataExtractor.php
+++ b/includes/media/SVGMetadataExtractor.php
@@ -164,10 +164,8 @@
                        } elseif ( $tag !== '#text' ) {
                                $this->debug( "Unhandled top-level XML tag 
$tag" );
 
-                               if ( !isset( $this->metadata['animated'] ) ) {
-                                       // Recurse into children of current 
tag, looking for animation.
-                                       $this->animateFilter( $tag );
-                               }
+                               // Recurse into children of current tag, 
looking for animation and languages.
+                               $this->animateFilterAndLang( $tag );
                        }
 
                        // Goto next element, which is sibling of current (Skip 
children).
@@ -222,11 +220,13 @@
        }
 
        /**
-        * Filter all children, looking for animate elements
+        * Filter all children, looking for animated elements.
+        * Also get a list of languages that can be targeted.
         *
         * @param string $name of the element that we are reading from
         */
-       private function animateFilter( $name ) {
+       private function animateFilterAndLang( $name ) {
+               $languages = array();
                $this->debug( "animate filter for tag $name" );
                if ( $this->reader->nodeType != XmlReader::ELEMENT ) {
                        return;
@@ -241,6 +241,17 @@
                                && $this->reader->nodeType == 
XmlReader::END_ELEMENT ) {
                                break;
                        } elseif ( $this->reader->namespaceURI == self::NS_SVG 
&& $this->reader->nodeType == XmlReader::ELEMENT ) {
+
+                               $sysLang = $this->reader->getAttribute( 
'systemLanguage' );
+                               if ( !is_null( $sysLang ) && $sysLang !== '' ) {
+                                       // See 
http://www.w3.org/TR/SVG/struct.html#SystemLanguageAttribute
+                                       $langList = explode( ',', $sysLang );
+                                       foreach( $langList as $langItem ) {
+                                               if ( 
Language::isWellFormedLanguageTag( $langItem ) ) {
+                                                       $languages[$langItem] = 
true;
+                                               }
+                                       }
+                               }
                                switch ( $this->reader->localName ) {
                                        case 'script':
                                                // Normally we disallow files 
with
@@ -259,6 +270,7 @@
                        }
                        $keepReading = $this->reader->read();
                }
+               $this->metadata['translations'] = array_keys( $languages );
        }
 
        private function throwXmlError( $err ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/91784
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a462270fe63eb3e3023419eddc8b06f5a617ab5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to