Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/117160

Change subject: Update lessphp to b7cd5c79e8
......................................................................

Update lessphp to b7cd5c79e8

Updates:
 * 1d62556008: CS fixes
 * d3fd5cec9e: use the built-in php magic database instead of the system one
 * 34fdf60f32: data-uri: add tests and use lessc::findImport to locate the file
 * 72b25725d9: implement data-uri([mimetype,] url) from less.js 1.4.0
 * 5cf7eb272e: Update lessc.inc.php
 * 7e64e41a59: Fix color contrast and threshold calculation
 * 69adc23a92: Use property_exist to avoid "Undefined property: 
stdClass::$parent"

Change-Id: Ie626b4f1117b44669bd2c6c43a0186d95b36435a
---
M includes/libs/lessc.inc.php
1 file changed, 69 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/60/117160/1

diff --git a/includes/libs/lessc.inc.php b/includes/libs/lessc.inc.php
index 3dce961..57d45ed 100644
--- a/includes/libs/lessc.inc.php
+++ b/includes/libs/lessc.inc.php
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * lessphp v0.4.0@261f1bd28f
+ * lessphp v0.4.0@b7cd5c79e8
  * http://leafo.net/lessphp
  *
  * LESS CSS compiler, adapted from http://lesscss.org
@@ -1011,6 +1011,39 @@
                return $this->lib_rgbahex($color);
        }
 
+       /**
+        * Given an url, decide whether to output a regular link or the 
base64-encoded contents of the file
+        *
+        * @param  array  $value either an argument list (two strings) or a 
single string
+        * @return string        formatted url(), either as a link or 
base64-encoded
+        */
+       protected function lib_data_uri($value) {
+               $mime = ($value[0] === 'list') ? $value[2][0][2] : null;
+               $url = ($value[0] === 'list') ? $value[2][1][2][0] : 
$value[2][0];
+
+               $fullpath = $this->findImport($url);
+
+               if($fullpath && ($fsize = filesize($fullpath)) !== false) {
+                       // IE8 can't handle data uris larger than 32KB
+                       if($fsize/1024 < 32) {
+                               if(is_null($mime)) {
+                                       if(class_exists('finfo')) { // php 5.3+
+                                               $finfo = new 
finfo(FILEINFO_MIME);
+                                               $mime = explode('; ', 
$finfo->file($fullpath));
+                                               $mime = $mime[0];
+                                       } 
elseif(function_exists('mime_content_type')) { // PHP 5.2
+                                               $mime = 
mime_content_type($fullpath);
+                                       }
+                               }
+
+                               if(!is_null($mime)) // fallback if the mime 
type is still unknown
+                                       $url = sprintf('data:%s;base64,%s', 
$mime, base64_encode(file_get_contents($fullpath)));
+                       }
+               }
+
+               return 'url("'.$url.'")';
+       }
+
        // utility func to unquote a string
        protected function lib_e($arg) {
                switch ($arg[0]) {
@@ -1234,23 +1267,43 @@
        }
 
        protected function lib_contrast($args) {
-               if ($args[0] != 'list' || count($args[2]) < 3) {
-                       return array(array('color', 0, 0, 0), 0);
-               }
+           $darkColor  = array('color', 0, 0, 0);
+           $lightColor = array('color', 255, 255, 255);
+           $threshold  = 0.43;
 
-               list($inputColor, $darkColor, $lightColor) = $args[2];
+           if ( $args[0] == 'list' ) {
+               $inputColor = ( isset($args[2][0]) ) ? 
$this->assertColor($args[2][0])  : $lightColor;
+               $darkColor  = ( isset($args[2][1]) ) ? 
$this->assertColor($args[2][1])  : $darkColor;
+               $lightColor = ( isset($args[2][2]) ) ? 
$this->assertColor($args[2][2])  : $lightColor;
+               $threshold  = ( isset($args[2][3]) ) ? 
$this->assertNumber($args[2][3]) : $threshold;
+           }
+           else {
+               $inputColor  = $this->assertColor($args);
+           }
 
-               $inputColor = $this->assertColor($inputColor);
-               $darkColor = $this->assertColor($darkColor);
-               $lightColor = $this->assertColor($lightColor);
-               $hsl = $this->toHSL($inputColor);
+           $inputColor = $this->coerceColor($inputColor);
+           $darkColor  = $this->coerceColor($darkColor);
+           $lightColor = $this->coerceColor($lightColor);
 
-               if ($hsl[3] > 50) {
-                       return $darkColor;
-               }
+           //Figure out which is actually light and dark!
+           if ( $this->lib_luma($darkColor) > $this->lib_luma($lightColor) ) {
+               $t  = $lightColor;
+               $lightColor = $darkColor;
+               $darkColor  = $t;
+           }
 
-               return $lightColor;
+           $inputColor_alpha = $this->lib_alpha($inputColor);
+           if ( ( $this->lib_luma($inputColor) * $inputColor_alpha) < 
$threshold) {
+               return $lightColor;
+           }
+           return $darkColor;
        }
+
+       protected function lib_luma($color) {
+           $color = $this->coerceColor($color);
+           return (0.2126 * $color[0] / 255) + (0.7152 * $color[1] / 255) + 
(0.0722 * $color[2] / 255);
+       }
+
 
        public function assertColor($value, $error = "expected color value") {
                $color = $this->coerceColor($value);
@@ -1475,8 +1528,9 @@
 
                        list(, $name, $args) = $value;
                        if ($name == "%") $name = "_sprintf";
+
                        $f = isset($this->libFunctions[$name]) ?
-                               $this->libFunctions[$name] : array($this, 
'lib_'.$name);
+                               $this->libFunctions[$name] : array($this, 
'lib_'.str_replace('-', '_', $name));
 
                        if (is_callable($f)) {
                                if ($args[0] == 'list')
@@ -2338,7 +2392,7 @@
                        $this->throwError();
 
                // TODO report where the block was opened
-               if (!is_null($this->env->parent))
+               if ( !property_exists($this->env, 'parent') || 
!is_null($this->env->parent) )
                        throw new exception('parse error: unclosed block');
 
                return $this->env;

-- 
To view, visit https://gerrit.wikimedia.org/r/117160
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie626b4f1117b44669bd2c6c43a0186d95b36435a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to