diff options
Diffstat (limited to 'includes/media/XMPValidate.php')
-rw-r--r-- | includes/media/XMPValidate.php | 82 |
1 files changed, 44 insertions, 38 deletions
diff --git a/includes/media/XMPValidate.php b/includes/media/XMPValidate.php index 87f8abfe..0fa60117 100644 --- a/includes/media/XMPValidate.php +++ b/includes/media/XMPValidate.php @@ -28,7 +28,7 @@ * Each of these functions take the same parameters * * an info array which is a subset of the XMPInfo::items array * * A value (passed as reference) to validate. This can be either a - * simple value or an array + * simple value or an array * * A boolean to determine if this is validating a simple or complex values * * It should be noted that when an array is being validated, typically the validation @@ -42,11 +42,11 @@ */ class XMPValidate { /** - * function to validate boolean properties ( True or False ) + * Function to validate boolean properties ( True or False ) * - * @param array $info information about current property - * @param &$val Mixed current value to validate - * @param $standalone Boolean if this is a simple property or array + * @param array $info Information about current property + * @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 ) { if ( !$standalone ) { @@ -57,15 +57,14 @@ class XMPValidate { wfDebugLog( 'XMP', __METHOD__ . " Expected True or False but got $val" ); $val = null; } - } /** * function to validate rational properties ( 12/10 ) * - * @param array $info information about current property - * @param &$val Mixed current value to validate - * @param $standalone Boolean if this is a simple property or array + * @param array $info Information about current property + * @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 ) { if ( !$standalone ) { @@ -76,7 +75,6 @@ class XMPValidate { wfDebugLog( 'XMP', __METHOD__ . " Expected rational but got $val" ); $val = null; } - } /** @@ -85,9 +83,9 @@ class XMPValidate { * if its outside of range put it into range. * * @see MWG spec - * @param array $info information about current property - * @param &$val Mixed current value to validate - * @param $standalone Boolean if this is a simple property or array + * @param array $info Information about current property + * @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 ) { if ( !$standalone ) { @@ -99,6 +97,7 @@ class XMPValidate { ) { wfDebugLog( 'XMP', __METHOD__ . " Expected rating but got $val" ); $val = null; + return; } else { $nVal = (float)$val; @@ -108,11 +107,13 @@ class XMPValidate { // as -1 is meant as a special reject rating. wfDebugLog( 'XMP', __METHOD__ . " Rating too low, setting to -1 (Rejected)" ); $val = '-1'; + return; } if ( $nVal > 5 ) { wfDebugLog( 'XMP', __METHOD__ . " Rating too high, setting to 5" ); $val = '5'; + return; } } @@ -121,9 +122,9 @@ class XMPValidate { /** * function to validate integers * - * @param array $info information about current property - * @param &$val Mixed current value to validate - * @param $standalone Boolean if this is a simple property or array + * @param array $info Information about current property + * @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 ) { if ( !$standalone ) { @@ -134,16 +135,15 @@ class XMPValidate { wfDebugLog( 'XMP', __METHOD__ . " Expected integer but got $val" ); $val = null; } - } /** * function to validate properties with a fixed number of allowed * choices. (closed choice) * - * @param array $info information about current property - * @param &$val Mixed current value to validate - * @param $standalone Boolean if this is a simple property or array + * @param array $info Information about current property + * @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 ) { if ( !$standalone ) { @@ -171,9 +171,9 @@ class XMPValidate { /** * function to validate and modify flash structure * - * @param array $info information about current property - * @param &$val Mixed current value to validate - * @param $standalone Boolean if this is a simple property or array + * @param array $info Information about current property + * @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 ) { if ( $standalone ) { @@ -205,9 +205,9 @@ class XMPValidate { * @see rfc 3066 * @see http://www.adobe.com/devnet/xmp/pdfs/XMPSpecificationPart1.pdf page 30 (section 8.2.2.5) * - * @param array $info information about current property - * @param &$val Mixed current value to validate - * @param $standalone Boolean if this is a simple property or array + * @param array $info Information about current property + * @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 ) { if ( !$standalone ) { @@ -219,7 +219,6 @@ class XMPValidate { wfDebugLog( 'XMP', __METHOD__ . " Expected Lang code but got $val" ); $val = null; } - } /** @@ -233,11 +232,11 @@ class XMPValidate { * YYYY-MM-DDThh:mm:ssTZD * YYYY-MM-DDThh:mm:ss.sTZD * - * @param array $info information about current property - * @param &$val Mixed current value to validate. Converts to TS_EXIF as a side-effect. - * in cases where there's only a partial date, it will give things like - * 2011:04. - * @param $standalone Boolean if this is a simple property or array + * @param array $info Information about current property + * @param mixed &$val Current value to validate. Converts to TS_EXIF as a side-effect. + * in cases where there's only a partial date, it will give things like + * 2011:04. + * @param bool $standalone If this is a simple property or array */ public static function validateDate( $info, &$val, $standalone ) { if ( !$standalone ) { @@ -245,11 +244,14 @@ class XMPValidate { return; } $res = array(); + // @codingStandardsIgnoreStart Long line that cannot be broken if ( !preg_match( /* ahh! scary regex... */ '/^([0-3]\d{3})(?:-([01]\d)(?:-([0-3]\d)(?:T([0-2]\d):([0-6]\d)(?::([0-6]\d)(?:\.\d+)?)?([-+]\d{2}:\d{2}|Z)?)?)?)?$/D', $val, $res ) ) { + // @codingStandardsIgnoreEnd + wfDebugLog( 'XMP', __METHOD__ . " Expected date but got $val" ); $val = null; } else { @@ -270,6 +272,7 @@ class XMPValidate { if ( $res[1] === '0000' ) { wfDebugLog( 'XMP', __METHOD__ . " Invalid date (year 0): $val" ); $val = null; + return; } @@ -282,6 +285,7 @@ class XMPValidate { if ( isset( $res[3] ) ) { $val .= ':' . $res[3]; } + return; } @@ -292,6 +296,7 @@ class XMPValidate { if ( isset( $res[6] ) && $res[6] !== '' ) { $val .= ':' . $res[6]; } + return; } @@ -320,7 +325,6 @@ class XMPValidate { $val = substr( $val, 0, -3 ); } } - } /** function to validate, and more importantly @@ -330,10 +334,10 @@ class XMPValidate { * @see http://www.adobe.com/devnet/xmp/pdfs/XMPSpecificationPart2.pdf * section 1.2.7.4 on page 23 * - * @param array $info unused (info about prop) - * @param &$val String GPS string in either DDD,MM,SSk or - * or DDD,MM.mmk form - * @param $standalone Boolean if its a simple prop (should always be true) + * @param array $info Unused (info about prop) + * @param string &$val GPS string in either DDD,MM,SSk or + * or DDD,MM.mmk form + * @param bool $standalone If its a simple prop (should always be true) */ public static function validateGPS( $info, &$val, $standalone ) { if ( !$standalone ) { @@ -352,6 +356,7 @@ class XMPValidate { $coord = -$coord; } $val = $coord; + return; } elseif ( preg_match( '/(\d{1,3}),(\d{1,2}(?:.\d*)?)([NWSE])/D', @@ -363,12 +368,13 @@ class XMPValidate { $coord = -$coord; } $val = $coord; - return; + return; } else { wfDebugLog( 'XMP', __METHOD__ . " Expected GPSCoordinate, but got $val." ); $val = null; + return; } } |