);
}
+ $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 ) );
+ }
+
// Add cannot animate thumbnail warning
if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
// Include the extension so wiki admins can
? $wgImageLimits[$option]
: array( 800, 600 ); // if nothing is set, fallback to a hardcoded default
}
+
+ /**
+ * 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
+ * @return String HTML to insert underneath image.
+ */
+ protected function doRenderLangOpt( array $langChoices, $curLang, $defaultLang ) {
+ 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.
+ foreach ( $langChoices as $lang ) {
+ $code = wfBCP47( $lang );
+ $name = Language::fetchLanguageName( $code, $this->getContext()->getLanguage()->getCode() );
+ if ( $name !== '' ) {
+ $display = wfMessage( '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( wfMessage( 'img-lang-default' )->text(), '', $defaultLang === $curLang ) . $opts;
+ }
+ if ( !$haveCurrentLang && $defaultLang !== $curLang ) {
+ $name = Language::fetchLanguageName( $curLang, $this->getContext()->getLanguage()->getCode() );
+ if ( $name !== '' ) {
+ $display = wfMessage( 'img-lang-opt', $curLang, $name )->text();
+ } else {
+ $display = $curLang;
+ }
+ $opts = XML::Option( $display, $curLang, true ) . $opts;
+ }
+
+ $select = Html::rawElement( 'select', array( 'id' => 'mw-imglangselector', 'name' => 'lang' ), $opts );
+ $submit = Xml::submitButton( wfMessage( 'img-lang-go' )->text() );
+
+ $formContents = wfMessage( 'img-lang-info' )->rawParams( $select, $submit )->parse()
+ . Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() );
+
+ $langSelectLine = Html::rawElement( 'div', array( 'id' => 'mw-imglangselector-line' ),
+ Html::rawElement( 'form', array( 'action' => $wgScript ), $formContents )
+ );
+ return $langSelectLine;
+ }
}
/**
}
}
+ /**
+ * Gives a (possibly empty) list of languages to render
+ * the file in.
+ *
+ * If the file doesn't have translations, or if the file
+ * format does not support that sort of thing, returns
+ * an empty array.
+ *
+ * @return Array
+ * @since 1.23
+ */
+ public function getAvailableLanguages() {
+ $handler = $this->getHandler();
+ if ( $handler ) {
+ return $handler->getAvailableLanguages( $this );
+ } else {
+ return array();
+ }
+ }
+
+ /**
+ * In files that support multiple language, what is the default language
+ * to use if none specified.
+ *
+ * @return String lang code, or null if filetype doesn't support multiple languages.
+ * @since 1.23
+ */
+ public function getDefaultRenderLanguage() {
+ $handler = $this->getHandler();
+ if ( $handler ) {
+ return $handler->getDefaultRenderLanguage( $this );
+ } else {
+ return null;
+ }
+ }
+
/**
* Will the thumbnail be animated if one would expect it to be.
*
wfHostname(), $retval, $errMessage, $cmd ) );
}
+ /**
+ * Get list of languages file can be viewed in.
+ *
+ * @param File $file
+ * @return Array Array of language codes, or empty array if unsupported.
+ * @since 1.23
+ */
+ public function getAvailableLanguages( File $file ) {
+ return array();
+ }
+
+ /**
+ * On file types that support renderings in multiple languages,
+ * which language is used by default if unspecified.
+ *
+ * If getAvailableLanguages returns a non-empty array, this must return
+ * a valid language code. Otherwise can return null if files of this
+ * type do not support alternative language renderings.
+ *
+ * @param File $file
+ * @return String language code or null if multi-language not supported for filetype.
+ * @since 1.23
+ */
+ public function getDefaultRenderLanguage( File $file ) {
+ return null;
+ }
}
return false;
}
+ /**
+ * Which languages (systemLanguage attribute) is supported.
+ *
+ * @note This list is not guaranteed to be exhaustive.
+ * To avoid OOM errors, we only look at first bit of a file.
+ * Thus all languages on this list are present in the file,
+ * but its possible for the file to have a language not on
+ * this list.
+ *
+ * @param File $file
+ * @return Array of language codes, or empty if no language switching supported.
+ */
+ public function getAvailableLanguages( File $file ) {
+ $metadata = $file->getMetadata();
+ $langList = array();
+ if ( $metadata ) {
+ $metadata = $this->unpackMetadata( $metadata );
+ if ( isset( $metadata['translations'] ) ) {
+ foreach( $metadata['translations'] as $lang => $langType ) {
+ if ( $langType === SvgReader::LANG_FULL_MATCH ) {
+ $langList[] = $lang;
+ }
+ }
+ }
+ }
+ return $langList;
+ }
+
+ /**
+ * What language to render file in if none selected.
+ *
+ * @return String language code.
+ */
+ public function getDefaultRenderLanguage( File $file ) {
+ return 'en';
+ }
+
/**
* We do not support making animated svg thumbnails
*/
$clientHeight = $params['height'];
$physicalWidth = $params['physicalWidth'];
$physicalHeight = $params['physicalHeight'];
- $lang = isset( $params['lang'] ) ? $params['lang'] : 'en';
+ $lang = isset( $params['lang'] ) ? $params['lang'] : $this->getDefaultRenderLanguage( $image );
if ( $flags & self::TRANSFORM_LATER ) {
return new ThumbnailImage( $image, $dstUrl, $dstPath, $params );
'imgmultigo' => 'Go!',
'imgmultigoto' => 'Go to page $1',
+'img-lang-opt' => '$2 ($1)',
+'img-lang-default' => '(default language)',
+'img-lang-info' => 'Render this image in $1 $2.',
+'img-lang-go' => 'Go',
+
# Table pager
'ascending_abbrev' => 'asc',
'descending_abbrev' => 'desc',
See also:
* {{msg-mw|Imgmultigo|Submit button text}}',
+'img-lang-opt' => '{{optional}} Items in the language drop down on the image page for a translated SVG file. For an example see [[:File:Gerrit patchset 25838 test.svg]]. See also {{msg-mw|img-lang-info}}
+
+* $1 Language code
+* $2 Language name (Either in the language in question, or the name of that language translated to the current users interface language)',
+'img-lang-default' => 'An option in the drop down of a translatable file. For example see [[:File:Gerrit patchset 25838 test.svg]]. Used when it cannot be determined what the default fallback language is. However it should be noted that most of the time, the content displayed for this option would be in English.',
+'img-lang-info' => 'Label for drop down box. Appears underneath the image on the image description page. See [[:File:Gerrit patchset 25838 test.svg]] for an example.
+
+* $1 is a drop down box with language options (See also {{msg-mw|img-lang-opt}})
+* $2 is a submit button, which uses the text from {{msg-mw|img-lang-go}}',
+'img-lang-go' => 'Go button for the language select for translatable files. See [[:File:Gerrit patchset 25838 test.svg]] for an example. See {{msg-mw|img-lang-info}}.',
+
# Table pager
'ascending_abbrev' => 'Abbreviation of ascending order.
See also:
'limitreport-expansiondepth-value',
'limitreport-expensivefunctioncount-value',
'interlanguage-link-title',
+ 'img-lang-opt',
);
/** Exif messages, which may be set as optional in several checks, but are generally mandatory */
'imgmultigo',
'imgmultigoto',
),
+ 'img-lang' => array(
+ 'img-lang-opt',
+ 'img-lang-default',
+ 'img-lang-info',
+ 'img-lang-go',
+ ),
'tablepager' => array(
'ascending_abbrev',
'descending_abbrev',
'watch-unwatch' => 'action=watch/unwatch',
'separators' => 'Separators for various lists, etc.',
'imgmulti' => 'Multipage image navigation',
+ 'img-lang' => 'Language selector for translatable SVGs',
'tablepager' => 'Table pager',
'autosumm' => 'Auto-summaries',
'autoblock_whitelist' => 'Autoblock whitelist',