Merge "Make $.fn.updateTooltipAccessKeys() less expensive"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 24 Nov 2015 06:50:13 +0000 (06:50 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 24 Nov 2015 06:50:13 +0000 (06:50 +0000)
includes/libs/ObjectFactory.php
includes/libs/objectcache/WANObjectCache.php
resources/lib/oojs-ui/oojs-ui.js
tests/phpunit/includes/libs/ObjectFactoryTest.php
tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php

index 6191612..2ffc1d3 100644 (file)
@@ -128,8 +128,13 @@ class ObjectFactory {
         * @return mixed Constructed instance
         */
        public static function constructClassInstance( $clazz, $args ) {
+               // $args should be a non-associative array; show nice error if that's not the case
+               if ( $args && array_keys( $args ) !== range( 0, count( $args ) - 1 ) ) {
+                       throw new InvalidArgumentException( __METHOD__ . ': $args cannot be an associative array' );
+               }
+
                // TODO: when PHP min version supported is >=5.6.0 replace this
-               // function body with `return new $clazz( ... $args );`.
+               // with `return new $clazz( ... $args );`.
                $obj = null;
                switch ( count( $args ) ) {
                        case 0:
index 128999a..16e894e 100644 (file)
@@ -101,6 +101,8 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        const TSE_NONE = -1;
        /** Max TTL to store keys when a data sourced is lagged */
        const TTL_LAGGED = 30;
+       /** Idiom for delete() for "no hold-off" */
+       const HOLDOFF_NONE = 0;
 
        /** Tiny negative float to use when CTL comes up >= 0 due to clock skew */
        const TINY_NEGATIVE = -0.000001;
@@ -254,7 +256,8 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                $checkKeyTimesForAll = $this->processCheckKeys( $checksForAll, $wrappedValues, $now );
                $checkKeyTimesByKey = array();
                foreach ( $checksByKey as $cacheKey => $checks ) {
-                       $checkKeyTimesByKey[$cacheKey] = $this->processCheckKeys( $checks, $wrappedValues, $now );
+                       $checkKeyTimesByKey[$cacheKey] =
+                               $this->processCheckKeys( $checks, $wrappedValues, $now );
                }
 
                // Get the main cache value for each key and validate them
@@ -456,7 +459,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         *
         * The $ttl parameter can be used when purging values that have not actually changed
         * recently. For example, a cleanup script to purge cache entries does not really need
-        * a hold-off period, so it can use the value 1. Likewise for user-requested purge.
+        * a hold-off period, so it can use HOLDOFF_NONE. Likewise for user-requested purge.
         * Note that $ttl limits the effective range of 'lockTSE' for getWithSetCallback().
         *
         * If called twice on the same key, then the last hold-off TTL takes precedence. For
@@ -468,12 +471,20 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         */
        final public function delete( $key, $ttl = self::HOLDOFF_TTL ) {
                $key = self::VALUE_KEY_PREFIX . $key;
-               // Avoid indefinite key salting for sanity
-               $ttl = max( $ttl, 1 );
-               // Update the local datacenter immediately
-               $ok = $this->cache->set( $key, self::PURGE_VAL_PREFIX . microtime( true ), $ttl );
-               // Publish the purge to all datacenters
-               return $this->relayPurge( $key, $ttl ) && $ok;
+
+               if ( $ttl <= 0 ) {
+                       // Update the local datacenter immediately
+                       $ok = $this->cache->delete( $key );
+                       // Publish the purge to all datacenters
+                       $ok = $this->relayDelete( $key ) && $ok;
+               } else {
+                       // Update the local datacenter immediately
+                       $ok = $this->cache->set( $key, self::PURGE_VAL_PREFIX . microtime( true ), $ttl );
+                       // Publish the purge to all datacenters
+                       $ok = $this->relayPurge( $key, $ttl ) && $ok;
+               }
+
+               return $ok;
        }
 
        /**
index 2565fb5..a00b973 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Local backports:
+ *
+ * - 4fbbc737c86b500c11bbb471ec1001c50ab8853c
+ *   SelectFileWidget: Use i18n string for button label
+ *   We totally forgot to use a localisation message we carefully introduced.
+ */
+
 /*!
  * OOjs UI v0.13.3
  * https://www.mediawiki.org/wiki/OOjs_UI
@@ -14234,7 +14242,7 @@ OO.ui.SelectFileWidget = function OoUiSelectFileWidget( config ) {
 
        this.selectButton = new OO.ui.ButtonWidget( {
                classes: [ 'oo-ui-selectFileWidget-selectButton' ],
-               label: 'Select a file',
+               label: OO.ui.msg( 'ooui-selectfile-button-select' ),
                disabled: this.disabled || !this.isSupported
        } );
 
index 622fce2..f338633 100644 (file)
@@ -108,6 +108,16 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase {
                        '11 args' => array( array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) ),
                );
        }
+
+       /**
+        * @expectedException InvalidArgumentException
+        */
+       public function testNamedArgs() {
+               $args = array( 'foo' => 1, 'bar' => 2, 'baz' => 3 );
+               $obj = ObjectFactory::constructClassInstance(
+                       'ObjectFactoryTestFixture', $args
+               );
+       }
 }
 
 class ObjectFactoryTestFixture {
index 90b4bd0..e2c6ac7 100644 (file)
@@ -391,8 +391,22 @@ class WANObjectCacheTest extends MediaWikiTestCase {
                $this->assertLessThan( 0, $curTTL, "Deleted key has current TTL < 0" );
 
                $this->cache->set( $key, $value . 'more' );
+               $v = $this->cache->get( $key, $curTTL );
                $this->assertFalse( $v, "Deleted key is tombstoned and has false value" );
                $this->assertLessThan( 0, $curTTL, "Deleted key is tombstoned and has current TTL < 0" );
+
+               $this->cache->set( $key, $value );
+               $this->cache->delete( $key, WANObjectCache::HOLDOFF_NONE );
+
+               $curTTL = null;
+               $v = $this->cache->get( $key, $curTTL );
+               $this->assertFalse( $v, "Deleted key has false value" );
+               $this->assertNull( $curTTL, "Deleted key has null current TTL" );
+
+               $this->cache->set( $key, $value );
+               $v = $this->cache->get( $key, $curTTL );
+               $this->assertEquals( $value, $v, "Key was created with value" );
+               $this->assertGreaterThan( 0, $curTTL, "Existing key has current TTL > 0" );
        }
 
        /**