Page MenuHomePhabricator

Once we have ContentHandlerFactory, we can think about injecting the LanguageConverterFactory into ContentHandler.
Open, MediumPublic2 Estimated Story Points

Description

Once we have DI for ContentHandler we can inject LanguageConverterFactory through it and omit direct call.

/**
	 * Shorthand for getting a Language Converter for specific language
	 * @param Language $language Language of converter
	 * @return LanguageConverter
	 */
	private function getLanguageConverter( \Language $language ) {
		return MediaWikiServices::getInstance()->getLanguageConverterFactory()
			->getLanguageConverter( $language );
	}

@includes/content/ContentHandler.php

Event Timeline

I recall making this comment, but I don't recall the context... ContentHandler currently doesn't use LanguageConverter, as far as I can see. Once we have ContentHandlerFactory, we could start to inject all things into ContentHandler subclasses. That would certainly be good. But I don't quite understand what this task is calling for.

Updated description with more context.

ContentHandler currently doesn't use LanguageConverter, as far as I can see.

It does! I'm not sure what for but:

public function getPageViewLanguage( Title $title, Content $content = null ) {
		$pageLang = $this->getPageLanguage( $title, $content );

		if ( $title->getNamespace() !== NS_MEDIAWIKI ) {
			// If the user chooses a variant, the content is actually
			// in a language whose code is the variant code.
			$variant = $this->getLanguageConverter( $pageLang )->getPreferredVariant();
			if ( $pageLang->getCode() !== $variant ) {
				$pageLang = MediaWikiServices::getInstance()->getLanguageFactory()
					->getLanguage( $variant );
			}
		}

		return $pageLang;
	}
Peter.ovchyn renamed this task from Once we have ContentHandlerFactory, we can think about injecting the LanguageConverterFactory. to Once we have ContentHandlerFactory, we can think about injecting the LanguageConverterFactory into ContentHandler..Jan 23 2020, 10:11 AM

ContentHandler currently doesn't use LanguageConverter, as far as I can see.

It does! I'm not sure what for but:

Ah right - in current master, it's still using it indirectly, via Language::getPreferredVariant().

PageViewLanguage as currently defined is a flawed concept, see e.g. T206101: Sort out how page/rendering language related properties are used.

I just created T243560: Use ObjectFactory to construct ContentHandlers. The way to inject services into a ContentHandler would be similar to what SpecialPageFactory does for EditTags and RevisionDelete: instead of using the plain class name as the "spec", an array is used that specifies the class name and also a list of services to pass. This in this case, the "spec" would be in $wgContentHandlers in DefaultSettings.php.

Peter.ovchyn set the point value for this task to 2.Apr 20 2020, 3:02 PM
Helga_sf triaged this task as Medium priority.Jun 11 2020, 11:11 AM