summaryrefslogtreecommitdiff
path: root/includes/media/XMPValidate.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-20 09:00:55 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-20 09:00:55 +0100
commita2190ac74dd4d7080b12bab90e552d7aa81209ef (patch)
tree8b31f38de9882d18df54cf8d9e0de74167a094eb /includes/media/XMPValidate.php
parent15e69f7b20b6596b9148030acce5b59993b95a45 (diff)
parent257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff)
Merge branch 'mw-1.26'
Diffstat (limited to 'includes/media/XMPValidate.php')
-rw-r--r--includes/media/XMPValidate.php60
1 files changed, 38 insertions, 22 deletions
diff --git a/includes/media/XMPValidate.php b/includes/media/XMPValidate.php
index 0fa60117..55e8ce79 100644
--- a/includes/media/XMPValidate.php
+++ b/includes/media/XMPValidate.php
@@ -21,6 +21,9 @@
* @ingroup Media
*/
+use Psr\Log\LoggerInterface;
+use Psr\Log\LoggerAwareInterface;
+
/**
* This contains some static methods for
* validating XMP properties. See XMPInfo and XMPReader classes.
@@ -40,7 +43,20 @@
* @see http://www.adobe.com/devnet/xmp/pdfs/XMPSpecificationPart1.pdf starting at pg 28
* @see http://www.adobe.com/devnet/xmp/pdfs/XMPSpecificationPart2.pdf starting at pg 11
*/
-class XMPValidate {
+class XMPValidate implements LoggerAwareInterface {
+
+ /**
+ * @var LoggerInterface
+ */
+ private $logger;
+
+ public function __construct( LoggerInterface $logger ) {
+ $this->setLogger( $logger );
+ }
+
+ public function setLogger( LoggerInterface $logger ) {
+ $this->logger = $logger;
+ }
/**
* Function to validate boolean properties ( True or False )
*
@@ -48,13 +64,13 @@ class XMPValidate {
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateBoolean( $info, &$val, $standalone ) {
+ public function validateBoolean( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
}
if ( $val !== 'True' && $val !== 'False' ) {
- wfDebugLog( 'XMP', __METHOD__ . " Expected True or False but got $val" );
+ $this->debug->info( __METHOD__ . " Expected True or False but got $val" );
$val = null;
}
}
@@ -66,13 +82,13 @@ class XMPValidate {
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateRational( $info, &$val, $standalone ) {
+ public function validateRational( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
}
if ( !preg_match( '/^(?:-?\d+)\/(?:\d+[1-9]|[1-9]\d*)$/D', $val ) ) {
- wfDebugLog( 'XMP', __METHOD__ . " Expected rational but got $val" );
+ $this->logger->info( __METHOD__ . " Expected rational but got $val" );
$val = null;
}
}
@@ -87,7 +103,7 @@ class XMPValidate {
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateRating( $info, &$val, $standalone ) {
+ public function validateRating( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
@@ -95,7 +111,7 @@ class XMPValidate {
if ( !preg_match( '/^[-+]?\d*(?:\.?\d*)$/D', $val )
|| !is_numeric( $val )
) {
- wfDebugLog( 'XMP', __METHOD__ . " Expected rating but got $val" );
+ $this->logger->info( __METHOD__ . " Expected rating but got $val" );
$val = null;
return;
@@ -105,13 +121,13 @@ class XMPValidate {
// We do < 0 here instead of < -1 here, since
// the values between 0 and -1 are also illegal
// as -1 is meant as a special reject rating.
- wfDebugLog( 'XMP', __METHOD__ . " Rating too low, setting to -1 (Rejected)" );
+ $this->logger->info( __METHOD__ . " Rating too low, setting to -1 (Rejected)" );
$val = '-1';
return;
}
if ( $nVal > 5 ) {
- wfDebugLog( 'XMP', __METHOD__ . " Rating too high, setting to 5" );
+ $this->logger->info( __METHOD__ . " Rating too high, setting to 5" );
$val = '5';
return;
@@ -126,13 +142,13 @@ class XMPValidate {
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateInteger( $info, &$val, $standalone ) {
+ public function validateInteger( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
}
if ( !preg_match( '/^[-+]?\d+$/D', $val ) ) {
- wfDebugLog( 'XMP', __METHOD__ . " Expected integer but got $val" );
+ $this->logger->info( __METHOD__ . " Expected integer but got $val" );
$val = null;
}
}
@@ -145,7 +161,7 @@ class XMPValidate {
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateClosed( $info, &$val, $standalone ) {
+ public function validateClosed( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
@@ -163,7 +179,7 @@ class XMPValidate {
}
if ( !isset( $info['choices'][$val] ) && !$inRange ) {
- wfDebugLog( 'XMP', __METHOD__ . " Expected closed choice, but got $val" );
+ $this->logger->info( __METHOD__ . " Expected closed choice, but got $val" );
$val = null;
}
}
@@ -175,7 +191,7 @@ class XMPValidate {
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateFlash( $info, &$val, $standalone ) {
+ public function validateFlash( $info, &$val, $standalone ) {
if ( $standalone ) {
// this only validates flash structs, not individual properties
return;
@@ -186,7 +202,7 @@ class XMPValidate {
&& isset( $val['RedEyeMode'] )
&& isset( $val['Return'] )
) ) {
- wfDebugLog( 'XMP', __METHOD__ . " Flash structure did not have all the required components" );
+ $this->logger->info( __METHOD__ . " Flash structure did not have all the required components" );
$val = null;
} else {
$val = ( "\0" | ( $val['Fired'] === 'True' )
@@ -209,14 +225,14 @@ class XMPValidate {
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateLangCode( $info, &$val, $standalone ) {
+ public function validateLangCode( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
}
if ( !preg_match( '/^[-A-Za-z0-9]{2,}$/D', $val ) ) {
//this is a rather naive check.
- wfDebugLog( 'XMP', __METHOD__ . " Expected Lang code but got $val" );
+ $this->logger->info( __METHOD__ . " Expected Lang code but got $val" );
$val = null;
}
}
@@ -238,7 +254,7 @@ class XMPValidate {
* 2011:04.
* @param bool $standalone If this is a simple property or array
*/
- public static function validateDate( $info, &$val, $standalone ) {
+ public function validateDate( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
@@ -252,7 +268,7 @@ class XMPValidate {
) {
// @codingStandardsIgnoreEnd
- wfDebugLog( 'XMP', __METHOD__ . " Expected date but got $val" );
+ $this->logger->info( __METHOD__ . " Expected date but got $val" );
$val = null;
} else {
/*
@@ -270,7 +286,7 @@ class XMPValidate {
* some programs convert between metadata formats.
*/
if ( $res[1] === '0000' ) {
- wfDebugLog( 'XMP', __METHOD__ . " Invalid date (year 0): $val" );
+ $this->logger->info( __METHOD__ . " Invalid date (year 0): $val" );
$val = null;
return;
@@ -339,7 +355,7 @@ class XMPValidate {
* or DDD,MM.mmk form
* @param bool $standalone If its a simple prop (should always be true)
*/
- public static function validateGPS( $info, &$val, $standalone ) {
+ public function validateGPS( $info, &$val, $standalone ) {
if ( !$standalone ) {
return;
}
@@ -371,7 +387,7 @@ class XMPValidate {
return;
} else {
- wfDebugLog( 'XMP', __METHOD__
+ $this->logger->info( __METHOD__
. " Expected GPSCoordinate, but got $val." );
$val = null;