Treat langtags in SVG switch case-insensitively
authorCormac Parle <cparle@wikimedia.org>
Wed, 18 Oct 2017 12:38:48 +0000 (13:38 +0100)
committerCormac Parle <cparle@wikimedia.org>
Fri, 10 Nov 2017 09:14:42 +0000 (09:14 +0000)
commitf6620e2a7576b81ac5d3ca2f598746d1bc70c887
tree3c7f1b7b29f7e93990178462b2ad3487df6c0784
parent6624df922627d1376b28f024fe189ab522f6a13a
Treat langtags in SVG switch case-insensitively

See https://tools.ietf.org/html/bcp47#section-2.1.1

Also implement matching of systemLanguage attribs as
specified in the SVG spec

Note that librsvg that we use for rendering pngs of svg
files has a bug, and matches languages in the following
way instead of what is implemented in SVG::getMatchedLanguage()

public function getMatchedLanguage( $userPreferredLanguage, array $svgLanguages ) {
  foreach ( $svgLanguages as $svgLang ) {
    if ($svgLang == $userPreferredLanguage) {
      return $svgLang;
    }
    $dashPosition = strpos( $userPreferredLanguage, '-' );
    if ( $dashPosition !== false ) {
      if (
        strtolower( substr( $svgLang, 0, $dashPosition ) ) ==
        strtolower( substr( $userPreferredLanguage, 0, $dashPosition ) )
      ) {
        return $svgLang;
      }
    }
    return null;
}

Bug: T154132
Change-Id: Ibff66a0844f0cecfae0260c6a7d20aeedc2849a2
includes/filerepo/file/File.php
includes/media/SVG.php
includes/page/ImagePage.php
tests/parser/parserTests.txt
tests/phpunit/includes/media/SVGTest.php