/** * @throws LogicException * @return SnakFormatter */ private function getSnakFormatter() { $params = $this->extractRequestParams(); $options = $this->getOptionsObject($params['options']); $formatter = $this->snakFormatterFactory->getSnakFormatter($params['generate'], $options); return $formatter; }
/** * @param Language $language * @param UsageAccumulator $usageAccumulator * * @return SnakFormatter */ private function newSnakFormatterForLanguage(Language $language, UsageAccumulator $usageAccumulator) { $languageFallbackChain = $this->languageFallbackChainFactory->newFromLanguage($language, LanguageFallbackChainFactory::FALLBACK_SELF | LanguageFallbackChainFactory::FALLBACK_VARIANTS); $options = new FormatterOptions(array(FormatterLabelDescriptionLookupFactory::OPT_LANGUAGE_FALLBACK_CHAIN => $languageFallbackChain, ValueFormatter::OPT_LANG => $language->getCode())); $snakFormatter = new UsageTrackingSnakFormatter($this->snakFormatterFactory->getSnakFormatter(SnakFormatter::FORMAT_WIKI, $options), $usageAccumulator, $languageFallbackChain->getFetchLanguageCodes()); return $snakFormatter; }
/** * @param string $languageCode * @param LanguageFallbackChain $languageFallbackChain * @param LabelDescriptionLookup $labelDescriptionLookup * * @return SnakFormatter */ public function getSnakFormatter($languageCode, LanguageFallbackChain $languageFallbackChain, LabelDescriptionLookup $labelDescriptionLookup) { $formatterOptions = $this->getFormatterOptions($languageCode, $languageFallbackChain, $labelDescriptionLookup); return $this->snakFormatterFactory->getSnakFormatter(SnakFormatter::FORMAT_HTML_WIDGET, $formatterOptions); }
/** * @return SummaryFormatter */ protected function newSummaryFormatter() { global $wgContLang; // This needs to use an EntityIdPlainLinkFormatter as we want to mangle // the links created in LinkBeginHookHandler afterwards (the links must not // contain a display text: [[Item:Q1]] is fine but [[Item:Q1|Q1]] isn't). $idFormatter = new EntityIdPlainLinkFormatter($this->getEntityContentFactory()); // Create a new ValueFormatterFactory, and override the formatter for entity IDs. $valueFormatterFactory = $this->newValueFormatterFactory(); foreach ($this->getEntityFactory()->getEntityTypes() as $entityType) { $valueFormatterFactory->setFormatterFactoryCallback("PT:wikibase-{$entityType}", function ($format, FormatterOptions $options) use($idFormatter) { if ($format === SnakFormatter::FORMAT_PLAIN) { return new EntityIdValueFormatter($idFormatter); } else { return null; } }); } // Create a new SnakFormatterFactory based on the specialized ValueFormatterFactory. $snakFormatterFactory = new OutputFormatSnakFormatterFactory(array(), $valueFormatterFactory, $this->getPropertyDataTypeLookup(), $this->getDataTypeFactory()); $options = new FormatterOptions(); $snakFormatter = $snakFormatterFactory->getSnakFormatter(SnakFormatter::FORMAT_PLAIN, $options); $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_PLAIN, $options); $formatter = new SummaryFormatter($idFormatter, $valueFormatter, $snakFormatter, $wgContLang, $this->getEntityIdParser()); return $formatter; }
public function testGetSnakFormatter_languageOption() { $self = $this; $callbacks = array('VT:string' => function ($format, FormatterOptions $options) use($self) { $self->assertSame('de', $options->getOption(ValueFormatter::OPT_LANG)); return new StringFormatter($options); }); $valueFormatterFactory = new OutputFormatValueFormatterFactory($callbacks, Language::factory('de'), new LanguageFallbackChainFactory()); $factory = new OutputFormatSnakFormatterFactory(array(), $valueFormatterFactory, $this->getMock('Wikibase\\DataModel\\Services\\Lookup\\PropertyDataTypeLookup'), new DataTypeFactory(array())); $factory->getSnakFormatter(SnakFormatter::FORMAT_PLAIN, new FormatterOptions()); }