/** * @dataProvider entitiesProvider */ public function testUpdateParserOutput(array $entities, $statements, $siteLinks) { $statementDataUpdater = $this->getMock('Wikibase\\Repo\\ParserOutput\\StatementDataUpdater'); $statementDataUpdater->expects($this->exactly($statements))->method('processStatement'); $statementDataUpdater->expects($this->once())->method('updateParserOutput'); $siteLinkDataUpdater = $this->getMock('Wikibase\\Repo\\ParserOutput\\SiteLinkDataUpdater'); $siteLinkDataUpdater->expects($this->exactly($siteLinks))->method('processSiteLink'); $siteLinkDataUpdater->expects($this->once())->method('updateParserOutput'); $instance = new EntityParserOutputDataUpdater(new ParserOutput(), array($statementDataUpdater, $siteLinkDataUpdater)); foreach ($entities as $entity) { $instance->processEntity($entity); } $instance->finish(); }
/** * Creates the parser output for the given entity revision. * * @since 0.5 * * @note: the new ParserOutput will be registered as a watcher with $options by * calling $options->registerWatcher( array( $parserOutput, 'recordOption' ) ). * * @param EntityRevision $entityRevision * @param ParserOptions $options * @param bool $generateHtml * * @throws InvalidArgumentException * @return ParserOutput */ public function getParserOutput(EntityRevision $entityRevision, ParserOptions $options, $generateHtml = true) { $parserOutput = new ParserOutput(); $options->registerWatcher(array($parserOutput, 'recordOption')); // @note: SIDE EFFECT: the call to $options->getUserLang() effectively splits // the parser cache. It gets reported to the ParserOutput which is registered // as a watcher to $options above. if ($options->getUserLang() !== $this->languageCode) { // The language requested by $parserOptions is different from what // this generator was configured for. This indicates an inconsistency. throw new InvalidArgumentException('Unexpected user language in ParserOptions'); } $entity = $entityRevision->getEntity(); $updater = new EntityParserOutputDataUpdater($parserOutput, $this->dataUpdaters); $updater->processEntity($entity); $updater->finish(); $configVars = $this->configBuilder->build($entity); $parserOutput->addJsConfigVars($configVars); // FIXME: OCP violation - https://phabricator.wikimedia.org/T75495 if ($entity instanceof Item) { $this->addBadgesToParserOutput($parserOutput, $entity->getSiteLinkList()); } $this->addTitleTextToParserOutput($parserOutput, $entity); if ($generateHtml) { $this->addHtmlToParserOutput($parserOutput, $entityRevision, $this->getEntityInfo($parserOutput), $options->getEditSection()); } else { // If we don't have HTML, the ParserOutput in question // shouldn't be cacheable. $parserOutput->updateCacheExpiry(0); } //@todo: record sitelinks as iwlinks $this->addModules($parserOutput); //FIXME: some places, like Special:NewItem, don't want to override the page title. // But we still want to use OutputPage::addParserOutput to apply the modules etc from the ParserOutput. // So, for now, we leave it to the caller to override the display title, if desired. // set the display title //$parserOutput->setTitleText( $entity>getLabel( $langCode ) ); // Sometimes extensions like SpamBlacklist might call getParserOutput // before the id is assigned, during the process of creating a new entity. // in that case, no alternate links are added, which probably is no problem. if ($entity->getId() !== null) { $this->addAlternateLinks($parserOutput, $entity->getId()); } return $parserOutput; }