Skip to content

Commit 1b1cea8

Browse files
codderslucaswerkmeister
authored andcommitted
Enable the wbui2025 interface for beta feature users
Determine “is this a wbui2025 mobile view?” once, when the Wbui2025FeatureFlag is called in the lazy-loaded parser options. In EntityHandler, we read that option (which will then be evaluated based on $lazyLoad), and pass it through to all the other places that don’t have access to the parser options directly. In ItemView and PropertyView, we add a new “placeholder” to the ViewContent, which will later be copied to the parser output’s extension data; in data updaters, we can then add the ResourceLoader modules based on that extension data, without needing another copy of the flag passed in. Because the "placeholder" variables need to be available in time for the content view creation, we create a new `getParserOuputOptions` function in the EntityView interface that the EntityParserOutputGenerator can call to transfer the options to the extension data before the content is rendered. `$wbMobile` is currently a bool|string mix. In a follow-up we can consider changing this to be an enum. Co-Authored-By: Lucas Werkmeister <[email protected]> Depends-On: Ifab976f2656b1e76fa2ea2d4c8621ce24c654617 Bug: T407737 Change-Id: I5ebf9743642fafe14b08e2dddbc1d29c90e5576c
1 parent 78b8941 commit 1b1cea8

31 files changed

+431
-96
lines changed

repo/WikibaseRepo.ServiceWiring.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
use Wikibase\View\LanguageDirectionalityLookup;
253253
use Wikibase\View\Template\TemplateFactory;
254254
use Wikibase\View\ViewFactory;
255+
use Wikibase\View\Wbui2025FeatureFlag;
255256
use Wikimedia\ObjectCache\HashBagOStuff;
256257
use Wikimedia\ObjectFactory\ObjectFactory;
257258

@@ -901,7 +902,9 @@ function ( EntityNamespaceLookup $nsLookup, DatabaseEntitySource $source ): Enti
901902
WikibaseRepo::getEntityViewFactory( $services ),
902903
WikibaseRepo::getEntityMetaTagsCreatorFactory( $services ),
903904
WikibaseRepo::getEntityTitleLookup( $services ),
905+
$services->getLanguageFactory(),
904906
WikibaseRepo::getLanguageFallbackChainFactory( $services ),
907+
$services->getLanguageNameUtils(),
905908
WikibaseRepo::getEntityDataFormatProvider( $services ),
906909
// FIXME: Should this be done for all usages of this lookup, or is the impact of
907910
// CachingPropertyInfoLookup enough?
@@ -2164,9 +2167,6 @@ function ( $types, $localTypeName ) use ( $subEntityTypes ) {
21642167
$services->getObjectCacheFactory()->getLocalClusterInstance()
21652168
);
21662169

2167-
$vueStatementView = $settings->getSetting( 'tmpMobileEditingUI' ) &&
2168-
WikibaseRepo::getMobileSite( $services );
2169-
21702170
return new ViewFactory(
21712171
WikibaseRepo::getEntityIdHtmlLinkFormatterFactory( $services ),
21722172
WikibaseRepo::getEntityIdLabelFormatterFactory( $services ),
@@ -2190,7 +2190,14 @@ function ( $types, $localTypeName ) use ( $subEntityTypes ) {
21902190
new RepoSpecialPageLinker(),
21912191
$services->getLanguageFactory(),
21922192
WikibaseRepo::getEntityIdParser( $services ),
2193-
$vueStatementView
2193+
WikibaseRepo::getWbui2025FeatureFlag( $services ),
2194+
);
2195+
},
2196+
2197+
'WikibaseRepo.Wbui2025FeatureFlag' => function ( MediaWikiServices $services ): Wbui2025FeatureFlag {
2198+
return new Wbui2025FeatureFlag(
2199+
$services->getUserOptionsLookup(),
2200+
WikibaseRepo::getSettings( $services ),
21942201
);
21952202
},
21962203

repo/WikibaseRepo.entitytypes.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
Def::VIEW_FACTORY_CALLBACK => function(
9393
Language $language,
9494
TermLanguageFallbackChain $fallbackChain,
95-
EntityDocument $entity
95+
EntityDocument $entity,
96+
array $viewOptions,
9697
) {
9798
$viewFactory = WikibaseRepo::getViewFactory();
9899
return $viewFactory->newItemView(
@@ -104,7 +105,8 @@
104105
$language,
105106
$fallbackChain,
106107
TermboxFlag::getInstance()->shouldRenderTermbox()
107-
)
108+
),
109+
$viewOptions,
108110
);
109111
},
110112
Def::META_TAGS_CREATOR_CALLBACK => function ( $userLanguage ) {
@@ -306,7 +308,8 @@
306308
Def::VIEW_FACTORY_CALLBACK => function(
307309
Language $language,
308310
TermLanguageFallbackChain $fallbackChain,
309-
EntityDocument $entity
311+
EntityDocument $entity,
312+
array $viewOptions,
310313
) {
311314
$viewFactory = WikibaseRepo::getViewFactory();
312315
return $viewFactory->newPropertyView(
@@ -318,7 +321,8 @@
318321
$language,
319322
$fallbackChain,
320323
TermboxFlag::getInstance()->shouldRenderTermbox()
321-
)
324+
),
325+
$viewOptions
322326
);
323327
},
324328
Def::META_TAGS_CREATOR_CALLBACK => function ( Language $userLanguage ) {

repo/includes/Content/EntityHandler.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,7 @@ protected function getParserOutputFromEntityView(
853853
$generateHtml = true
854854
) {
855855
$outputGenerator = WikibaseRepo::getEntityParserOutputGeneratorFactory()
856-
->getEntityParserOutputGenerator(
857-
$this->getValidUserLanguage( $options->getUserLangObj() )
858-
);
856+
->getEntityParserOutputGeneratorForParserOptions( $options );
859857

860858
$entityRevision = $this->getEntityRevision( $content, $revisionId );
861859

@@ -872,15 +870,6 @@ protected function getParserOutputFromEntityView(
872870
return $parserOutput;
873871
}
874872

875-
private function getValidUserLanguage( Language $language ): Language {
876-
$services = MediaWikiServices::getInstance();
877-
if ( !$services->getLanguageNameUtils()->isValidBuiltInCode( $language->getCode() ) ) {
878-
return $services->getLanguageFactory()->getLanguage( 'und' ); // T204791
879-
}
880-
881-
return $language;
882-
}
883-
884873
/**
885874
* @param EntityContent $content
886875
* @param int|null $revisionId

repo/includes/Hooks/GetBetaFeaturePreferencesHookHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use MediaWiki\User\User;
88
use Wikibase\Lib\SettingsArray;
9+
use Wikibase\View\Wbui2025FeatureFlag;
910

1011
/**
1112
* Hook handler that registers beta features with the BetaFeatures extension.
@@ -31,7 +32,7 @@ public function onGetBetaFeaturePreferences( User $user, array &$betaFeatures ):
3132
if ( !$this->enableMobileEditingUIBetaFeature ) {
3233
return;
3334
}
34-
$betaFeatures['wikibase-mobile-editing-ui'] = [
35+
$betaFeatures[Wbui2025FeatureFlag::OPTION_NAME] = [
3536
'label-message' => 'wikibase-mobile-editing-ui-beta-feature-message',
3637
'desc-message' => 'wikibase-mobile-editing-ui-beta-feature-description',
3738
// These links are required, but given we don't have community pages set up yet, link to Phab.

repo/includes/ParserOutput/DispatchingEntityViewFactory.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ public function __construct( array $entityViewFactoryCallbacks ) {
3737
* @param Language $language
3838
* @param TermLanguageFallbackChain $termFallbackChain
3939
* @param EntityDocument $entity
40+
* @param array $factoryOptions
4041
*
4142
* @throws OutOfBoundsException
4243
* @return EntityDocumentView
4344
*/
4445
public function newEntityView(
4546
Language $language,
4647
TermLanguageFallbackChain $termFallbackChain,
47-
EntityDocument $entity
48+
EntityDocument $entity,
49+
array $factoryOptions = [],
4850
) {
4951
$entityType = $entity->getType();
5052
if ( !isset( $this->entityViewFactoryCallbacks[$entityType] ) ) {
@@ -54,7 +56,8 @@ public function newEntityView(
5456
$entityView = $this->entityViewFactoryCallbacks[$entityType](
5557
$language,
5658
$termFallbackChain,
57-
$entity
59+
$entity,
60+
$factoryOptions,
5861
);
5962

6063
Assert::postcondition(

repo/includes/ParserOutput/EntityParserOutputGeneratorFactory.php

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use MediaWiki\Extension\Math\MathDataUpdater;
99
use MediaWiki\FileRepo\RepoGroup;
1010
use MediaWiki\Language\Language;
11+
use MediaWiki\Language\LanguageFactory;
12+
use MediaWiki\Language\LanguageNameUtils;
13+
use MediaWiki\Parser\ParserOptions;
1114
use MediaWiki\Registration\ExtensionRegistry;
1215
use PageImages\PageImages;
1316
use Wikibase\DataModel\Services\Entity\PropertyDataTypeMatcher;
@@ -34,7 +37,9 @@ class EntityParserOutputGeneratorFactory {
3437
private DispatchingEntityViewFactory $entityViewFactory;
3538
private DispatchingEntityMetaTagsCreatorFactory $entityMetaTagsCreatorFactory;
3639
private EntityTitleLookup $entityTitleLookup;
40+
private LanguageFactory $languageFactory;
3741
private LanguageFallbackChainFactory $languageFallbackChainFactory;
42+
private LanguageNameUtils $languageNameUtils;
3843
private EntityDataFormatProvider $entityDataFormatProvider;
3944
private PropertyDataTypeLookup $propertyDataTypeLookup;
4045

@@ -66,7 +71,9 @@ class EntityParserOutputGeneratorFactory {
6671
* @param DispatchingEntityViewFactory $entityViewFactory
6772
* @param DispatchingEntityMetaTagsCreatorFactory $entityMetaTagsCreatorFactory
6873
* @param EntityTitleLookup $entityTitleLookup
74+
* @param LanguageFactory $languageFactory
6975
* @param LanguageFallbackChainFactory $languageFallbackChainFactory
76+
* @param LanguageNameUtils $languageNameUtils
7077
* @param EntityDataFormatProvider $entityDataFormatProvider
7178
* @param PropertyDataTypeLookup $propertyDataTypeLookup
7279
* @param EntityReferenceExtractorDelegator $entityReferenceExtractorDelegator
@@ -85,7 +92,9 @@ public function __construct(
8592
DispatchingEntityViewFactory $entityViewFactory,
8693
DispatchingEntityMetaTagsCreatorFactory $entityMetaTagsCreatorFactory,
8794
EntityTitleLookup $entityTitleLookup,
95+
LanguageFactory $languageFactory,
8896
LanguageFallbackChainFactory $languageFallbackChainFactory,
97+
LanguageNameUtils $languageNameUtils,
8998
EntityDataFormatProvider $entityDataFormatProvider,
9099
PropertyDataTypeLookup $propertyDataTypeLookup,
91100
EntityReferenceExtractorDelegator $entityReferenceExtractorDelegator,
@@ -102,7 +111,9 @@ public function __construct(
102111
$this->entityViewFactory = $entityViewFactory;
103112
$this->entityMetaTagsCreatorFactory = $entityMetaTagsCreatorFactory;
104113
$this->entityTitleLookup = $entityTitleLookup;
114+
$this->languageFactory = $languageFactory;
105115
$this->languageFallbackChainFactory = $languageFallbackChainFactory;
116+
$this->languageNameUtils = $languageNameUtils;
106117
$this->entityDataFormatProvider = $entityDataFormatProvider;
107118
$this->propertyDataTypeLookup = $propertyDataTypeLookup;
108119
$this->entityReferenceExtractorDelegator = $entityReferenceExtractorDelegator;
@@ -117,7 +128,41 @@ public function __construct(
117128
$this->isMobileView = $isMobileView;
118129
}
119130

120-
public function getEntityParserOutputGenerator( Language $userLanguage ): EntityParserOutputGenerator {
131+
private function getValidUserLanguage( Language $language ): Language {
132+
if ( !$this->languageNameUtils->isValidBuiltInCode( $language->getCode() ) ) {
133+
return $this->languageFactory->getLanguage( 'und' ); // T204791
134+
}
135+
return $language;
136+
}
137+
138+
/**
139+
* Introduce this function to make it possible to transition the interface
140+
* for `getEntityParserOutputGenerator` from taking a Language to taking a ParserOptions
141+
* object.
142+
*
143+
* We introduce this new function, update callers to call the new function with the
144+
* new interface, then in future commits we will remove the old function.
145+
*
146+
* @param ParserOptions $options
147+
* @return EntityParserOutputGenerator
148+
*/
149+
public function getEntityParserOutputGeneratorForParserOptions( ParserOptions $options ): EntityParserOutputGenerator {
150+
$userLanguage = $this->getValidUserLanguage( $options->getUserLangObj() );
151+
$wbMobile = $options->getOption( 'wbMobile' );
152+
153+
return $this->getEntityParserOutputGenerator( $userLanguage, $wbMobile );
154+
}
155+
156+
/**
157+
* @deprecated Remove this function in favour of the function version that takes
158+
* a ParserOptions object. When all callers of this function have migrated, the function
159+
* can be removed.
160+
*
161+
* @param Language $userLanguage
162+
* @param bool|string $wbMobile
163+
* @return EntityParserOutputGenerator
164+
*/
165+
public function getEntityParserOutputGenerator( Language $userLanguage, $wbMobile = false ): EntityParserOutputGenerator {
121166
$pog = new FullEntityParserOutputGenerator(
122167
$this->entityViewFactory,
123168
$this->entityMetaTagsCreatorFactory,
@@ -126,6 +171,7 @@ public function getEntityParserOutputGenerator( Language $userLanguage ): Entity
126171
$this->entityDataFormatProvider,
127172
$this->getDataUpdaters(),
128173
$userLanguage,
174+
$wbMobile,
129175
$this->isMobileView
130176
);
131177

@@ -186,17 +232,12 @@ private function getDataUpdaters(): array {
186232
$this->newKartographerDataUpdater( $this->kartographerEmbeddingHandler ) );
187233
}
188234

189-
$tmpMobileEditingUI = WikibaseRepo::getSettings()->getSetting( 'tmpMobileEditingUI' );
190235
$entityUpdaters = [
191236
new ItemParserOutputUpdater(
192237
$statementUpdater,
193-
$this->isMobileView,
194-
$tmpMobileEditingUI
195238
),
196239
new PropertyParserOutputUpdater(
197240
$statementUpdater,
198-
$this->isMobileView,
199-
$tmpMobileEditingUI
200241
),
201242
new ReferencedEntitiesDataUpdater(
202243
$this->entityReferenceExtractorDelegator,

repo/includes/ParserOutput/FullEntityParserOutputGenerator.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use Wikibase\Lib\Store\EntityRevision;
1313
use Wikibase\Lib\TermLanguageFallbackChain;
1414
use Wikibase\Repo\LinkedData\EntityDataFormatProvider;
15+
use Wikibase\View\EntityDocumentView;
1516
use Wikibase\View\ViewPlaceHolderEmitter;
17+
use Wikibase\View\Wbui2025FeatureFlag;
1618

1719
/**
1820
* Creates the parser output for an entity.
@@ -41,6 +43,8 @@ class FullEntityParserOutputGenerator implements EntityParserOutputGenerator {
4143

4244
private Language $language;
4345

46+
private bool|string $wbMobile;
47+
4448
private bool $isMobileView;
4549

4650
/**
@@ -51,6 +55,8 @@ class FullEntityParserOutputGenerator implements EntityParserOutputGenerator {
5155
* @param EntityDataFormatProvider $entityDataFormatProvider
5256
* @param EntityParserOutputUpdater[] $dataUpdaters
5357
* @param Language $language
58+
* @param bool|string $wbMobile
59+
* @param bool $isMobileView
5460
*/
5561
public function __construct(
5662
DispatchingEntityViewFactory $entityViewFactory,
@@ -60,6 +66,7 @@ public function __construct(
6066
EntityDataFormatProvider $entityDataFormatProvider,
6167
array $dataUpdaters,
6268
Language $language,
69+
bool|string $wbMobile,
6370
bool $isMobileView
6471
) {
6572
$this->entityViewFactory = $entityViewFactory;
@@ -69,6 +76,7 @@ public function __construct(
6976
$this->entityDataFormatProvider = $entityDataFormatProvider;
7077
$this->dataUpdaters = $dataUpdaters;
7178
$this->language = $language;
79+
$this->wbMobile = $wbMobile;
7280
$this->isMobileView = $isMobileView;
7381
}
7482

@@ -86,6 +94,12 @@ public function getParserOutput(
8694
$parserOutput = new ParserOutput();
8795
$parserOutput->resetParseStartTime();
8896

97+
$entityView = $this->createEntityView( $entityRevision );
98+
$parserOutputOptions = $entityView->getParserOutputOptions();
99+
foreach ( $parserOutputOptions as $key => $value ) {
100+
$parserOutput->setExtensionData( $key, $value );
101+
}
102+
89103
$updaterCollection = new EntityParserOutputDataUpdaterCollection( $parserOutput, $this->dataUpdaters );
90104
$updaterCollection->updateParserOutput( $entity );
91105

@@ -99,7 +113,8 @@ public function getParserOutput(
99113
if ( $generateHtml ) {
100114
$this->addHtmlToParserOutput(
101115
$parserOutput,
102-
$entityRevision
116+
$entityRevision,
117+
$entityView,
103118
);
104119
} else {
105120
// If we don't have HTML, the ParserOutput in question
@@ -128,17 +143,23 @@ public function getParserOutput(
128143
return $parserOutput;
129144
}
130145

131-
private function addHtmlToParserOutput(
132-
ParserOutput $parserOutput,
133-
EntityRevision $entityRevision
134-
): void {
146+
private function createEntityView( EntityRevision $entityRevision ): EntityDocumentView {
135147
$entity = $entityRevision->getEntity();
136148

137-
$entityView = $this->entityViewFactory->newEntityView(
149+
return $this->entityViewFactory->newEntityView(
138150
$this->language,
139151
$this->termLanguageFallbackChain,
140-
$entity
152+
$entity,
153+
[ Wbui2025FeatureFlag::EXTENSION_DATA_KEY => $this->wbMobile ],
141154
);
155+
}
156+
157+
private function addHtmlToParserOutput(
158+
ParserOutput $parserOutput,
159+
EntityRevision $entityRevision,
160+
EntityDocumentView $entityView,
161+
): void {
162+
$entity = $entityRevision->getEntity();
142163

143164
// Set the display title to display the label together with the item's id
144165
$titleHtml = $entityView->getTitleHtml( $entity );

0 commit comments

Comments
 (0)