Page MenuHomePhabricator

Once we have ContentHandlerFactory, we can think about injecting the LanguageConverterFactory into ContentHandler.
Open, Needs TriagePublic

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.

Peter.ovchyn updated the task description. (Show Details)Jan 22 2020, 9:47 PM

Updated description with more context.

Peter.ovchyn added a comment.EditedJan 22 2020, 9:51 PM

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.