X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fpage%2FImagePage.php;h=76ff41bc3699ddc6837c3784773feb9f5b68909f;hb=c8e482371407477ecd4f0a1b5778e565d3963a93;hp=b870831e5fba3ecd68889d748284bd7ac5a08b8b;hpb=1e8f417f3d6d648e19c03465890b58a331514362;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php index b870831e5f..76ff41bc36 100644 --- a/includes/page/ImagePage.php +++ b/includes/page/ImagePage.php @@ -285,6 +285,22 @@ class ImagePage extends Article { return parent::getContentObject(); } + private function getLanguageForRendering( WebRequest $request, File $file ) { + $handler = $this->displayImg->getHandler(); + if ( !$handler ) { + return null; + } + + $requestLanguage = $request->getVal( 'lang' ); + if ( !is_null( $requestLanguage ) ) { + if ( $handler->validateParam( 'lang', $requestLanguage ) ) { + return $requestLanguage; + } + } + + return $handler->getDefaultRenderLanguage( $this->displayImg ); + } + protected function openShowImage() { global $wgEnableUploads, $wgSend404Code, $wgSVGMaxSize; @@ -309,14 +325,9 @@ class ImagePage extends Article { $params = [ 'page' => $page ]; } - $renderLang = $request->getVal( 'lang' ); + $renderLang = $this->getLanguageForRendering( $request, $this->displayImg ); if ( !is_null( $renderLang ) ) { - $handler = $this->displayImg->getHandler(); - if ( $handler && $handler->validateParam( 'lang', $renderLang ) ) { - $params['lang'] = $renderLang; - } else { - $renderLang = null; - } + $params['lang'] = $renderLang; } $width_orig = $this->displayImg->getWidth( $page ); @@ -544,12 +555,7 @@ EOT $renderLangOptions = $this->displayImg->getAvailableLanguages(); if ( count( $renderLangOptions ) >= 1 ) { - $currentLanguage = $renderLang; - $defaultLang = $this->displayImg->getDefaultRenderLanguage(); - if ( is_null( $currentLanguage ) ) { - $currentLanguage = $defaultLang; - } - $out->addHTML( $this->doRenderLangOpt( $renderLangOptions, $currentLanguage, $defaultLang ) ); + $out->addHTML( $this->doRenderLangOpt( $renderLangOptions, $renderLang ) ); } // Add cannot animate thumbnail warning @@ -621,8 +627,8 @@ EOT /** * Make the text under the image to say what size preview * - * @param $params array parameters for thumbnail - * @param $sizeLinkBigImagePreview HTML for the current size + * @param array $params parameters for thumbnail + * @param string $sizeLinkBigImagePreview HTML for the current size * @return string HTML output */ private function getThumbPrevText( $params, $sizeLinkBigImagePreview ) { @@ -963,7 +969,7 @@ EOT $fromSrc = $this->getContext()->msg( 'shared-repo-from', $file->getRepo()->getDisplayName() - )->text(); + )->escaped(); } $out->addHTML( "
  • {$link} {$fromSrc}
  • \n" ); } @@ -1047,60 +1053,31 @@ EOT * Output a drop-down box for language options for the file * * @param array $langChoices Array of string language codes - * @param string $curLang Language code file is being viewed in. - * @param string $defaultLang Language code that image is rendered in by default + * @param string $renderLang Language code for the language we want the file to rendered in. * @return string HTML to insert underneath image. */ - protected function doRenderLangOpt( array $langChoices, $curLang, $defaultLang ) { + protected function doRenderLangOpt( array $langChoices, $renderLang ) { global $wgScript; - sort( $langChoices ); - $curLang = wfBCP47( $curLang ); - $defaultLang = wfBCP47( $defaultLang ); $opts = ''; - $haveCurrentLang = false; - $haveDefaultLang = false; - - // We make a list of all the language choices in the file. - // Additionally if the default language to render this file - // is not included as being in this file (for example, in svgs - // usually the fallback content is the english content) also - // include a choice for that. Last of all, if we're viewing - // the file in a language not on the list, add it as a choice. + + $matchedRenderLang = $this->displayImg->getMatchedLanguage( $renderLang ); + foreach ( $langChoices as $lang ) { - $code = wfBCP47( $lang ); - $name = Language::fetchLanguageName( $code, $this->getContext()->getLanguage()->getCode() ); - if ( $name !== '' ) { - $display = $this->getContext()->msg( 'img-lang-opt', $code, $name )->text(); - } else { - $display = $code; - } - $opts .= "\n" . Xml::option( $display, $code, $curLang === $code ); - if ( $curLang === $code ) { - $haveCurrentLang = true; - } - if ( $defaultLang === $code ) { - $haveDefaultLang = true; - } - } - if ( !$haveDefaultLang ) { - // Its hard to know if the content is really in the default language, or - // if its just unmarked content that could be in any language. - $opts = Xml::option( - $this->getContext()->msg( 'img-lang-default' )->text(), - $defaultLang, - $defaultLang === $curLang - ) . $opts; - } - if ( !$haveCurrentLang && $defaultLang !== $curLang ) { - $name = Language::fetchLanguageName( $curLang, $this->getContext()->getLanguage()->getCode() ); - if ( $name !== '' ) { - $display = $this->getContext()->msg( 'img-lang-opt', $curLang, $name )->text(); - } else { - $display = $curLang; - } - $opts = Xml::option( $display, $curLang, true ) . $opts; + $opts .= $this->createXmlOptionStringForLanguage( + $lang, + $matchedRenderLang === $lang + ); } + // Allow for the default case in an svg that is displayed if no + // systemLanguage attribute matches + $opts .= "\n" . + Xml::option( + $this->getContext()->msg( 'img-lang-default' )->text(), + 'und', + is_null( $matchedRenderLang ) + ); + $select = Html::rawElement( 'select', [ 'id' => 'mw-imglangselector', 'name' => 'lang' ], @@ -1119,6 +1096,27 @@ EOT return $langSelectLine; } + /** + * @param $lang string + * @param $selected bool + * @return string + */ + private function createXmlOptionStringForLanguage( $lang, $selected ) { + $code = LanguageCode::bcp47( $lang ); + $name = Language::fetchLanguageName( $code, $this->getContext()->getLanguage()->getCode() ); + if ( $name !== '' ) { + $display = $this->getContext()->msg( 'img-lang-opt', $code, $name )->text(); + } else { + $display = $code; + } + return "\n" . + Xml::option( + $display, + $lang, + $selected + ); + } + /** * Get the width and height to display image at. *