Aude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/119502
Change subject: Add / allow injecting experimental mode param in
LanguageFallbackChainFactory
......................................................................
Add / allow injecting experimental mode param in LanguageFallbackChainFactory
also adds simple test. more/better tests could be done as follow-up.
Change-Id: Id20d4512254249aaccae54f0de6c76ab5139e708
---
M client/includes/WikibaseClient.php
M lib/includes/LanguageFallbackChainFactory.php
M lib/tests/phpunit/LanguageFallbackChainFactoryTest.php
M lib/tests/phpunit/LanguageFallbackChainTest.php
M repo/includes/WikibaseRepo.php
5 files changed, 45 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/02/119502/1
diff --git a/client/includes/WikibaseClient.php
b/client/includes/WikibaseClient.php
index 41ce354..df799ef 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -264,7 +264,9 @@
*/
public function getLanguageFallbackChainFactory() {
if ( $this->languageFallbackChainFactory === null ) {
- $this->languageFallbackChainFactory = new
LanguageFallbackChainFactory();
+ $this->languageFallbackChainFactory = new
LanguageFallbackChainFactory(
+ defined( 'WB_EXPERIMENTAL_FEATURES' ) &&
WB_EXPERIMENTAL_FEATURES
+ );
}
return $this->languageFallbackChainFactory;
diff --git a/lib/includes/LanguageFallbackChainFactory.php
b/lib/includes/LanguageFallbackChainFactory.php
index fdc7b43..8c971c9 100644
--- a/lib/includes/LanguageFallbackChainFactory.php
+++ b/lib/includes/LanguageFallbackChainFactory.php
@@ -54,12 +54,19 @@
public $anonymousPageViewCached;
/**
- * Constructor.
- *
+ * @var bool
+ */
+ private $isExperimentalMode;
+
+ /**
* @param $anonymousPageViewCached bool
* Whether full page outputs are cached for anons, so some
fine-grained fallbacks shouldn't be used for them.
*/
- public function __construct( $anonymousPageViewCached = false ) {
+ public function __construct( $isExperimentalMode = null,
$anonymousPageViewCached = false ) {
+ // @fixme fix instantiation of factory in various lib classes
+ $this->isExperimentalMode = $isExperimentalMode ?
$isExperimentalMode :
+ defined( 'WB_EXPERIMENTAL_FEATURES' ) &&
WB_EXPERIMENTAL_FEATURES;
+
$this->anonymousPageViewCached = $anonymousPageViewCached;
}
@@ -340,8 +347,7 @@
* @return LanguageFallbackChain
*/
public function newFromContextForPageView( IContextSource $context ) {
- if ( defined( 'WB_EXPERIMENTAL_FEATURES' ) &&
WB_EXPERIMENTAL_FEATURES ) {
-
+ if ( $this->isExperimentalMode ) {
// The generated chain should yield a cacheable result
if ( $this->anonymousPageViewCached &&
$context->getUser()->isAnon() ) {
// Anonymous users share the same Squid cache,
which is splitted by URL.
@@ -353,7 +359,7 @@
} else {
return $this->newFromLanguage(
$context->getLanguage(),
- LanguageFallbackChainFactory::FALLBACK_SELF
+ self::FALLBACK_SELF
);
}
}
diff --git a/lib/tests/phpunit/LanguageFallbackChainFactoryTest.php
b/lib/tests/phpunit/LanguageFallbackChainFactoryTest.php
index 949dc00..8f75206 100644
--- a/lib/tests/phpunit/LanguageFallbackChainFactoryTest.php
+++ b/lib/tests/phpunit/LanguageFallbackChainFactoryTest.php
@@ -2,7 +2,10 @@
namespace Wikibase\Test;
+use Language;
use MWException;
+use RequestContext;
+use User;
use Wikibase\LanguageFallbackChain;
use Wikibase\LanguageFallbackChainFactory;
@@ -376,4 +379,28 @@
),
);
}
+
+ /**
+ * @dataProvider newFromContextForPageViewProvider
+ */
+ public function testNewFromContextForPageView( $experimental,
$anonymousPageViewCached, $msg ) {
+ $context = new RequestContext();
+ $context->setLanguage( Language::factory( 'es' ) );
+ $user = User::newFromId( 0 );
+ $context->setUser( $user );
+
+ $factory = new LanguageFallbackChainFactory( false, true );
+ $fallbackChain = $factory->newFromContextForPageView( $context
);
+
+ $this->assertInstanceOf( 'Wikibase\LanguageFallbackChain',
$fallbackChain, $msg );
+ }
+
+ public function newFromContextForPageViewProvider() {
+ return array(
+ array( false, true, 'non-experimental, anon cached page
view' ),
+ array( false, false, 'non-experimental, not anon cached
page view' ),
+ array( true, true, 'experimental, anon cached page
view' ),
+ array( true, false, 'experimental, not anon cached page
view' )
+ );
+ }
}
diff --git a/lib/tests/phpunit/LanguageFallbackChainTest.php
b/lib/tests/phpunit/LanguageFallbackChainTest.php
index 2bf1bb7..83cecc9 100644
--- a/lib/tests/phpunit/LanguageFallbackChainTest.php
+++ b/lib/tests/phpunit/LanguageFallbackChainTest.php
@@ -163,4 +163,5 @@
array( 'ar',
LanguageFallbackChainFactory::FALLBACK_SELF, array(), null ),
);
}
+
}
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 4ca0e96..77865d9 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -318,9 +318,11 @@
public function getLanguageFallbackChainFactory() {
if ( $this->languageFallbackChainFactory === null ) {
global $wgUseSquid;
+
// The argument is about whether full page output
(OutputPage, specifically JS vars in it currently)
// is cached for anons, where the only caching
mechanism in use now is Squid.
$this->languageFallbackChainFactory = new
LanguageFallbackChainFactory(
+ defined( 'WB_EXPERIMENTAL_FEATURES' ) &&
WB_EXPERIMENTAL_FEATURES,
/* $anonymousPageViewCached = */ $wgUseSquid
);
}
--
To view, visit https://gerrit.wikimedia.org/r/119502
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id20d4512254249aaccae54f0de6c76ab5139e708
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits