Drop Linker::formatSize, deprecated in 1.28 and unused
[lhc/web/wiklou.git] / includes / page / ImagePage.php
index c879a88..66804bc 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\ResultWrapper;
 
 /**
@@ -187,7 +188,10 @@ class ImagePage extends Article {
                                'h2',
                                [ 'id' => 'metadata' ],
                                        $this->getContext()->msg( 'metadata' )->text() ) . "\n" );
-                       $out->addWikiTextAsInterface( $this->makeMetadataTable( $formattedMetadata ) );
+                       $out->wrapWikiTextAsInterface(
+                               'mw-imagepage-section-metadata',
+                               $this->makeMetadataTable( $formattedMetadata )
+                       );
                        $out->addModules( [ 'mediawiki.action.view.metadata' ] );
                }
 
@@ -246,8 +250,7 @@ class ImagePage extends Article {
         * @return string The metadata table. This is treated as Wikitext (!)
         */
        protected function makeMetadataTable( $metadata ) {
-               $r = "<div class=\"mw-imagepage-section-metadata\">";
-               $r .= $this->getContext()->msg( 'metadata-help' )->plain();
+               $r = $this->getContext()->msg( 'metadata-help' )->plain();
                // Intial state is collapsed
                // see filepage.css and mediawiki.action.view.metadata module.
                $r .= "<table id=\"mw_metadata\" class=\"mw_metadata collapsed\">\n";
@@ -264,7 +267,7 @@ class ImagePage extends Article {
                                );
                        }
                }
-               $r .= "</table>\n</div>\n";
+               $r .= "</table>\n";
                return $r;
        }
 
@@ -279,26 +282,33 @@ class ImagePage extends Article {
         */
        public function getEmptyPageParserOutput( ParserOptions $options ) {
                $this->loadFile();
-               if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->getId() ) {
+               if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && $this->getId() == 0 ) {
                        return new ParserOutput();
                }
                return parent::getEmptyPageParserOutput( $options );
        }
 
+       /**
+        * Returns language code to be used for dispaying the image, based on request context and
+        * languages available in the file.
+        *
+        * @param WebRequest $request
+        * @param File $file
+        * @return string|null
+        */
        private function getLanguageForRendering( WebRequest $request, File $file ) {
-               $handler = $this->displayImg->getHandler();
+               $handler = $file->getHandler();
                if ( !$handler ) {
                        return null;
                }
 
-               $requestLanguage = $request->getVal( 'lang' );
-               if ( !is_null( $requestLanguage ) ) {
-                       if ( $handler->validateParam( 'lang', $requestLanguage ) ) {
-                               return $requestLanguage;
-                       }
+               $config = MediaWikiServices::getInstance()->getMainConfig();
+               $requestLanguage = $request->getVal( 'lang', $config->get( 'LanguageCode' ) );
+               if ( $handler->validateParam( 'lang', $requestLanguage ) ) {
+                       return $file->getMatchedLanguage( $requestLanguage );
                }
 
-               return $handler->getDefaultRenderLanguage( $this->displayImg );
+               return $handler->getDefaultRenderLanguage( $file );
        }
 
        protected function openShowImage() {
@@ -347,7 +357,7 @@ class ImagePage extends Article {
                                # image
                                # "Download high res version" link below the image
                                # $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
-                               #   Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
+                               #   Language::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
                                # We'll show a thumbnail of this image
                                if ( $width > $maxWidth || $height > $maxHeight || $this->displayImg->isVectorized() ) {
                                        list( $width, $height ) = $this->getDisplayWidthHeight(
@@ -1089,8 +1099,8 @@ EOT
        }
 
        /**
-        * @param $lang string
-        * @param $selected bool
+        * @param string $lang
+        * @param bool $selected
         * @return string
         */
        private function createXmlOptionStringForLanguage( $lang, $selected ) {