Merge "rdbms: optimize Database::selectDomain() to avoid extra queries"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 8 Mar 2019 23:37:14 +0000 (23:37 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 8 Mar 2019 23:37:14 +0000 (23:37 +0000)
26 files changed:
.phpcs.xml
RELEASE-NOTES-1.33
autoload.php
includes/api/ApiQueryLogEvents.php
includes/cache/CacheDependency.php [deleted file]
includes/cache/dependency/CacheDependency.php [new file with mode: 0644]
includes/cache/dependency/ConstantDependency.php [new file with mode: 0644]
includes/cache/dependency/DependencyWrapper.php [new file with mode: 0644]
includes/cache/dependency/FileDependency.php [new file with mode: 0644]
includes/cache/dependency/GlobalDependency.php [new file with mode: 0644]
includes/cache/dependency/MainConfigDependency.php [new file with mode: 0644]
includes/libs/objectcache/BagOStuff.php
includes/libs/objectcache/CachedBagOStuff.php
includes/libs/objectcache/IExpiringStore.php
includes/libs/objectcache/MemcachedBagOStuff.php
includes/libs/objectcache/RedisBagOStuff.php
includes/libs/objectcache/WANObjectCache.php
includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderContext.php
resources/src/jquery.tablesorter/jquery.tablesorter.js
resources/src/mediawiki.skinning/elements.css
tests/phpunit/ResourceLoaderTestCase.php
tests/phpunit/includes/OutputPageTest.php
tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index 5a639ad..171cfaf 100644 (file)
@@ -74,7 +74,6 @@
                <exclude-pattern>*/includes/RevisionList\.php</exclude-pattern>
                <exclude-pattern>*/includes/installer/PhpBugTests\.php</exclude-pattern>
                <exclude-pattern>*/includes/specials/SpecialMostinterwikis\.php</exclude-pattern>
-               <exclude-pattern>*/includes/cache/CacheDependency\.php</exclude-pattern>
                <exclude-pattern>*/includes/compat/XMPReader\.php</exclude-pattern>
                <exclude-pattern>*/includes/diff/DairikiDiff\.php</exclude-pattern>
                <exclude-pattern>*/includes/specials/SpecialAncientpages\.php</exclude-pattern>
                <exclude-pattern>*/includes/api/ApiMessage\.php</exclude-pattern>
                <exclude-pattern>*/includes/api/ApiOpenSearch\.php</exclude-pattern>
                <exclude-pattern>*/includes/api/ApiRsd\.php</exclude-pattern>
-               <exclude-pattern>*/includes/cache/CacheDependency\.php</exclude-pattern>
                <exclude-pattern>*/includes/compat/XMPReader\.php</exclude-pattern>
                <exclude-pattern>*/includes/diff/DairikiDiff\.php</exclude-pattern>
                <exclude-pattern>*/includes/diff/DiffEngine\.php</exclude-pattern>
index b9331bc..0180763 100644 (file)
@@ -284,6 +284,7 @@ because of Phabricator reports.
 * (T217772) The 'wgAvailableSkins' mw.config key in JavaScript, was removed.
 * Language::markNoConversion, deprecated in 1.32, has been removed. Use
   LanguageConverter::markNoConversion instead.
+* BagOStuff::modifySimpleRelayEvent() method has been removed.
 
 === Deprecations in 1.33 ===
 * The configuration option $wgUseESI has been deprecated, and is expected
index be37737..403b610 100644 (file)
@@ -217,7 +217,7 @@ $wgAutoloadLocalClasses = [
        'BufferingStatsdDataFactory' => __DIR__ . '/includes/libs/stats/BufferingStatsdDataFactory.php',
        'CLIParser' => __DIR__ . '/maintenance/parse.php',
        'CSSMin' => __DIR__ . '/includes/libs/CSSMin.php',
-       'CacheDependency' => __DIR__ . '/includes/cache/CacheDependency.php',
+       'CacheDependency' => __DIR__ . '/includes/cache/dependency/CacheDependency.php',
        'CacheHelper' => __DIR__ . '/includes/cache/CacheHelper.php',
        'CacheTime' => __DIR__ . '/includes/parser/CacheTime.php',
        'CachedAction' => __DIR__ . '/includes/actions/CachedAction.php',
@@ -303,7 +303,7 @@ $wgAutoloadLocalClasses = [
        'ConfigException' => __DIR__ . '/includes/config/ConfigException.php',
        'ConfigFactory' => __DIR__ . '/includes/config/ConfigFactory.php',
        'ConfiguredReadOnlyMode' => __DIR__ . '/includes/ConfiguredReadOnlyMode.php',
-       'ConstantDependency' => __DIR__ . '/includes/cache/CacheDependency.php',
+       'ConstantDependency' => __DIR__ . '/includes/cache/dependency/ConstantDependency.php',
        'Content' => __DIR__ . '/includes/content/Content.php',
        'ContentHandler' => __DIR__ . '/includes/content/ContentHandler.php',
        'ContentModelLogFormatter' => __DIR__ . '/includes/logging/ContentModelLogFormatter.php',
@@ -387,7 +387,7 @@ $wgAutoloadLocalClasses = [
        'DeleteSelfExternals' => __DIR__ . '/maintenance/deleteSelfExternals.php',
        'DeletedContribsPager' => __DIR__ . '/includes/specials/pagers/DeletedContribsPager.php',
        'DeletedContributionsPage' => __DIR__ . '/includes/specials/SpecialDeletedContributions.php',
-       'DependencyWrapper' => __DIR__ . '/includes/cache/CacheDependency.php',
+       'DependencyWrapper' => __DIR__ . '/includes/cache/dependency/DependencyWrapper.php',
        'DeprecatedGlobal' => __DIR__ . '/includes/DeprecatedGlobal.php',
        'DeprecatedInterfaceFinder' => __DIR__ . '/maintenance/findDeprecated.php',
        'DeprecationHelper' => __DIR__ . '/includes/debug/DeprecationHelper.php',
@@ -519,7 +519,7 @@ $wgAutoloadLocalClasses = [
        'FileContentHandler' => __DIR__ . '/includes/content/FileContentHandler.php',
        'FileContentsHasher' => __DIR__ . '/includes/utils/FileContentsHasher.php',
        'FileDeleteForm' => __DIR__ . '/includes/FileDeleteForm.php',
-       'FileDependency' => __DIR__ . '/includes/cache/CacheDependency.php',
+       'FileDependency' => __DIR__ . '/includes/cache/dependency/FileDependency.php',
        'FileDuplicateSearchPage' => __DIR__ . '/includes/specials/SpecialFileDuplicateSearch.php',
        'FileJournal' => __DIR__ . '/includes/libs/filebackend/filejournal/FileJournal.php',
        'FileOp' => __DIR__ . '/includes/libs/filebackend/fileop/FileOp.php',
@@ -569,7 +569,7 @@ $wgAutoloadLocalClasses = [
        'GetReplicaServer' => __DIR__ . '/maintenance/getReplicaServer.php',
        'GetTextMaint' => __DIR__ . '/maintenance/getText.php',
        'GitInfo' => __DIR__ . '/includes/GitInfo.php',
-       'GlobalDependency' => __DIR__ . '/includes/cache/CacheDependency.php',
+       'GlobalDependency' => __DIR__ . '/includes/cache/dependency/GlobalDependency.php',
        'GlobalVarConfig' => __DIR__ . '/includes/config/GlobalVarConfig.php',
        'GuzzleHttpRequest' => __DIR__ . '/includes/http/GuzzleHttpRequest.php',
        'HHVMMakeRepo' => __DIR__ . '/maintenance/hhvm/makeRepo.php',
@@ -845,7 +845,7 @@ $wgAutoloadLocalClasses = [
        'MagicWordArray' => __DIR__ . '/includes/MagicWordArray.php',
        'MagicWordFactory' => __DIR__ . '/includes/MagicWordFactory.php',
        'MailAddress' => __DIR__ . '/includes/mail/MailAddress.php',
-       'MainConfigDependency' => __DIR__ . '/includes/cache/CacheDependency.php',
+       'MainConfigDependency' => __DIR__ . '/includes/cache/dependency/MainConfigDependency.php',
        'MaintainableDBConnRef' => __DIR__ . '/includes/libs/rdbms/database/MaintainableDBConnRef.php',
        'Maintenance' => __DIR__ . '/maintenance/Maintenance.php',
        'MakeTestEdits' => __DIR__ . '/maintenance/makeTestEdits.php',
index cc11c48..7798688 100644 (file)
@@ -183,6 +183,10 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                $db, 'log_user', User::newFromName( $params['user'], false )
                        );
                        $this->addWhere( $q['conds'] );
+
+                       // T71222: MariaDB's optimizer, at least 10.1.37 and .38, likes to choose a wildly bad plan for
+                       // some reason for this code path. Tell it not to use the wrong index it wants to pick.
+                       $this->addOption( 'IGNORE INDEX', [ 'logging' => [ 'times' ] ] );
                }
 
                $title = $params['title'];
diff --git a/includes/cache/CacheDependency.php b/includes/cache/CacheDependency.php
deleted file mode 100644 (file)
index 11df5bc..0000000
+++ /dev/null
@@ -1,293 +0,0 @@
-<?php
-/**
- * Data caching with dependencies.
- *
- * 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
- * @ingroup Cache
- */
-use MediaWiki\MediaWikiServices;
-
-/**
- * This class stores an arbitrary value along with its dependencies.
- * Users should typically only use DependencyWrapper::getValueFromCache(),
- * rather than instantiating one of these objects directly.
- * @ingroup Cache
- */
-class DependencyWrapper {
-       private $value;
-       /** @var CacheDependency[] */
-       private $deps;
-
-       /**
-        * @param mixed $value The user-supplied value
-        * @param CacheDependency|CacheDependency[] $deps A dependency or dependency
-        *   array. All dependencies must be objects implementing CacheDependency.
-        */
-       function __construct( $value = false, $deps = [] ) {
-               $this->value = $value;
-
-               if ( !is_array( $deps ) ) {
-                       $deps = [ $deps ];
-               }
-
-               $this->deps = $deps;
-       }
-
-       /**
-        * Returns true if any of the dependencies have expired
-        *
-        * @return bool
-        */
-       function isExpired() {
-               foreach ( $this->deps as $dep ) {
-                       if ( $dep->isExpired() ) {
-                               return true;
-                       }
-               }
-
-               return false;
-       }
-
-       /**
-        * Initialise dependency values in preparation for storing. This must be
-        * called before serialization.
-        */
-       function initialiseDeps() {
-               foreach ( $this->deps as $dep ) {
-                       $dep->loadDependencyValues();
-               }
-       }
-
-       /**
-        * Get the user-defined value
-        * @return bool|mixed
-        */
-       function getValue() {
-               return $this->value;
-       }
-
-       /**
-        * Store the wrapper to a cache
-        *
-        * @param BagOStuff $cache
-        * @param string $key
-        * @param int $expiry
-        */
-       function storeToCache( $cache, $key, $expiry = 0 ) {
-               $this->initialiseDeps();
-               $cache->set( $key, $this, $expiry );
-       }
-
-       /**
-        * Attempt to get a value from the cache. If the value is expired or missing,
-        * it will be generated with the callback function (if present), and the newly
-        * calculated value will be stored to the cache in a wrapper.
-        *
-        * @param BagOStuff $cache
-        * @param string $key The cache key
-        * @param int $expiry The expiry timestamp or interval in seconds
-        * @param bool|callable $callback The callback for generating the value, or false
-        * @param array $callbackParams The function parameters for the callback
-        * @param array $deps The dependencies to store on a cache miss. Note: these
-        *    are not the dependencies used on a cache hit! Cache hits use the stored
-        *    dependency array.
-        *
-        * @return mixed The value, or null if it was not present in the cache and no
-        *    callback was defined.
-        */
-       static function getValueFromCache( $cache, $key, $expiry = 0, $callback = false,
-               $callbackParams = [], $deps = []
-       ) {
-               $obj = $cache->get( $key );
-
-               if ( is_object( $obj ) && $obj instanceof DependencyWrapper && !$obj->isExpired() ) {
-                       $value = $obj->value;
-               } elseif ( $callback ) {
-                       $value = $callback( ...$callbackParams );
-                       # Cache the newly-generated value
-                       $wrapper = new DependencyWrapper( $value, $deps );
-                       $wrapper->storeToCache( $cache, $key, $expiry );
-               } else {
-                       $value = null;
-               }
-
-               return $value;
-       }
-}
-
-/**
- * @ingroup Cache
- */
-abstract class CacheDependency {
-       /**
-        * Returns true if the dependency is expired, false otherwise
-        */
-       abstract function isExpired();
-
-       /**
-        * Hook to perform any expensive pre-serialize loading of dependency values.
-        */
-       function loadDependencyValues() {
-       }
-}
-
-/**
- * @ingroup Cache
- */
-class FileDependency extends CacheDependency {
-       private $filename;
-       private $timestamp;
-
-       /**
-        * Create a file dependency
-        *
-        * @param string $filename The name of the file, preferably fully qualified
-        * @param null|bool|int $timestamp The unix last modified timestamp, or false if the
-        *        file does not exist. If omitted, the timestamp will be loaded from
-        *        the file.
-        *
-        * A dependency on a nonexistent file will be triggered when the file is
-        * created. A dependency on an existing file will be triggered when the
-        * file is changed.
-        */
-       function __construct( $filename, $timestamp = null ) {
-               $this->filename = $filename;
-               $this->timestamp = $timestamp;
-       }
-
-       /**
-        * @return array
-        */
-       function __sleep() {
-               $this->loadDependencyValues();
-
-               return [ 'filename', 'timestamp' ];
-       }
-
-       function loadDependencyValues() {
-               if ( is_null( $this->timestamp ) ) {
-                       Wikimedia\suppressWarnings();
-                       # Dependency on a non-existent file stores "false"
-                       # This is a valid concept!
-                       $this->timestamp = filemtime( $this->filename );
-                       Wikimedia\restoreWarnings();
-               }
-       }
-
-       /**
-        * @return bool
-        */
-       function isExpired() {
-               Wikimedia\suppressWarnings();
-               $lastmod = filemtime( $this->filename );
-               Wikimedia\restoreWarnings();
-               if ( $lastmod === false ) {
-                       if ( $this->timestamp === false ) {
-                               # Still nonexistent
-                               return false;
-                       } else {
-                               # Deleted
-                               wfDebug( "Dependency triggered: {$this->filename} deleted.\n" );
-
-                               return true;
-                       }
-               } else {
-                       if ( $lastmod > $this->timestamp ) {
-                               # Modified or created
-                               wfDebug( "Dependency triggered: {$this->filename} changed.\n" );
-
-                               return true;
-                       } else {
-                               # Not modified
-                               return false;
-                       }
-               }
-       }
-}
-
-/**
- * @ingroup Cache
- */
-class GlobalDependency extends CacheDependency {
-       private $name;
-       private $value;
-
-       function __construct( $name ) {
-               $this->name = $name;
-               $this->value = $GLOBALS[$name];
-       }
-
-       /**
-        * @return bool
-        */
-       function isExpired() {
-               if ( !isset( $GLOBALS[$this->name] ) ) {
-                       return true;
-               }
-
-               return $GLOBALS[$this->name] != $this->value;
-       }
-}
-
-/**
- * @ingroup Cache
- */
-class MainConfigDependency extends CacheDependency {
-       private $name;
-       private $value;
-
-       function __construct( $name ) {
-               $this->name = $name;
-               $this->value = $this->getConfig()->get( $this->name );
-       }
-
-       private function getConfig() {
-               return MediaWikiServices::getInstance()->getMainConfig();
-       }
-
-       /**
-        * @return bool
-        */
-       function isExpired() {
-               if ( !$this->getConfig()->has( $this->name ) ) {
-                       return true;
-               }
-
-               return $this->getConfig()->get( $this->name ) != $this->value;
-       }
-}
-
-/**
- * @ingroup Cache
- */
-class ConstantDependency extends CacheDependency {
-       private $name;
-       private $value;
-
-       function __construct( $name ) {
-               $this->name = $name;
-               $this->value = constant( $name );
-       }
-
-       /**
-        * @return bool
-        */
-       function isExpired() {
-               return constant( $this->name ) != $this->value;
-       }
-}
diff --git a/includes/cache/dependency/CacheDependency.php b/includes/cache/dependency/CacheDependency.php
new file mode 100644 (file)
index 0000000..2e4711f
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Data caching with dependencies.
+ *
+ * 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
+ * @ingroup Cache
+ */
+
+/**
+ * @ingroup Cache
+ */
+abstract class CacheDependency {
+       /**
+        * Returns true if the dependency is expired, false otherwise
+        */
+       abstract function isExpired();
+
+       /**
+        * Hook to perform any expensive pre-serialize loading of dependency values.
+        */
+       function loadDependencyValues() {
+       }
+}
diff --git a/includes/cache/dependency/ConstantDependency.php b/includes/cache/dependency/ConstantDependency.php
new file mode 100644 (file)
index 0000000..079e99f
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Data caching with dependencies.
+ *
+ * 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
+ * @ingroup Cache
+ */
+
+/**
+ * @ingroup Cache
+ */
+class ConstantDependency extends CacheDependency {
+       private $name;
+       private $value;
+
+       function __construct( $name ) {
+               $this->name = $name;
+               $this->value = constant( $name );
+       }
+
+       /**
+        * @return bool
+        */
+       function isExpired() {
+               return constant( $this->name ) != $this->value;
+       }
+}
diff --git a/includes/cache/dependency/DependencyWrapper.php b/includes/cache/dependency/DependencyWrapper.php
new file mode 100644 (file)
index 0000000..43d659c
--- /dev/null
@@ -0,0 +1,130 @@
+<?php
+/**
+ * Data caching with dependencies.
+ *
+ * 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
+ * @ingroup Cache
+ */
+
+/**
+ * This class stores an arbitrary value along with its dependencies.
+ * Users should typically only use DependencyWrapper::getValueFromCache(),
+ * rather than instantiating one of these objects directly.
+ * @ingroup Cache
+ */
+class DependencyWrapper {
+       private $value;
+       /** @var CacheDependency[] */
+       private $deps;
+
+       /**
+        * @param mixed $value The user-supplied value
+        * @param CacheDependency|CacheDependency[] $deps A dependency or dependency
+        *   array. All dependencies must be objects implementing CacheDependency.
+        */
+       function __construct( $value = false, $deps = [] ) {
+               $this->value = $value;
+
+               if ( !is_array( $deps ) ) {
+                       $deps = [ $deps ];
+               }
+
+               $this->deps = $deps;
+       }
+
+       /**
+        * Returns true if any of the dependencies have expired
+        *
+        * @return bool
+        */
+       function isExpired() {
+               foreach ( $this->deps as $dep ) {
+                       if ( $dep->isExpired() ) {
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+
+       /**
+        * Initialise dependency values in preparation for storing. This must be
+        * called before serialization.
+        */
+       function initialiseDeps() {
+               foreach ( $this->deps as $dep ) {
+                       $dep->loadDependencyValues();
+               }
+       }
+
+       /**
+        * Get the user-defined value
+        * @return bool|mixed
+        */
+       function getValue() {
+               return $this->value;
+       }
+
+       /**
+        * Store the wrapper to a cache
+        *
+        * @param BagOStuff $cache
+        * @param string $key
+        * @param int $expiry
+        */
+       function storeToCache( $cache, $key, $expiry = 0 ) {
+               $this->initialiseDeps();
+               $cache->set( $key, $this, $expiry );
+       }
+
+       /**
+        * Attempt to get a value from the cache. If the value is expired or missing,
+        * it will be generated with the callback function (if present), and the newly
+        * calculated value will be stored to the cache in a wrapper.
+        *
+        * @param BagOStuff $cache
+        * @param string $key The cache key
+        * @param int $expiry The expiry timestamp or interval in seconds
+        * @param bool|callable $callback The callback for generating the value, or false
+        * @param array $callbackParams The function parameters for the callback
+        * @param array $deps The dependencies to store on a cache miss. Note: these
+        *    are not the dependencies used on a cache hit! Cache hits use the stored
+        *    dependency array.
+        *
+        * @return mixed The value, or null if it was not present in the cache and no
+        *    callback was defined.
+        */
+       static function getValueFromCache( $cache, $key, $expiry = 0, $callback = false,
+               $callbackParams = [], $deps = []
+       ) {
+               $obj = $cache->get( $key );
+
+               if ( is_object( $obj ) && $obj instanceof DependencyWrapper && !$obj->isExpired() ) {
+                       $value = $obj->value;
+               } elseif ( $callback ) {
+                       $value = $callback( ...$callbackParams );
+                       # Cache the newly-generated value
+                       $wrapper = new DependencyWrapper( $value, $deps );
+                       $wrapper->storeToCache( $cache, $key, $expiry );
+               } else {
+                       $value = null;
+               }
+
+               return $value;
+       }
+}
diff --git a/includes/cache/dependency/FileDependency.php b/includes/cache/dependency/FileDependency.php
new file mode 100644 (file)
index 0000000..8d199e2
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+/**
+ * Data caching with dependencies.
+ *
+ * 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
+ * @ingroup Cache
+ */
+
+/**
+ * @ingroup Cache
+ */
+class FileDependency extends CacheDependency {
+       private $filename;
+       private $timestamp;
+
+       /**
+        * Create a file dependency
+        *
+        * @param string $filename The name of the file, preferably fully qualified
+        * @param null|bool|int $timestamp The unix last modified timestamp, or false if the
+        *        file does not exist. If omitted, the timestamp will be loaded from
+        *        the file.
+        *
+        * A dependency on a nonexistent file will be triggered when the file is
+        * created. A dependency on an existing file will be triggered when the
+        * file is changed.
+        */
+       function __construct( $filename, $timestamp = null ) {
+               $this->filename = $filename;
+               $this->timestamp = $timestamp;
+       }
+
+       /**
+        * @return array
+        */
+       function __sleep() {
+               $this->loadDependencyValues();
+
+               return [ 'filename', 'timestamp' ];
+       }
+
+       function loadDependencyValues() {
+               if ( is_null( $this->timestamp ) ) {
+                       Wikimedia\suppressWarnings();
+                       # Dependency on a non-existent file stores "false"
+                       # This is a valid concept!
+                       $this->timestamp = filemtime( $this->filename );
+                       Wikimedia\restoreWarnings();
+               }
+       }
+
+       /**
+        * @return bool
+        */
+       function isExpired() {
+               Wikimedia\suppressWarnings();
+               $lastmod = filemtime( $this->filename );
+               Wikimedia\restoreWarnings();
+               if ( $lastmod === false ) {
+                       if ( $this->timestamp === false ) {
+                               # Still nonexistent
+                               return false;
+                       } else {
+                               # Deleted
+                               wfDebug( "Dependency triggered: {$this->filename} deleted.\n" );
+
+                               return true;
+                       }
+               } else {
+                       if ( $lastmod > $this->timestamp ) {
+                               # Modified or created
+                               wfDebug( "Dependency triggered: {$this->filename} changed.\n" );
+
+                               return true;
+                       } else {
+                               # Not modified
+                               return false;
+                       }
+               }
+       }
+}
diff --git a/includes/cache/dependency/GlobalDependency.php b/includes/cache/dependency/GlobalDependency.php
new file mode 100644 (file)
index 0000000..be1d345
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Data caching with dependencies.
+ *
+ * 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
+ * @ingroup Cache
+ */
+
+/**
+ * @ingroup Cache
+ */
+class GlobalDependency extends CacheDependency {
+       private $name;
+       private $value;
+
+       function __construct( $name ) {
+               $this->name = $name;
+               $this->value = $GLOBALS[$name];
+       }
+
+       /**
+        * @return bool
+        */
+       function isExpired() {
+               if ( !isset( $GLOBALS[$this->name] ) ) {
+                       return true;
+               }
+
+               return $GLOBALS[$this->name] != $this->value;
+       }
+}
diff --git a/includes/cache/dependency/MainConfigDependency.php b/includes/cache/dependency/MainConfigDependency.php
new file mode 100644 (file)
index 0000000..dd33a2e
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Data caching with dependencies.
+ *
+ * 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
+ * @ingroup Cache
+ */
+use MediaWiki\MediaWikiServices;
+
+/**
+ * @ingroup Cache
+ */
+class MainConfigDependency extends CacheDependency {
+       private $name;
+       private $value;
+
+       function __construct( $name ) {
+               $this->name = $name;
+               $this->value = $this->getConfig()->get( $this->name );
+       }
+
+       private function getConfig() {
+               return MediaWikiServices::getInstance()->getMainConfig();
+       }
+
+       /**
+        * @return bool
+        */
+       function isExpired() {
+               if ( !$this->getConfig()->has( $this->name ) ) {
+                       return true;
+               }
+
+               return $this->getConfig()->get( $this->name ) != $this->value;
+       }
+}
index a3c020e..9fa3232 100644 (file)
@@ -87,12 +87,6 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
        /** @var int[] Map of (ATTR_* class constant => QOS_* class constant) */
        protected $attrMap = [];
 
-       /** Possible values for getLastError() */
-       const ERR_NONE = 0; // no error
-       const ERR_NO_RESPONSE = 1; // no response
-       const ERR_UNREACHABLE = 2; // can't connect
-       const ERR_UNEXPECTED = 3; // response gave some error
-
        /** Bitfield constants for get()/getMulti() */
        const READ_LATEST = 1; // use latest data for replicated stores
        const READ_VERIFIED = 2; // promise that caller can tell when keys are stale
@@ -729,24 +723,6 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
                $this->busyCallbacks[] = $workCallback;
        }
 
-       /**
-        * Modify a cache update operation array for EventRelayer::notify()
-        *
-        * This is used for relayed writes, e.g. for broadcasting a change
-        * to multiple data-centers. If the array contains a 'val' field
-        * then the command involves setting a key to that value. Note that
-        * for simplicity, 'val' is always a simple scalar value. This method
-        * is used to possibly serialize the value and add any cache-specific
-        * key/values needed for the relayer daemon (e.g. memcached flags).
-        *
-        * @param array $event
-        * @return array
-        * @since 1.26
-        */
-       public function modifySimpleRelayEvent( array $event ) {
-               return $event;
-       }
-
        /**
         * @param string $text
         */
index 3927ed3..25fcdb0 100644 (file)
@@ -117,9 +117,5 @@ class CachedBagOStuff extends HashBagOStuff {
                return $this->backend->clearLastError();
        }
 
-       public function modifySimpleRelayEvent( array $event ) {
-               return $this->backend->modifySimpleRelayEvent( $event );
-       }
-
        // @codeCoverageIgnoreEnd
 }
index 7bab20a..c1edff7 100644 (file)
@@ -56,4 +56,9 @@ interface IExpiringStore {
        const QOS_SYNCWRITES_SS = 4; // strict-serializable, nodes refuse reads if possible stale
        // Generic "unknown" value that is useful for comparisons (e.g. always good enough)
        const QOS_UNKNOWN = INF;
+
+       const ERR_NONE = 0; // no error
+       const ERR_NO_RESPONSE = 1; // no response
+       const ERR_UNREACHABLE = 2; // can't connect
+       const ERR_UNEXPECTED = 3; // response gave some error
 }
index bf0da11..47e04d0 100644 (file)
@@ -181,12 +181,4 @@ class MemcachedBagOStuff extends BagOStuff {
        protected function debugLog( $text ) {
                $this->logger->debug( $text );
        }
-
-       public function modifySimpleRelayEvent( array $event ) {
-               if ( array_key_exists( 'val', $event ) ) {
-                       $event['flg'] = 0; // data is not serialized nor gzipped (for memcached driver)
-               }
-
-               return $event;
-       }
 }
index a0febfc..3926604 100644 (file)
@@ -317,14 +317,6 @@ class RedisBagOStuff extends BagOStuff {
                return $result;
        }
 
-       public function modifySimpleRelayEvent( array $event ) {
-               if ( array_key_exists( 'val', $event ) ) {
-                       $event['val'] = serialize( $event['val'] ); // this class uses PHP serialization
-               }
-
-               return $event;
-       }
-
        /**
         * @param mixed $data
         * @return string
index bed7965..41a3e4e 100644 (file)
@@ -214,12 +214,6 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        const FLD_FLAGS = 4; // key to the flags bitfield (reserved number)
        const FLD_HOLDOFF = 5; // key to any hold-off TTL
 
-       const ERR_NONE = 0; // no error
-       const ERR_NO_RESPONSE = 1; // no response
-       const ERR_UNREACHABLE = 2; // can't connect
-       const ERR_UNEXPECTED = 3; // response gave some error
-       const ERR_RELAY = 4; // relay broadcast failed
-
        const VALUE_KEY_PREFIX = 'WANCache:v:';
        const INTERIM_KEY_PREFIX = 'WANCache:i:';
        const TIME_KEY_PREFIX = 'WANCache:t:';
@@ -237,7 +231,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         * @param array $params
         *   - cache    : BagOStuff object for a persistent cache
         *   - logger   : LoggerInterface object
-        *   - stats    : LoggerInterface object
+        *   - stats    : StatsdDataFactoryInterface object
         *   - asyncHandler : A function that takes a callback and runs it later. If supplied,
         *       whenever a preemptive refresh would be triggered in getWithSetCallback(), the
         *       current cache value is still used instead. However, the async-handler function
@@ -696,16 +690,17 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         * @return bool True if the item was purged or not found, false on failure
         */
        final public function delete( $key, $ttl = self::HOLDOFF_TTL ) {
-               $key = self::VALUE_KEY_PREFIX . $key;
-
                if ( $ttl <= 0 ) {
                        // Publish the purge to all datacenters
-                       $ok = $this->relayDelete( $key );
+                       $ok = $this->relayDelete( self::VALUE_KEY_PREFIX . $key );
                } else {
                        // Publish the purge to all datacenters
-                       $ok = $this->relayPurge( $key, $ttl, self::HOLDOFF_NONE );
+                       $ok = $this->relayPurge( self::VALUE_KEY_PREFIX . $key, $ttl, self::HOLDOFF_NONE );
                }
 
+               $kClass = $this->determineKeyClassForStats( $key );
+               $this->stats->increment( "wanobjectcache.$kClass.delete." . ( $ok ? 'ok' : 'error' ) );
+
                return $ok;
        }
 
@@ -860,7 +855,12 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         */
        final public function touchCheckKey( $key, $holdoff = self::HOLDOFF_TTL ) {
                // Publish the purge to all datacenters
-               return $this->relayPurge( self::TIME_KEY_PREFIX . $key, self::CHECK_KEY_TTL, $holdoff );
+               $ok = $this->relayPurge( self::TIME_KEY_PREFIX . $key, self::CHECK_KEY_TTL, $holdoff );
+
+               $kClass = $this->determineKeyClassForStats( $key );
+               $this->stats->increment( "wanobjectcache.$kClass.ck_touch." . ( $ok ? 'ok' : 'error' ) );
+
+               return $ok;
        }
 
        /**
@@ -892,7 +892,12 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         */
        final public function resetCheckKey( $key ) {
                // Publish the purge to all datacenters
-               return $this->relayDelete( self::TIME_KEY_PREFIX . $key );
+               $ok = $this->relayDelete( self::TIME_KEY_PREFIX . $key );
+
+               $kClass = $this->determineKeyClassForStats( $key );
+               $this->stats->increment( "wanobjectcache.$kClass.ck_reset." . ( $ok ? 'ok' : 'error' ) );
+
+               return $ok;
        }
 
        /**
@@ -1288,8 +1293,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                $touchedCb = $opts['touchedCallback'] ?? null;
                $initialTime = $this->getCurrentTime();
 
-               // Get a collection name to describe this class of key
-               $kClass = $this->determineKeyClass( $key );
+               $kClass = $this->determineKeyClassForStats( $key );
 
                // Get the current key value
                $curTTL = self::PASS_BY_REF;
@@ -2299,9 +2303,9 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
 
        /**
         * @param string $key String of the format <scope>:<class>[:<class or variable>]...
-        * @return string
+        * @return string A collection name to describe this class of key
         */
-       protected function determineKeyClass( $key ) {
+       protected function determineKeyClassForStats( $key ) {
                $parts = explode( ':', $key );
 
                return $parts[1] ?? $parts[0]; // sanity
index 3d13350..5712692 100644 (file)
@@ -1106,7 +1106,7 @@ MESSAGE;
                                                                // mw.loader.implement will use globalEval if scripts is a string.
                                                                // Minify manually here, because general response minification is
                                                                // not effective due it being a string literal, not a function.
-                                                               if ( !self::inDebugMode() ) {
+                                                               if ( !$context->getDebug() ) {
                                                                        $scripts = self::filter( 'minify-js', $scripts ); // T107377
                                                                }
                                                        } else {
@@ -1695,8 +1695,10 @@ MESSAGE;
                        'modules' => self::makePackedModulesString( $modules ),
                        'lang' => $lang,
                        'skin' => $skin,
-                       'debug' => $debug ? 'true' : 'false',
                ];
+               if ( $debug === true ) {
+                       $query['debug'] = 'true';
+               }
                if ( $user !== null ) {
                        $query['user'] = $user;
                }
index 67de192..a625970 100644 (file)
@@ -72,10 +72,7 @@ class ResourceLoaderContext implements MessageLocalizer {
 
                // Various parameters
                $this->user = $request->getRawVal( 'user' );
-               $this->debug = $request->getFuzzyBool(
-                       'debug',
-                       $this->getConfig()->get( 'ResourceLoaderDebug' )
-               );
+               $this->debug = $request->getRawVal( 'debug' ) === 'true';
                $this->only = $request->getRawVal( 'only', null );
                $this->version = $request->getRawVal( 'version', null );
                $this->raw = $request->getFuzzyBool( 'raw' );
index a5a1783..b73f430 100644 (file)
         * @return {string}
         */
        function getElementSortKey( node ) {
-               var $node = $( node ),
-                       // Use data-sort-value attribute.
-                       // Use data() instead of attr() so that live value changes
-                       // are processed as well (T40152).
-                       data = $node.data( 'sortValue' );
+               // Get data-sort-value attribute. Uses jQuery to allow live value
+               // changes from other code paths via data(), which reside only in jQuery.
+               // Must use $().data() instead of $.data(), as the latter *only*
+               // accesses the live values, without reading HTML5 attribs first (T40152).
+               var data = $( node ).data( 'sortValue' );
 
                if ( data !== null && data !== undefined ) {
                        // Cast any numbers or other stuff to a string, methods
                        return String( data );
                }
                if ( node.tagName.toLowerCase() === 'img' ) {
-                       return $node.attr( 'alt' ) || ''; // handle undefined alt
+                       return node.alt;
                }
-               return $.makeArray( node.childNodes ).map( function ( elem ) {
+               // Iterate the NodeList (not an array).
+               // Also uses null-return as filter in the same pass.
+               // eslint-disable-next-line no-jquery/no-map-util
+               return $.map( node.childNodes, function ( elem ) {
                        if ( elem.nodeType === Node.ELEMENT_NODE ) {
                                if ( $( elem ).hasClass( 'reference' ) ) {
                                        return null;
-                               } else {
-                                       return getElementSortKey( elem );
                                }
+                               return getElementSortKey( elem );
+                       }
+                       if ( elem.nodeType === Node.TEXT_NODE ) {
+                               return elem.textContent;
                        }
-                       return $.text( elem );
+                       // Ignore other node types, such as HTML comments.
+                       return null;
                } ).join( '' );
        }
 
index db9265a..a33595c 100644 (file)
@@ -184,7 +184,6 @@ p img {
 }
 
 ul {
-       list-style-type: square;
        margin: 0.3em 0 0 1.6em;
        padding: 0;
 }
index cadd0ff..ca5ff6c 100644 (file)
@@ -26,6 +26,7 @@ abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
                        $options = [ 'lang' => $options ];
                }
                $options += [
+                       'debug' => 'true',
                        'lang' => 'en',
                        'dir' => 'ltr',
                        'skin' => 'vector',
@@ -35,6 +36,7 @@ abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
                ];
                $resourceLoader = $rl ?: new ResourceLoader();
                $request = new FauxRequest( [
+                               'debug' => $options['debug'],
                                'lang' => $options['lang'],
                                'modules' => $options['modules'],
                                'only' => $options['only'],
index abc7c43..aa14124 100644 (file)
@@ -2574,14 +2574,14 @@ class OutputPageTest extends MediaWikiTestCase {
                        [
                                [ 'test.foo', ResourceLoaderModule::TYPE_SCRIPTS ],
                                "<script nonce=\"secret\">(window.RLQ=window.RLQ||[]).push(function(){"
-                                       . 'mw.loader.load("http://127.0.0.1:8080/w/load.php?debug=false\u0026lang=en\u0026modules=test.foo\u0026only=scripts\u0026skin=fallback");'
+                                       . 'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.foo\u0026only=scripts\u0026skin=fallback");'
                                        . "});</script>"
                        ],
                        // Multiple only=styles load
                        [
                                [ [ 'test.baz', 'test.foo', 'test.bar' ], ResourceLoaderModule::TYPE_STYLES ],
 
-                               '<link rel="stylesheet" href="http://127.0.0.1:8080/w/load.php?debug=false&amp;lang=en&amp;modules=test.bar%2Cbaz%2Cfoo&amp;only=styles&amp;skin=fallback"/>'
+                               '<link rel="stylesheet" href="http://127.0.0.1:8080/w/load.php?lang=en&amp;modules=test.bar%2Cbaz%2Cfoo&amp;only=styles&amp;skin=fallback"/>'
                        ],
                        // Private embed (only=scripts)
                        [
@@ -2606,14 +2606,14 @@ class OutputPageTest extends MediaWikiTestCase {
                        // noscript group
                        [
                                [ 'test.noscript', ResourceLoaderModule::TYPE_STYLES ],
-                               '<noscript><link rel="stylesheet" href="http://127.0.0.1:8080/w/load.php?debug=false&amp;lang=en&amp;modules=test.noscript&amp;only=styles&amp;skin=fallback"/></noscript>'
+                               '<noscript><link rel="stylesheet" href="http://127.0.0.1:8080/w/load.php?lang=en&amp;modules=test.noscript&amp;only=styles&amp;skin=fallback"/></noscript>'
                        ],
                        // Load two modules in separate groups
                        [
                                [ [ 'test.group.foo', 'test.group.bar' ], ResourceLoaderModule::TYPE_COMBINED ],
                                "<script nonce=\"secret\">(window.RLQ=window.RLQ||[]).push(function(){"
-                                       . 'mw.loader.load("http://127.0.0.1:8080/w/load.php?debug=false\u0026lang=en\u0026modules=test.group.bar\u0026skin=fallback");'
-                                       . 'mw.loader.load("http://127.0.0.1:8080/w/load.php?debug=false\u0026lang=en\u0026modules=test.group.foo\u0026skin=fallback");'
+                                       . 'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.group.bar\u0026skin=fallback");'
+                                       . 'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.group.foo\u0026skin=fallback");'
                                        . "});</script>"
                        ],
                ];
@@ -2677,13 +2677,13 @@ class OutputPageTest extends MediaWikiTestCase {
                        'default logged-out' => [
                                'exemptStyleModules' => [ 'site' => [ 'site.styles' ] ],
                                '<meta name="ResourceLoaderDynamicStyles" content=""/>' . "\n" .
-                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=fallback"/>',
+                               '<link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=fallback"/>',
                        ],
                        'default logged-in' => [
                                'exemptStyleModules' => [ 'site' => [ 'site.styles' ], 'user' => [ 'user.styles' ] ],
                                '<meta name="ResourceLoaderDynamicStyles" content=""/>' . "\n" .
-                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=fallback"/>' . "\n" .
-                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=user.styles&amp;only=styles&amp;skin=fallback&amp;version=1ai9g6t"/>',
+                               '<link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=fallback"/>' . "\n" .
+                               '<link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=user.styles&amp;only=styles&amp;skin=fallback&amp;version=1ai9g6t"/>',
                        ],
                        'custom modules' => [
                                'exemptStyleModules' => [
@@ -2691,10 +2691,10 @@ class OutputPageTest extends MediaWikiTestCase {
                                        'user' => [ 'user.styles', 'example.user' ],
                                ],
                                '<meta name="ResourceLoaderDynamicStyles" content=""/>' . "\n" .
-                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=example.site.a%2Cb&amp;only=styles&amp;skin=fallback"/>' . "\n" .
-                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=fallback"/>' . "\n" .
-                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=example.user&amp;only=styles&amp;skin=fallback&amp;version=0a56zyi"/>' . "\n" .
-                               '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=user.styles&amp;only=styles&amp;skin=fallback&amp;version=1ai9g6t"/>',
+                               '<link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=example.site.a%2Cb&amp;only=styles&amp;skin=fallback"/>' . "\n" .
+                               '<link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=fallback"/>' . "\n" .
+                               '<link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=example.user&amp;only=styles&amp;skin=fallback&amp;version=0a56zyi"/>' . "\n" .
+                               '<link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=user.styles&amp;only=styles&amp;skin=fallback&amp;version=1ai9g6t"/>',
                        ],
                ];
                // phpcs:enable
index 87c1d1e..017d745 100644 (file)
@@ -1841,14 +1841,14 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase {
 
        /**
         * @dataProvider statsKeyProvider
-        * @covers WANObjectCache::determineKeyClass
+        * @covers WANObjectCache::determineKeyClassForStats
         */
        public function testStatsKeyClass( $key, $class ) {
                $wanCache = TestingAccessWrapper::newFromObject( new WANObjectCache( [
                        'cache' => new HashBagOStuff
                ] ) );
 
-               $this->assertEquals( $class, $wanCache->determineKeyClass( $key ) );
+               $this->assertEquals( $class, $wanCache->determineKeyClassForStats( $key ) );
        }
 }
 
index 8fdf5dd..50b9421 100644 (file)
@@ -21,7 +21,6 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase {
                        'ResourceModuleSkinStyles' => [],
                        'ResourceModules' => [],
                        'EnableJavaScriptTest' => false,
-                       'ResourceLoaderDebug' => false,
                        'LoadScript' => '/w/load.php',
                ] );
                return new ResourceLoaderContext(
@@ -208,9 +207,9 @@ Deprecation message.' ]
                        . 'mw.loader.implement("test.private@{blankVer}",null,{"css":[]});'
                        . 'RLPAGEMODULES=["test"];mw.loader.load(RLPAGEMODULES);'
                        . '});</script>' . "\n"
-                       . '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.styles.deprecated%2Cpure&amp;only=styles&amp;skin=fallback"/>' . "\n"
+                       . '<link rel="stylesheet" href="/w/load.php?lang=nl&amp;modules=test.styles.deprecated%2Cpure&amp;only=styles&amp;skin=fallback"/>' . "\n"
                        . '<style>.private{}</style>' . "\n"
-                       . '<script async="" src="/w/load.php?debug=false&amp;lang=nl&amp;modules=startup&amp;only=scripts&amp;skin=fallback"></script>';
+                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts&amp;skin=fallback"></script>';
                // phpcs:enable
                $expected = self::expandVariables( $expected );
 
@@ -230,7 +229,7 @@ Deprecation message.' ]
 
                // phpcs:disable Generic.Files.LineLength
                $expected = '<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' . "\n"
-                       . '<script async="" src="/w/load.php?debug=false&amp;lang=nl&amp;modules=startup&amp;only=scripts&amp;skin=fallback&amp;target=example"></script>';
+                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts&amp;skin=fallback&amp;target=example"></script>';
                // phpcs:enable
 
                $this->assertEquals( $expected, $client->getHeadHtml() );
@@ -249,7 +248,7 @@ Deprecation message.' ]
 
                // phpcs:disable Generic.Files.LineLength
                $expected = '<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' . "\n"
-                       . '<script async="" src="/w/load.php?debug=false&amp;lang=nl&amp;modules=startup&amp;only=scripts&amp;safemode=1&amp;skin=fallback"></script>';
+                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts&amp;safemode=1&amp;skin=fallback"></script>';
                // phpcs:enable
 
                $this->assertEquals( $expected, $client->getHeadHtml() );
@@ -268,7 +267,7 @@ Deprecation message.' ]
 
                // phpcs:disable Generic.Files.LineLength
                $expected = '<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' . "\n"
-                       . '<script async="" src="/w/load.php?debug=false&amp;lang=nl&amp;modules=startup&amp;only=scripts&amp;skin=fallback"></script>';
+                       . '<script async="" src="/w/load.php?lang=nl&amp;modules=startup&amp;only=scripts&amp;skin=fallback"></script>';
                // phpcs:enable
 
                $this->assertEquals( $expected, $client->getHeadHtml() );
@@ -307,18 +306,21 @@ Deprecation message.' ]
                                'context' => [],
                                'modules' => [ 'test.unknown' ],
                                'only' => ResourceLoaderModule::TYPE_STYLES,
+                               'extra' => [],
                                'output' => '',
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test.styles.private' ],
                                'only' => ResourceLoaderModule::TYPE_STYLES,
+                               'extra' => [],
                                'output' => '<style>.private{}</style>',
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test.private' ],
                                'only' => ResourceLoaderModule::TYPE_COMBINED,
+                               'extra' => [],
                                'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.private@{blankVer}",null,{"css":[]});});</script>',
                        ],
                        [
@@ -326,85 +328,98 @@ Deprecation message.' ]
                                // Eg. startup module
                                'modules' => [ 'test.scripts.raw' ],
                                'only' => ResourceLoaderModule::TYPE_SCRIPTS,
-                               'output' => '<script async="" src="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.scripts.raw&amp;only=scripts&amp;skin=fallback"></script>',
+                               'extra' => [],
+                               'output' => '<script async="" src="/w/load.php?lang=nl&amp;modules=test.scripts.raw&amp;only=scripts&amp;skin=fallback"></script>',
                        ],
                        [
-                               'context' => [ 'sync' => true ],
+                               'context' => [],
                                'modules' => [ 'test.scripts.raw' ],
                                'only' => ResourceLoaderModule::TYPE_SCRIPTS,
-                               'output' => '<script src="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.scripts.raw&amp;only=scripts&amp;skin=fallback&amp;sync=1"></script>',
+                               'extra' => [ 'sync' => '1' ],
+                               'output' => '<script src="/w/load.php?lang=nl&amp;modules=test.scripts.raw&amp;only=scripts&amp;skin=fallback&amp;sync=1"></script>',
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test.scripts.user' ],
                                'only' => ResourceLoaderModule::TYPE_SCRIPTS,
-                               'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.scripts.user\u0026only=scripts\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
+                               'extra' => [],
+                               'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test.scripts.user\u0026only=scripts\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test.user' ],
                                'only' => ResourceLoaderModule::TYPE_COMBINED,
-                               'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.user\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
+                               'extra' => [],
+                               'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test.user\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
                        ],
                        [
-                               'context' => [ 'debug' => true ],
+                               'context' => [ 'debug' => 'true' ],
                                'modules' => [ 'test.styles.pure', 'test.styles.mixed' ],
                                'only' => ResourceLoaderModule::TYPE_STYLES,
+                               'extra' => [],
                                'output' => '<link rel="stylesheet" href="/w/load.php?debug=true&amp;lang=nl&amp;modules=test.styles.mixed&amp;only=styles&amp;skin=fallback"/>' . "\n"
                                        . '<link rel="stylesheet" href="/w/load.php?debug=true&amp;lang=nl&amp;modules=test.styles.pure&amp;only=styles&amp;skin=fallback"/>',
                        ],
                        [
-                               'context' => [ 'debug' => false ],
+                               'context' => [ 'debug' => 'false' ],
                                'modules' => [ 'test.styles.pure', 'test.styles.mixed' ],
                                'only' => ResourceLoaderModule::TYPE_STYLES,
-                               'output' => '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.styles.mixed%2Cpure&amp;only=styles&amp;skin=fallback"/>',
+                               'extra' => [],
+                               'output' => '<link rel="stylesheet" href="/w/load.php?lang=nl&amp;modules=test.styles.mixed%2Cpure&amp;only=styles&amp;skin=fallback"/>',
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test.styles.noscript' ],
                                'only' => ResourceLoaderModule::TYPE_STYLES,
-                               'output' => '<noscript><link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.styles.noscript&amp;only=styles&amp;skin=fallback"/></noscript>',
+                               'extra' => [],
+                               'output' => '<noscript><link rel="stylesheet" href="/w/load.php?lang=nl&amp;modules=test.styles.noscript&amp;only=styles&amp;skin=fallback"/></noscript>',
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test.shouldembed' ],
                                'only' => ResourceLoaderModule::TYPE_COMBINED,
+                               'extra' => [],
                                'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.shouldembed@09p30q0",null,{"css":[]});});</script>',
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test.styles.shouldembed' ],
                                'only' => ResourceLoaderModule::TYPE_STYLES,
+                               'extra' => [],
                                'output' => '<style>.shouldembed{}</style>',
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test.scripts.shouldembed' ],
                                'only' => ResourceLoaderModule::TYPE_SCRIPTS,
+                               'extra' => [],
                                'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.state({"test.scripts.shouldembed":"ready"});});</script>',
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test', 'test.shouldembed' ],
                                'only' => ResourceLoaderModule::TYPE_COMBINED,
-                               'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test\u0026skin=fallback");mw.loader.implement("test.shouldembed@09p30q0",null,{"css":[]});});</script>',
+                               'extra' => [],
+                               'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test\u0026skin=fallback");mw.loader.implement("test.shouldembed@09p30q0",null,{"css":[]});});</script>',
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test.styles.pure', 'test.styles.shouldembed' ],
                                'only' => ResourceLoaderModule::TYPE_STYLES,
+                               'extra' => [],
                                'output' =>
-                                       '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.styles.pure&amp;only=styles&amp;skin=fallback"/>' . "\n"
+                                       '<link rel="stylesheet" href="/w/load.php?lang=nl&amp;modules=test.styles.pure&amp;only=styles&amp;skin=fallback"/>' . "\n"
                                        . '<style>.shouldembed{}</style>'
                        ],
                        [
                                'context' => [],
                                'modules' => [ 'test.ordering.a', 'test.ordering.e', 'test.ordering.b', 'test.ordering.d', 'test.ordering.c' ],
                                'only' => ResourceLoaderModule::TYPE_STYLES,
+                               'extra' => [],
                                'output' =>
-                                       '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.ordering.a%2Cb&amp;only=styles&amp;skin=fallback"/>' . "\n"
+                                       '<link rel="stylesheet" href="/w/load.php?lang=nl&amp;modules=test.ordering.a%2Cb&amp;only=styles&amp;skin=fallback"/>' . "\n"
                                        . '<style>.orderingC{}.orderingD{}</style>' . "\n"
-                                       . '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.ordering.e&amp;only=styles&amp;skin=fallback"/>'
+                                       . '<link rel="stylesheet" href="/w/load.php?lang=nl&amp;modules=test.ordering.e&amp;only=styles&amp;skin=fallback"/>'
                        ],
                ];
                // phpcs:enable
@@ -422,8 +437,14 @@ Deprecation message.' ]
         * @covers ResourceLoader::makeLoaderQuery
         * @covers ResourceLoader::makeInlineScript
         */
-       public function testMakeLoad( array $extraQuery, array $modules, $type, $expected ) {
-               $context = self::makeContext( $extraQuery );
+       public function testMakeLoad(
+               array $contextQuery,
+               array $modules,
+               $type,
+               array $extraQuery,
+               $expected
+       ) {
+               $context = self::makeContext( $contextQuery );
                $context->getResourceLoader()->register( self::makeSampleModules() );
                $actual = ResourceLoaderClientHtml::makeLoad( $context, $modules, $type, $extraQuery, false );
                $expected = self::expandVariables( $expected );
index f6bf7f1..5941c6e 100644 (file)
@@ -767,11 +767,11 @@ END
                }, $scripts );
                $rl->register( $modules );
 
-               $this->setMwGlobals( 'wgResourceLoaderDebug', $debug );
                $context = $this->getResourceLoaderContext(
                        [
                                'modules' => implode( '|', array_keys( $modules ) ),
                                'only' => 'scripts',
+                               'debug' => $debug ? 'true' : 'false',
                        ],
                        $rl
                );