Skip to content

Commit 3c62fa0

Browse files
committed
Use constant instead of literal string for wbMobile parser option
We use the literal string `wbMobile` in many places in the Wikibase codebase to refer to the parser option for mobile (and now wbui2025) functionality. Replace the literal string with a constant. Bug: T407737 Change-Id: Ib3ec93c27e515c8f4a68822ef4f5cb206a6a6964
1 parent 7a04407 commit 3c62fa0

File tree

7 files changed

+19
-13
lines changed

7 files changed

+19
-13
lines changed

repo/includes/ParserOutput/EntityParserOutputGeneratorFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Wikibase\Repo\Hooks\WikibaseRepoOnParserOutputUpdaterConstructionHook;
2727
use Wikibase\Repo\LinkedData\EntityDataFormatProvider;
2828
use Wikibase\Repo\WikibaseRepo;
29+
use Wikibase\View\Wbui2025FeatureFlag;
2930
use Wikimedia\Stats\StatsFactory;
3031

3132
/**
@@ -146,7 +147,7 @@ public function getEntityParserOutputGeneratorForParserOptions( ParserOptions $o
146147
$this->entityDataFormatProvider,
147148
$this->getDataUpdaters(),
148149
$userLanguage,
149-
$options->getOption( 'wbMobile' ),
150+
$options->getOption( Wbui2025FeatureFlag::PARSER_OPTION_NAME ),
150151
$this->isMobileView
151152
);
152153

repo/includes/ParserOutput/FullEntityParserOutputGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private function addHtmlToParserOutput(
166166
$parserOutput->setTitleText( $titleHtml ?? '' );
167167

168168
// split parser cache by desktop/mobile/wbui2025 (T344362, T394291, T394291)
169-
$parserOutput->recordOption( 'wbMobile' );
169+
$parserOutput->recordOption( Wbui2025FeatureFlag::PARSER_OPTION_NAME );
170170
$viewContent = $entityView->getContent( $entity, $entityRevision->getRevisionId() );
171171
$parserOutput->setContentHolderText( $viewContent->getHtml() );
172172

@@ -187,7 +187,7 @@ private function addModules( ParserOutput $parserOutput ): void {
187187
'wikibase.alltargets',
188188
] );
189189
// split parser cache by desktop/mobile (T344362)
190-
$parserOutput->recordOption( 'wbMobile' );
190+
$parserOutput->recordOption( Wbui2025FeatureFlag::PARSER_OPTION_NAME );
191191
// T324991
192192
if ( !$this->isMobileView ) {
193193
$parserOutput->addModuleStyles( [

repo/includes/RepoHooks.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
use Wikibase\Repo\Store\Sql\SqlSubscriptionLookup;
7373
use Wikibase\View\ViewHooks;
7474
use Wikibase\View\VueNoScriptRendering;
75+
use Wikibase\View\Wbui2025FeatureFlag;
7576
use Wikimedia\Rdbms\IDBAccessObject;
7677

7778
/**
@@ -1145,9 +1146,9 @@ public function onParserOptionsRegister( &$defaults, &$inCacheKey, &$lazyLoad )
11451146
TermboxView::TERMBOX_VERSION . TermboxView::CACHE_VERSION :
11461147
PlaceholderEmittingEntityTermsView::TERMBOX_VERSION . PlaceholderEmittingEntityTermsView::CACHE_VERSION;
11471148
};
1148-
$defaults['wbMobile'] = null;
1149-
$inCacheKey['wbMobile'] = true;
1150-
$lazyLoad['wbMobile'] = function ( ParserOptions $parserOptions ) {
1149+
$defaults[Wbui2025FeatureFlag::PARSER_OPTION_NAME] = null;
1150+
$inCacheKey[Wbui2025FeatureFlag::PARSER_OPTION_NAME] = true;
1151+
$lazyLoad[Wbui2025FeatureFlag::PARSER_OPTION_NAME] = function ( ParserOptions $parserOptions ) {
11511152
return WikibaseRepo::getWbui2025FeatureFlag()->generateWbMobileFlagValue(
11521153
WikibaseRepo::getMobileSite(),
11531154
$parserOptions->getUserIdentity(),

repo/tests/phpunit/includes/Content/ItemHandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Wikibase\Repo\Content\ItemHandler;
2828
use Wikibase\Repo\Search\Fields\FieldDefinitions;
2929
use Wikibase\Repo\WikibaseRepo;
30+
use Wikibase\View\Wbui2025FeatureFlag;
3031

3132
/**
3233
* @covers \Wikibase\Repo\Content\ItemHandler
@@ -320,7 +321,7 @@ public function testGetParserOutput() {
320321
$title = Title::makeTitle( NS_MAIN, 'Foo' );
321322
$parserOutput = $contentRenderer->getParserOutput( $content, $title );
322323

323-
$expectedUsedOptions = [ 'userlang', 'wb', 'termboxVersion', 'wbMobile' ];
324+
$expectedUsedOptions = [ 'userlang', 'wb', 'termboxVersion', Wbui2025FeatureFlag::PARSER_OPTION_NAME ];
324325
$actualOptions = $parserOutput->getUsedOptions();
325326
$this->assertEqualsCanonicalizing(
326327
$expectedUsedOptions,

repo/tests/phpunit/includes/Content/PropertyHandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Wikibase\Repo\Content\PropertyContent;
1818
use Wikibase\Repo\Content\PropertyHandler;
1919
use Wikibase\Repo\WikibaseRepo;
20+
use Wikibase\View\Wbui2025FeatureFlag;
2021

2122
/**
2223
* @covers \Wikibase\Repo\Content\PropertyHandler
@@ -202,7 +203,7 @@ public function testGetParserOutput() {
202203
$title->setContentModel( CONTENT_MODEL_WIKITEXT );
203204
$parserOutput = $contentRenderer->getParserOutput( $content, $title );
204205

205-
$expectedUsedOptions = [ 'userlang', 'wb', 'termboxVersion', 'wbMobile' ];
206+
$expectedUsedOptions = [ 'userlang', 'wb', 'termboxVersion', Wbui2025FeatureFlag::PARSER_OPTION_NAME ];
206207
$actualOptions = $parserOutput->getUsedOptions();
207208
$this->assertEqualsCanonicalizing(
208209
$expectedUsedOptions,

repo/tests/phpunit/includes/RepoHooksTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Wikibase\Repo\RepoHooks;
3232
use Wikibase\Repo\Store\RateLimitingIdGenerator;
3333
use Wikibase\Repo\WikibaseRepo;
34+
use Wikibase\View\Wbui2025FeatureFlag;
3435
use WikiImporter;
3536

3637
/**
@@ -395,26 +396,26 @@ public function testOnParserOptionsRegister(
395396
$this->assertSame( [
396397
'wb' => null,
397398
'termboxVersion' => null,
398-
'wbMobile' => null,
399+
Wbui2025FeatureFlag::PARSER_OPTION_NAME => null,
399400
], $defaults );
400401
$this->assertSame( [
401402
'wb' => true,
402403
'termboxVersion' => true,
403-
'wbMobile' => true,
404+
Wbui2025FeatureFlag::PARSER_OPTION_NAME => true,
404405
], $inCacheKey );
405406
$this->assertSame( [
406407
'wb',
407408
'termboxVersion',
408-
'wbMobile',
409+
Wbui2025FeatureFlag::PARSER_OPTION_NAME,
409410
], array_keys( $lazyOptions ) );
410411
$parserOptions = $this->createConfiguredMock( ParserOptions::class, [
411412
'getUserIdentity' => $this->createMock( UserIdentity::class ),
412413
] );
413414
$this->assertIsCallable( $lazyOptions[ 'wb' ] );
414415
$this->assertSame( EntityHandler::PARSER_VERSION, $lazyOptions[ 'wb' ]() );
415416
$this->assertIsCallable( $lazyOptions[ 'termboxVersion' ] );
416-
$this->assertIsCallable( $lazyOptions[ 'wbMobile' ] );
417-
$this->assertSame( $expectedWbMobileValue, $lazyOptions[ 'wbMobile' ]( $parserOptions ) );
417+
$this->assertIsCallable( $lazyOptions[ Wbui2025FeatureFlag::PARSER_OPTION_NAME ] );
418+
$this->assertSame( $expectedWbMobileValue, $lazyOptions[ Wbui2025FeatureFlag::PARSER_OPTION_NAME ]( $parserOptions ) );
418419
}
419420

420421
public function testOnParserOptionsRegister_hook() {

view/src/Wbui2025FeatureFlag.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Wbui2025FeatureFlag {
1717
public const OPTION_NAME = 'wikibase-mobile-editing-ui';
1818
public const EXTENSION_DATA_KEY = 'wikibase-mobile';
1919
public const WBMOBILE_WBUI2025_FLAG = 'wbui2025';
20+
public const PARSER_OPTION_NAME = 'wbMobile';
2021

2122
private UserOptionsLookup $userOptionsLookup;
2223
private bool $wbui2025Enabled;

0 commit comments

Comments
 (0)