X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=a83217d5a20db4b882536d287fabf0e089972707;hb=ac80a433bb101e63e179f3c6f13acb1ba1547494;hp=4ea1712f044e5b6ce3656e3d9d422be1c6d4c54d;hpb=c21a77b35601753a50e236f1b231cd1383fd40a2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 4ea1712f04..a83217d5a2 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -262,7 +262,9 @@ class ImagePage extends Article { # @todo FIXME: Why is this using escapeId for a class?! $class = Sanitizer::escapeId( $v['id'] ); if ( $type == 'collapsed' ) { - $class .= ' collapsable'; // sic + // Handled by mediawiki.action.view.metadata module + // and skins/common/shared.css. + $class .= ' collapsable'; } $r .= "\n"; $r .= "{$v['name']}\n"; @@ -314,7 +316,12 @@ class ImagePage extends Article { $renderLang = $request->getVal( 'lang' ); if ( !is_null( $renderLang ) ) { - $params['lang'] = $renderLang; + $handler = $this->displayImg->getHandler(); + if ( $handler && $handler->validateParam( 'lang', $renderLang ) ) { + $params['lang'] = $renderLang; + } else { + $renderLang = null; + } } $width_orig = $this->displayImg->getWidth( $page ); @@ -377,8 +384,8 @@ class ImagePage extends Article { // since that is added to the message separately, so // it can be denoted as the current size being shown. if ( $size[0] <= $width_orig && $size[1] <= $height_orig - && $size[0] != $width && $size[1] != $height ) - { + && $size[0] != $width && $size[1] != $height + ) { $sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] ); if ( $sizeLink ) { $otherSizes[] = $sizeLink; @@ -525,6 +532,16 @@ 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 ) ); + } + // Add cannot animate thumbnail warning if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) { // Include the extension so wiki admins can @@ -715,7 +732,7 @@ EOT return $dbr->select( array( 'imagelinks', 'page' ), - array( 'page_namespace', 'page_title', 'page_is_redirect', 'il_to' ), + array( 'page_namespace', 'page_title', 'il_to' ), array( 'il_to' => $target, 'il_from = page_id' ), __METHOD__, array( 'LIMIT' => $limit + 1, 'ORDER BY' => 'il_from', ) @@ -726,13 +743,19 @@ EOT $limit = 100; $out = $this->getContext()->getOutput(); - $res = $this->queryImageLinks( $this->getTitle()->getDBkey(), $limit + 1 ); + $rows = array(); $redirects = array(); + foreach ( $this->getTitle()->getRedirectsHere( NS_FILE ) as $redir ) { + $redirects[$redir->getDBkey()] = array(); + $rows[] = (object)array( + 'page_namespace' => NS_FILE, + 'page_title' => $redir->getDBkey(), + ); + } + + $res = $this->queryImageLinks( $this->getTitle()->getDBkey(), $limit + 1 ); foreach ( $res as $row ) { - if ( $row->page_is_redirect ) { - $redirects[$row->page_title] = array(); - } $rows[] = $row; } $count = count( $rows ); @@ -947,6 +970,72 @@ EOT ? $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, $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; + } } /** @@ -1203,8 +1292,8 @@ class ImageHistoryList extends ContextSource { $lang = $this->getLanguage(); $user = $this->getUser(); if ( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE, $user ) - && !$file->isDeleted( File::DELETED_FILE ) ) - { + && !$file->isDeleted( File::DELETED_FILE ) + ) { $params = array( 'width' => '120', 'height' => '120',