Pass context to FormatMetadata class on ImagePage
authorumherirrender <umherirrender_de.wp@web.de>
Sun, 28 Dec 2014 20:31:34 +0000 (21:31 +0100)
committerumherirrender <umherirrender_de.wp@web.de>
Fri, 30 Jan 2015 19:31:54 +0000 (20:31 +0100)
This avoids on image page:
ContextSource::getContext (FormatMetadata): called and $context is null.
Using RequestContext::getMain() for sanity

Change-Id: I92774e1a88f03d44967d1797c6c2b8a31c1b10fc

includes/filerepo/file/File.php
includes/media/ExifBitmap.php
includes/media/GIF.php
includes/media/MediaHandler.php
includes/media/PNG.php
includes/media/SVG.php
includes/page/ImagePage.php

index df85f9c..eec8d21 100644 (file)
@@ -1765,14 +1765,15 @@ abstract class File {
        }
 
        /**
+        * @param bool|IContextSource $context Context to use (optional)
         * @return bool
         */
-       function formatMetadata() {
+       function formatMetadata( $context = false ) {
                if ( !$this->getHandler() ) {
                        return false;
                }
 
-               return $this->getHandler()->formatMetadata( $this, $this->getMetadata() );
+               return $this->getHandler()->formatMetadata( $this, $context );
        }
 
        /**
index b7657cb..f56a947 100644 (file)
@@ -125,15 +125,16 @@ class ExifBitmapHandler extends BitmapHandler {
 
        /**
         * @param File $image
+        * @param bool|IContextSource $context Context to use (optional)
         * @return array|bool
         */
-       function formatMetadata( $image ) {
+       function formatMetadata( $image, $context = false ) {
                $meta = $this->getCommonMetaArray( $image );
                if ( count( $meta ) === 0 ) {
                        return false;
                }
 
-               return $this->formatMetadataHelper( $meta );
+               return $this->formatMetadataHelper( $meta, $context );
        }
 
        public function getCommonMetaArray( File $file ) {
index 5992be1..e3621fb 100644 (file)
@@ -44,15 +44,16 @@ class GIFHandler extends BitmapHandler {
 
        /**
         * @param File $image
+        * @param bool|IContextSource $context Context to use (optional)
         * @return array|bool
         */
-       function formatMetadata( $image ) {
+       function formatMetadata( $image, $context = false ) {
                $meta = $this->getCommonMetaArray( $image );
                if ( count( $meta ) === 0 ) {
                        return false;
                }
 
-               return $this->formatMetadataHelper( $meta );
+               return $this->formatMetadataHelper( $meta, $context );
        }
 
        /**
index b88a1b1..0103946 100644 (file)
@@ -507,9 +507,10 @@ abstract class MediaHandler {
         * to some standard. That makes it possible to do things like visual
         * indication of grouped and chained streams in ogg container files.
         * @param File $image
+        * @param bool|IContextSource $context Context to use (optional)
         * @return array|bool
         */
-       function formatMetadata( $image ) {
+       function formatMetadata( $image, $context = false ) {
                return false;
        }
 
@@ -520,15 +521,16 @@ abstract class MediaHandler {
         * This is used by the media handlers that use the FormatMetadata class
         *
         * @param array $metadataArray Metadata array
+        * @param bool|IContextSource $context Context to use (optional)
         * @return array Array for use displaying metadata.
         */
-       function formatMetadataHelper( $metadataArray ) {
+       function formatMetadataHelper( $metadataArray, $context = false ) {
                $result = array(
                        'visible' => array(),
                        'collapsed' => array()
                );
 
-               $formatted = FormatMetadata::getFormattedData( $metadataArray );
+               $formatted = FormatMetadata::getFormattedData( $metadataArray, $context );
                // Sort fields into visible and collapsed
                $visibleFields = $this->visibleMetadataFields();
                foreach ( $formatted as $name => $value ) {
index 3cf8488..5f1aca5 100644 (file)
@@ -49,15 +49,16 @@ class PNGHandler extends BitmapHandler {
 
        /**
         * @param File $image
+        * @param bool|IContextSource $context Context to use (optional)
         * @return array|bool
         */
-       function formatMetadata( $image ) {
+       function formatMetadata( $image, $context = false ) {
                $meta = $this->getCommonMetaArray( $image );
                if ( count( $meta ) === 0 ) {
                        return false;
                }
 
-               return $this->formatMetadataHelper( $meta );
+               return $this->formatMetadataHelper( $meta, $context );
        }
 
        /**
index 53abfef..0618f7e 100644 (file)
@@ -410,9 +410,10 @@ class SvgHandler extends ImageHandler {
 
        /**
         * @param File $file
+        * @param bool|IContextSource $context Context to use (optional)
         * @return array|bool
         */
-       function formatMetadata( $file ) {
+       function formatMetadata( $file, $context = false ) {
                $result = array(
                        'visible' => array(),
                        'collapsed' => array()
index b8f67c2..803e425 100644 (file)
@@ -140,7 +140,7 @@ class ImagePage extends Article {
 
                if ( $wgShowEXIF && $this->displayImg->exists() ) {
                        // @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
-                       $formattedMetadata = $this->displayImg->formatMetadata();
+                       $formattedMetadata = $this->displayImg->formatMetadata( $this->getContext() );
                        $showmeta = $formattedMetadata !== false;
                } else {
                        $showmeta = false;