* (bug 4093) '&bot=1' in Special:Contributions now propagate to other links
* Fix display of old recentchanges records for page moves
* (bug 2111) Collapsable exif metadata table, clean up display
+* Reduce fractions in display of exif exposure time
=== Caveats ===
case 'ExposureTime':
// Show the pretty fraction as well as decimal version
$tags[$tag] = wfMsg( 'exif-exposuretime-format',
- $val, $this->formatNum( $val ) );
+ $this->formatFraction( $val ), $this->formatNum( $val ) );
break;
case 'FNumber':
else
return $num;
}
+
+ /**
+ * Format a rational number, reducing fractions
+ *
+ * @access private
+ *
+ * @param mixed $num The value to format
+ * @return mixed A floating point number or whatever we were fed
+ */
+ function formatFraction( $num ) {
+ if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) ) {
+ $numerator = intval( $m[1] );
+ $denominator = intval( $m[2] );
+ $gcd = $this->gcd( $numerator, $denominator );
+ if( $gcd != 0 ) {
+ // 0 shouldn't happen! ;)
+ return $numerator / $gcd . '/' . $denominator / $gcd;
+ }
+ }
+ return $this->formatNum( $num );
+ }
+
+ /**
+ * Calculate the greatest common divisor of two integers.
+ *
+ * @param int $a
+ * @param int $b
+ * @return int
+ * @access private
+ */
+ function gcd( $a, $b ) {
+ /*
+ // http://en.wikipedia.org/wiki/Euclidean_algorithm
+ // Recursive form would be:
+ if( $b == 0 )
+ return $a;
+ else
+ return gcd( $b, $a % $b );
+ */
+ while( $b != 0 ) {
+ $remainder = $a % $b;
+
+ // tail recursion...
+ $a = $b;
+ $b = $remainder;
+ }
+ return $a;
+ }
}