Fix grammar in 'mimesearch-summary'
[lhc/web/wiklou.git] / includes / ImageFunctions.php
index 219b5b0..467624c 100644 (file)
@@ -1,11 +1,17 @@
 <?php
+/**
+ * Global functions related to images
+ *
+ * @file
+ */
+
 /**
  * Return a rounded pixel equivalent for a labeled CSS/SVG length.
  * http://www.w3.org/TR/SVG11/coords.html#UnitIdentifiers
  *
  * @param $length String: CSS/SVG length.
- * @param $viewpoerSize: Float optional scale for percentage units...
- * @return Integer: length in pixels
+ * @param $viewportSize: Float optional scale for percentage units...
+ * @return float: length in pixels
  */
 function wfScaleSVGUnit( $length, $viewportSize=512 ) {
        static $unitLength = array(
@@ -24,13 +30,13 @@ function wfScaleSVGUnit( $length, $viewportSize=512 ) {
                $length = floatval( $matches[1] );
                $unit = $matches[2];
                if( $unit == '%' ) {
-                       return round( $length * 0.01 * $viewportSize );
+                       return $length * 0.01 * $viewportSize;
                } else {
-                       return round( $length * $unitLength[$unit] );
+                       return $length * $unitLength[$unit];
                }
        } else {
                // Assume pixels
-               return round( floatval( $length ) );
+               return floatval( $length );
        }
 }
 
@@ -76,8 +82,11 @@ class XmlSizeFilter {
                                $width = $height * $aspect;
                        }
                        
-                       $this->width = $width;
-                       $this->height = $height;
+                       if( $width > 0 && $height > 0 ) {
+                               $this->width = intval( round( $width ) );
+                               $this->height = intval( round( $height ) );
+                       }
+                       
                        $this->first = false;
                }
        }
@@ -120,6 +129,12 @@ function wfIsBadImage( $name, $contextTitle = false ) {
        static $badImages = false;
        wfProfileIn( __METHOD__ );
 
+       # Handle redirects
+       $redirectTitle = RepoGroup::singleton()->checkRedirect( Title::makeTitle( NS_FILE, $name ) );
+       if( $redirectTitle ) {
+               $name = $redirectTitle->getDbKey();
+       }
+
        # Run the extension hook
        $bad = false;
        if( !wfRunHooks( 'BadImage', array( $name, &$bad ) ) ) {