/**
  * Builds and returns the HTML representing a whole WikibaseEntity.
  *
  * @note: The HTML returned by this method may contain placeholders. Such placeholders can be
  * expanded with the help of TextInjector::inject() calling back to
  * EntityViewPlaceholderExpander::getExtraUserLanguages()
  * @note: In order to keep the list of placeholders small, this calls resetPlaceholders().
  *
  * @since 0.1
  *
  * @param EntityRevision $entityRevision the entity to render
  *
  * @return string HTML
  */
 public function getHtml(EntityRevision $entityRevision)
 {
     $entity = $entityRevision->getEntity();
     $entityId = $entity->getId() ?: 'new';
     // if id is not set, use 'new' suffix for css classes
     $html = $this->templateFactory->render('wikibase-entityview', $entity->getType(), $entityId, $this->language->getCode(), $this->language->getDir(), $this->getMainHtml($entityRevision), $this->getSideHtml($entity));
     return $html;
 }
 /**
  * Generates the HTML for a single snak.
  *
  * @param Snak $snak
  * @param bool $showPropertyLink
  *
  * @return string
  */
 public function getSnakHtml(Snak $snak, $showPropertyLink = false)
 {
     $snakViewVariation = $this->getSnakViewVariation($snak);
     $snakViewCssClass = 'wikibase-snakview-variation-' . $snakViewVariation;
     $formattedValue = $this->getFormattedSnakValue($snak);
     if ($formattedValue === '') {
         $formattedValue = ' ';
     }
     $propertyLink = $showPropertyLink ? $this->makePropertyLink($snak) : '';
     $html = $this->templateFactory->render('wikibase-snakview', $propertyLink, $snakViewCssClass, $formattedValue);
     return $html;
 }
 /**
  * @param string $cssClassSuffix
  * @param string $buttonLabel the message to show on the toolbar button link
  * @param string|null $editUrl The edit url
  *
  * @return string
  */
 private function getToolbarButton($cssClassSuffix, $buttonLabel, $editUrl = null)
 {
     if ($editUrl === null) {
         return '';
     }
     return $this->templateFactory->render('wikibase-toolbar-button', 'wikibase-toolbar-button-' . $cssClassSuffix, $editUrl, $buttonLabel);
 }
 /**
  * @return OutputPageBeforeHTMLHookHandler
  */
 public static function newFromGlobalState()
 {
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $entityIdParser = $wikibaseRepo->getEntityIdParser();
     $entityContentFactory = $wikibaseRepo->getEntityContentFactory();
     return new self(TemplateFactory::getDefaultInstance(), new BabelUserLanguageLookup(), $wikibaseRepo->getTermsLanguages(), $entityIdParser, $wikibaseRepo->getEntityRevisionLookup(), new LanguageNameLookup(), $entityContentFactory);
 }
 /**
  * @param Statement[] $statements
  * @param string $addStatementHtml
  *
  * @return string HTML
  */
 private function getHtmlForStatementListView(array $statements, $addStatementHtml)
 {
     $statementViewsHtml = '';
     foreach ($statements as $statement) {
         $statementViewsHtml .= $this->claimHtmlGenerator->getHtmlForClaim($statement, $this->editSectionGenerator->getStatementEditSection($statement instanceof Statement ? $statement : new Statement($statement)));
     }
     return $this->templateFactory->render('wikibase-statementlistview', $statementViewsHtml, $addStatementHtml);
 }
 /**
  * Generates the HTML for a list of snaks.
  *
  * @param Snak[] $snaks
  *
  * @return string HTML
  */
 private function getSnaklistviewHtml(array $snaks)
 {
     $snaksHtml = '';
     $i = 0;
     foreach ($snaks as $snak) {
         $snaksHtml .= $this->snakHtmlGenerator->getSnakHtml($snak, $i++ === 0);
     }
     return $this->templateFactory->render('wikibase-snaklistview', $snaksHtml);
 }
 private function newToolbarEditSectionGenerator()
 {
     $specialPageLinker = $this->getMock('Wikibase\\View\\SpecialPageLinker');
     $specialPageLinker->expects($this->any())->method('getLink')->will($this->returnCallback(function ($specialPage, $params = array()) {
         return 'Special:' . $specialPage . '/' . implode('/', $params);
     }));
     $templateFactory = TemplateFactory::getDefaultInstance();
     return new ToolbarEditSectionGenerator($specialPageLinker, $templateFactory);
 }
 /**
  * @dataProvider getHtmlForClaimProvider
  *
  * @uses Wikibase\View\Template\Template
  * @uses Wikibase\View\Template\TemplateFactory
  * @uses Wikibase\View\Template\TemplateRegistry
  */
 public function testGetHtmlForClaim(SnakHtmlGenerator $snakHtmlGenerator, Statement $statement, $patterns)
 {
     $templateFactory = TemplateFactory::getDefaultInstance();
     $claimHtmlGenerator = new ClaimHtmlGenerator($templateFactory, $snakHtmlGenerator);
     $html = $claimHtmlGenerator->getHtmlForClaim($statement, 'edit');
     foreach ($patterns as $message => $pattern) {
         $this->assertRegExp($pattern, $html, $message);
     }
 }
 /**
  * @param PHPUnit_Framework_MockObject_Matcher_Invocation $formatPropertyIdMatcher
  *
  * @return SnakHtmlGenerator
  */
 private function getSnakHtmlGenerator(PHPUnit_Framework_MockObject_Matcher_Invocation $formatPropertyIdMatcher)
 {
     $snakFormatter = $this->getMock('Wikibase\\Lib\\SnakFormatter');
     $snakFormatter->expects($this->once())->method('formatSnak')->will($this->returnValue('<SNAK>'));
     $snakFormatter->expects($this->once())->method('getFormat')->will($this->returnValue(SnakFormatter::FORMAT_HTML));
     $propertyIdFormatter = $this->getMock('Wikibase\\DataModel\\Services\\EntityId\\EntityIdFormatter');
     $propertyIdFormatter->expects($formatPropertyIdMatcher)->method('formatEntityId')->will($this->returnValue('<ID>'));
     return new SnakHtmlGenerator(TemplateFactory::getDefaultInstance(), $snakFormatter, $propertyIdFormatter);
 }
 /**
  * @param string $key
  *
  * @return string HTML
  */
 private function getHtmlForSectionHeading($key)
 {
     /**
      * Message keys:
      * wikibase-statementsection-statements
      * wikibase-statementsection-identifiers
      */
     $msg = wfMessage('wikibase-statementsection-' . strtolower($key));
     $className = 'wikibase-statements';
     if ($key === 'statements') {
         $id = 'claims';
     } else {
         $id = $key;
         $className .= ' wikibase-statements-' . $key;
     }
     // TODO: Add link to SpecialPage that allows adding a new statement.
     return $this->templateFactory->render('wb-section-heading', $msg->escaped(), $id, $className);
 }
 private function getEntityTermsView($editSectionCalls = 0, $languageNameCalls = 0, $languageCode = 'en')
 {
     $editSectionGenerator = $this->getMock('Wikibase\\View\\EditSectionGenerator');
     $editSectionGenerator->expects($this->exactly($editSectionCalls))->method('getLabelDescriptionAliasesEditSection')->will($this->returnValue('<EDITSECTION>'));
     $languageNameLookup = $this->getMock('Wikibase\\Lib\\LanguageNameLookup');
     $languageNameLookup->expects($this->exactly($languageNameCalls))->method('getName')->will($this->returnCallback(function ($languageCode) {
         return "<LANGUAGENAME-{$languageCode}>";
     }));
     return new EntityTermsView(TemplateFactory::getDefaultInstance(), $editSectionGenerator, $languageNameLookup, $languageCode);
 }
 /**
  * @return OutputPageBeforeHTMLHookHandler
  */
 private function getHookHandler()
 {
     $userLanguageLookup = $this->getMock('Wikibase\\Lib\\UserLanguageLookup');
     $userLanguageLookup->expects($this->once())->method('getUserSpecifiedLanguages')->will($this->returnValue(array('de', 'es', 'ru')));
     $contentLanguages = $this->getMock('Wikibase\\Lib\\ContentLanguages');
     $contentLanguages->expects($this->once())->method('getLanguages')->will($this->returnValue(array('en', 'es', 'ru')));
     $languageNameLookup = $this->getMock('Wikibase\\Lib\\LanguageNameLookup');
     $languageNameLookup->expects($this->never())->method('getName');
     $outputPageBeforeHTMLHookHandler = new OutputPageBeforeHTMLHookHandler(TemplateFactory::getDefaultInstance(), $userLanguageLookup, $contentLanguages, new BasicEntityIdParser(), $this->getMock('Wikibase\\Lib\\Store\\EntityRevisionLookup'), $languageNameLookup, new EntityContentFactory(array()));
     return $outputPageBeforeHTMLHookHandler;
 }
 /**
  * @param User $user
  * @param EntityRevisionLookup $entityRevisionLookup
  * @param ItemId $itemId
  *
  * @return EntityViewPlaceholderExpander
  */
 private function newExpander(User $user, EntityRevisionLookup $entityRevisionLookup, ItemId $itemId)
 {
     $templateFactory = TemplateFactory::getDefaultInstance();
     $title = $this->getMockBuilder('Title')->disableOriginalConstructor()->getMock();
     $language = Language::factory('en');
     $idParser = $this->getMockBuilder('Wikibase\\DataModel\\Entity\\EntityIdParser')->disableOriginalConstructor()->getMock();
     $idParser->expects($this->any())->method('parse')->will($this->returnValue($itemId));
     $userLanguages = $this->getMock('Wikibase\\Lib\\UserLanguageLookup');
     $userLanguages->expects($this->any())->method('getAllUserLanguages')->will($this->returnValue(array('de', 'en', 'ru')));
     $languageNameLookup = $this->getMock('Wikibase\\Lib\\LanguageNameLookup');
     return new EntityViewPlaceholderExpander($templateFactory, $title, $user, $language, $idParser, $entityRevisionLookup, $userLanguages, new MediaWikiContentLanguages(), $languageNameLookup);
 }
 private function getHtmlForBadges(SiteLink $siteLink)
 {
     $html = '';
     foreach ($siteLink->getBadges() as $badge) {
         $serialization = $badge->getSerialization();
         $classes = Sanitizer::escapeClass($serialization);
         if (!empty($this->badgeItems[$serialization])) {
             $classes .= ' ' . Sanitizer::escapeClass($this->badgeItems[$serialization]);
         }
         $html .= $this->templateFactory->render('wb-badge', $classes, $this->entityIdFormatter->formatEntityId($badge), $badge);
     }
     return $this->templateFactory->render('wikibase-badgeselector', $html);
 }
 /**
  * @param AliasGroupList $aliasGroups
  * @param string $languageCode
  *
  * @return string HTML
  */
 private function getAliasesView(AliasGroupList $aliasGroups, $languageCode)
 {
     if (!$aliasGroups->hasGroupForLanguage($languageCode)) {
         return $this->templateFactory->render('wikibase-aliasesview', 'wb-empty', '', '');
     } else {
         $aliasesHtml = '';
         $aliases = $aliasGroups->getByLanguage($languageCode)->getAliases();
         foreach ($aliases as $alias) {
             $aliasesHtml .= $this->templateFactory->render('wikibase-aliasesview-list-item', htmlspecialchars($alias));
         }
         return $this->templateFactory->render('wikibase-aliasesview', '', $aliasesHtml, '');
     }
 }
    /**
     * @see ResourceLoaderModule::getScript
     *
     * @param ResourceLoaderContext $context
     *
     * @return string
     */
    public function getScript(ResourceLoaderContext $context)
    {
        // register HTML templates
        $templateFactory = TemplateFactory::getDefaultInstance();
        $templatesJson = FormatJson::encode($templateFactory->getTemplates());
        // template store JavaScript initialisation
        $script = <<<EOT
( function( mw ) {
\t'use strict';

\tmw.wbTemplates = mw.wbTemplates || {};
\tmw.wbTemplates.store = new mw.Map();
\tmw.wbTemplates.store.set( {$templatesJson} );

}( mediaWiki ) );
EOT;
        return $script . "\n" . parent::getScript($context);
    }
 private function newEntityParserOutputGenerator()
 {
     $entityDataFormatProvider = new EntityDataFormatProvider();
     $formats = array('json', 'ntriples');
     $entityDataFormatProvider->setFormatWhiteList($formats);
     $entityTitleLookup = $this->getEntityTitleLookupMock();
     $propertyDataTypeMatcher = new PropertyDataTypeMatcher($this->getPropertyDataTypeLookup());
     $dataUpdaters = array(new ExternalLinksDataUpdater($propertyDataTypeMatcher), new ImageLinksDataUpdater($propertyDataTypeMatcher), new ReferencedEntitiesDataUpdater($entityTitleLookup, new BasicEntityIdParser()));
     return new EntityParserOutputGenerator($this->getEntityViewFactory(), $this->getConfigBuilderMock(), $entityTitleLookup, new SqlEntityInfoBuilderFactory(), $this->newLanguageFallbackChain(), TemplateFactory::getDefaultInstance(), $entityDataFormatProvider, $dataUpdaters, 'en');
 }
 public function provideTestGetHtml()
 {
     $templateFactory = TemplateFactory::getDefaultInstance();
     $itemView = new ItemView($templateFactory, $this->getMockBuilder('Wikibase\\View\\EntityTermsView')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('Wikibase\\View\\StatementSectionsView')->disableOriginalConstructor()->getMock(), $this->getMock('Language'), $this->getMockBuilder('Wikibase\\View\\SiteLinksView')->disableOriginalConstructor()->getMock(), array());
     return array(array($itemView, $this->newEntityRevisionForStatements(array()), '/wb-item/'));
 }
예제 #19
0
 /**
  * @return EntityParserOutputGeneratorFactory
  */
 public function getEntityParserOutputGeneratorFactory()
 {
     $templateFactory = TemplateFactory::getDefaultInstance();
     $dataTypeLookup = $this->getPropertyDataTypeLookup();
     $statementGrouperBuilder = new StatementGrouperBuilder($this->settings->getSetting('statementSections'), $dataTypeLookup);
     $entityViewFactory = new EntityViewFactory($this->getEntityIdHtmlLinkFormatterFactory(), new EntityIdLabelFormatterFactory(), $this->getHtmlSnakFormatterFactory(), $statementGrouperBuilder->getStatementGrouper(), $this->getSiteStore(), $this->getDataTypeFactory(), $templateFactory, new LanguageNameLookup(), $this->settings->getSetting('siteLinkGroups'), $this->settings->getSetting('specialSiteLinkGroups'), $this->settings->getSetting('badgeItems'));
     $entityDataFormatProvider = new EntityDataFormatProvider();
     $formats = $this->getSettings()->getSetting('entityDataFormats');
     $entityDataFormatProvider->setFormatWhiteList($formats);
     return new EntityParserOutputGeneratorFactory($entityViewFactory, $this->getStore()->getEntityInfoBuilderFactory(), $this->getEntityContentFactory(), $this->getLanguageFallbackChainFactory(), $templateFactory, $entityDataFormatProvider, $dataTypeLookup, $this->getLocalEntityUriParser(), $this->settings->getSetting('preferredGeoDataProperties'), $this->settings->getSetting('preferredPageImagesProperties'), $this->settings->getSetting('globeUris'));
 }
 public function testGetDefaultInstance()
 {
     $instance = TemplateFactory::getDefaultInstance();
     $this->assertInstanceOf('Wikibase\\View\\Template\\TemplateFactory', $instance);
 }
 public function provideTestGetHtml()
 {
     $templateFactory = TemplateFactory::getDefaultInstance();
     $propertyView = new PropertyView($templateFactory, $this->getMockBuilder('Wikibase\\View\\EntityTermsView')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('Wikibase\\View\\StatementSectionsView')->disableOriginalConstructor()->getMock(), $this->getDataTypeFactory(), Language::factory('en'));
     return array(array($propertyView, $this->newEntityRevisionForStatements(array()), '/wb-property/'));
 }