X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=a83217d5a20db4b882536d287fabf0e089972707;hb=eabfeda3bec5d8108bddf143cf677aa301d8073b;hp=b2a53cdb1bd987cdc3273f9bb1df065b6db94dfb;hpb=4960dd9b775b4f7aae2e1f1906a1f72b859415df;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/ImagePage.php b/includes/ImagePage.php
index b2a53cdb1b..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 );
@@ -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;
+ }
}
/**