From dc1b084079a508ad73b709812f651a5cf1c3712c Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sun, 28 Dec 2014 21:31:34 +0100 Subject: [PATCH] Pass context to FormatMetadata class on ImagePage 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 | 5 +++-- includes/media/ExifBitmap.php | 5 +++-- includes/media/GIF.php | 5 +++-- includes/media/MediaHandler.php | 8 +++++--- includes/media/PNG.php | 5 +++-- includes/media/SVG.php | 3 ++- includes/page/ImagePage.php | 2 +- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index df85f9c723..eec8d216a7 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -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 ); } /** diff --git a/includes/media/ExifBitmap.php b/includes/media/ExifBitmap.php index b7657cb3aa..f56a947f9a 100644 --- a/includes/media/ExifBitmap.php +++ b/includes/media/ExifBitmap.php @@ -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 ) { diff --git a/includes/media/GIF.php b/includes/media/GIF.php index 5992be11ed..e3621fbdaa 100644 --- a/includes/media/GIF.php +++ b/includes/media/GIF.php @@ -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 ); } /** diff --git a/includes/media/MediaHandler.php b/includes/media/MediaHandler.php index b88a1b12a0..0103946d67 100644 --- a/includes/media/MediaHandler.php +++ b/includes/media/MediaHandler.php @@ -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 ) { diff --git a/includes/media/PNG.php b/includes/media/PNG.php index 3cf8488d74..5f1aca57a0 100644 --- a/includes/media/PNG.php +++ b/includes/media/PNG.php @@ -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 ); } /** diff --git a/includes/media/SVG.php b/includes/media/SVG.php index 53abfef04a..0618f7efd0 100644 --- a/includes/media/SVG.php +++ b/includes/media/SVG.php @@ -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() diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php index b8f67c2e2c..803e4257bb 100644 --- a/includes/page/ImagePage.php +++ b/includes/page/ImagePage.php @@ -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; -- 2.20.1