Move LESS function definitions from DefaultSettings to ResourceLoaderLESSFunctions.php
authorBrion Vibber <brion@pobox.com>
Thu, 26 Sep 2013 18:55:57 +0000 (11:55 -0700)
committerBrion Vibber <brion@pobox.com>
Thu, 26 Sep 2013 22:57:50 +0000 (15:57 -0700)
Intermittent error in production from top-level lambda functions:
https://bugs.php.net/bug.php?id=52144

Change-Id: I9785a601fd5d57c9d8d84b90ee29eef61a6f2e77

includes/AutoLoader.php
includes/DefaultSettings.php
includes/resourceloader/ResourceLoaderLESSFunctions.php [new file with mode: 0644]

index 54bffab..7eec763 100644 (file)
@@ -857,6 +857,7 @@ $wgAutoloadLocalClasses = array(
        'ResourceLoaderContext' => 'includes/resourceloader/ResourceLoaderContext.php',
        'ResourceLoaderFileModule' => 'includes/resourceloader/ResourceLoaderFileModule.php',
        'ResourceLoaderFilePageModule' => 'includes/resourceloader/ResourceLoaderFilePageModule.php',
+       'ResourceLoaderLESSFunctions' => 'includes/resourceloader/ResourceLoaderLESSFunctions.php',
        'ResourceLoaderModule' => 'includes/resourceloader/ResourceLoaderModule.php',
        'ResourceLoaderNoscriptModule' => 'includes/resourceloader/ResourceLoaderNoscriptModule.php',
        'ResourceLoaderSiteModule' => 'includes/resourceloader/ResourceLoaderSiteModule.php',
index 46d1fd4..4d8c032 100644 (file)
@@ -3314,50 +3314,8 @@ $wgResourceLoaderLESSVars = array();
  * @since 1.22
  */
 $wgResourceLoaderLESSFunctions = array(
-       /**
-        * Check if an image file reference is suitable for embedding.
-        * An image is embeddable if it (a) exists, (b) has a suitable MIME-type,
-        * (c) does not exceed IE<9 size limit of 32kb. This is a LESS predicate
-        * function; it returns a LESS boolean value and can thus be used as a
-        * mixin guard.
-        *
-        * @par Example:
-        * @code
-        *   .background-image(@url) when(embeddable(@url)) {
-        *       background-image: url(@url) !ie;
-        *   }
-        * @endcode
-        */
-       'embeddable' => function( $frame, $less ) {
-               $base = pathinfo( $less->parser->sourceName, PATHINFO_DIRNAME );
-               $url = $frame[2][0];
-               $file = realpath( $base . '/' . $url );
-               $embeddable = ( $file
-                       && strpos( $url, '//' ) === false
-                       && filesize( $file ) < CSSMin::EMBED_SIZE_LIMIT
-                       && CSSMin::getMimeType( $file ) !== false ) ? 'true' : 'false';
-               return array( 'keyword', $embeddable );
-       },
-
-       /**
-        * Convert an image URI to a base64-encoded data URI.
-        *
-        * @par Example:
-        * @code
-        *   .fancy-button {
-        *       background-image: embed('../images/button-bg.png');
-        *   }
-        * @endcode
-        */
-       'embed' => function( $frame, $less ) {
-               $base = pathinfo( $less->parser->sourceName, PATHINFO_DIRNAME );
-               $url = $frame[2][0];
-               $file = realpath( $base . '/' . $url );
-
-               $data = CSSMin::encodeImageAsDataURI( $file );
-               $less->embeddedFiles[ $file ] = filemtime( $file );
-               return 'url(' . $data . ')';
-       },
+       'embeddable' => 'ResourceLoaderLESSFunctions::embeddable',
+       'embed' => 'ResourceLoaderLESSFunctions::embed',
 );
 
 /**
diff --git a/includes/resourceloader/ResourceLoaderLESSFunctions.php b/includes/resourceloader/ResourceLoaderLESSFunctions.php
new file mode 100644 (file)
index 0000000..084bb54
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+/**
+ * PHP-provided functions for LESS; see docs for $wgResourceLoaderLESSFunctions
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+class ResourceLoaderLESSFunctions {
+       /**
+        * Check if an image file reference is suitable for embedding.
+        * An image is embeddable if it (a) exists, (b) has a suitable MIME-type,
+        * (c) does not exceed IE<9 size limit of 32kb. This is a LESS predicate
+        * function; it returns a LESS boolean value and can thus be used as a
+        * mixin guard.
+        *
+        * @par Example:
+        * @code
+        *   .background-image(@url) when(embeddable(@url)) {
+        *       background-image: url(@url) !ie;
+        *   }
+        * @endcode
+        */
+       public static function embeddable( $frame, $less ) {
+               $base = pathinfo( $less->parser->sourceName, PATHINFO_DIRNAME );
+               $url = $frame[2][0];
+               $file = realpath( $base . '/' . $url );
+               $embeddable = ( $file
+                       && strpos( $url, '//' ) === false
+                       && filesize( $file ) < CSSMin::EMBED_SIZE_LIMIT
+                       && CSSMin::getMimeType( $file ) !== false ) ? 'true' : 'false';
+               return array( 'keyword', $embeddable );
+       }
+
+       /**
+        * Convert an image URI to a base64-encoded data URI.
+        *
+        * @par Example:
+        * @code
+        *   .fancy-button {
+        *       background-image: embed('../images/button-bg.png');
+        *   }
+        * @endcode
+        */
+       public static function embed( $frame, $less ) {
+               $base = pathinfo( $less->parser->sourceName, PATHINFO_DIRNAME );
+               $url = $frame[2][0];
+               $file = realpath( $base . '/' . $url );
+
+               $data = CSSMin::encodeImageAsDataURI( $file );
+               $less->embeddedFiles[ $file ] = filemtime( $file );
+               return 'url(' . $data . ')';
+       }
+}