/**
  * @see EntityView::getMainHtml
  *
  * @param EntityRevision $entityRevision
  *
  * @throws InvalidArgumentException
  * @return string HTML
  */
 protected function getMainHtml(EntityRevision $entityRevision)
 {
     $item = $entityRevision->getEntity();
     if (!$item instanceof Item) {
         throw new InvalidArgumentException('$entityRevision must contain an Item.');
     }
     $html = $this->getHtmlForFingerprint($entityRevision) . $this->templateFactory->render('wikibase-toc') . $this->statementSectionsView->getHtml($item->getStatements());
     return $html;
 }
 /**
  * @see EntityView::getMainHtml
  *
  * @param EntityRevision $entityRevision
  *
  * @throws InvalidArgumentException
  * @return string HTML
  */
 protected function getMainHtml(EntityRevision $entityRevision)
 {
     $property = $entityRevision->getEntity();
     if (!$property instanceof Property) {
         throw new InvalidArgumentException('$entityRevision must contain a Property.');
     }
     $html = $this->getHtmlForFingerprint($entityRevision) . $this->templateFactory->render('wikibase-toc') . $this->getHtmlForDataType($property->getDataTypeId()) . $this->statementSectionsView->getHtml($property->getStatements());
     $footer = wfMessage('wikibase-property-footer');
     if (!$footer->isBlank()) {
         $html .= "\n" . $footer->parse();
     }
     return $html;
 }
 private function storePresetDataInStatement(EntityRevision $entityRevision, PropertyId $propertyId)
 {
     global $wgUser;
     $store = WikibaseRepo::getDefaultInstance()->getEntityStore();
     /** @var Item $item */
     $item = $entityRevision->getEntity();
     $snak = new PropertyNoValueSnak($propertyId);
     $guid = $item->getId()->getSerialization() . '$1111AAAA-43cb-ed6d-3adb-760e85bd17ee';
     $item->getStatements()->addNewStatement($snak, null, null, $guid);
     $item->setLabel('en', 'en-label');
     $item->setLabel('de', 'de-label');
     $item->setDescription('de', 'de-desc');
     $item->setDescription('es', 'es-desc');
     $item->setAliases('pt', array('AA', 'BB'));
     $item->setAliases('en', array('AA-en', 'BB-en'));
     $entityRevision = $store->saveEntity($item, 'testing more!', $wgUser);
     return $entityRevision;
 }
 /**
  * This is to set up the environment
  */
 protected function setUp()
 {
     parent::setUp();
     //TODO: remove global TestSites DB setup once we can inject sites sanely.
     static $hasSites = false;
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     if (!$hasSites) {
         $sitesTable = $wikibaseRepo->getSiteStore();
         $sitesTable->clear();
         $sitesTable->saveSites(TestSites::getSites());
         $hasSites = true;
     }
     $item = new Item();
     $this->entityRevision = $wikibaseRepo->getEntityStore()->saveEntity($item, '', $GLOBALS['wgUser'], EDIT_NEW);
     $id = $this->entityRevision->getEntity()->getId();
     $this->itemTitle = $wikibaseRepo->getEntityTitleLookup()->getTitleForId($id);
     $title = Title::newFromText('wbmovetest', $this->getDefaultWikitextNS());
     $this->page = new WikiPage($title);
     $this->page->doEditContent(new WikitextContent('foobar'), 'test');
 }
 /**
  * @see SpecialWikibasePage::execute
  *
  * @since 0.4
  *
  * @param string|null $subPage
  */
 public function execute($subPage)
 {
     parent::execute($subPage);
     $this->checkPermissions();
     $this->checkBlocked();
     $this->checkReadOnly();
     $this->setHeaders();
     $this->outputHeader();
     try {
         $this->prepareArguments($subPage);
     } catch (UserInputException $ex) {
         $error = $this->msg($ex->getKey(), $ex->getParams())->parse();
         $this->showErrorHTML($error);
     }
     $summary = false;
     $valid = $this->validateInput();
     $entity = $this->entityRevision === null ? null : $this->entityRevision->getEntity();
     if ($valid) {
         $summary = $this->modifyEntity($entity);
     }
     if (!$summary) {
         $this->setForm($entity);
     } else {
         //TODO: Add conflict detection. All we need to do is to provide the base rev from
         // $this->entityRevision to the saveEntity() call. But we need to make sure
         // conflicts are reported in a nice way first. In particular, we'd want to
         // show the form again.
         $status = $this->saveEntity($entity, $summary, $this->getRequest()->getVal('wpEditToken'));
         if (!$status->isOK() && $status->getErrorsArray()) {
             $errors = $status->getErrorsArray();
             $this->showErrorHTML($this->msg($errors[0][0], array_slice($errors[0], 1))->parse());
             $this->setForm($entity);
         } else {
             $entityUrl = $this->getEntityTitle($entity->getId())->getFullUrl();
             $this->getOutput()->redirect($entityUrl);
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Returns the latest revision ID.
  *
  * @return int 0 if the entity doesn't exist
  */
 private function getLatestRevisionId()
 {
     // Don't do negative caching: We call this to see whether the entity yet exists
     // before creating.
     if ($this->latestRevId === 0) {
         $id = $this->newEntity->getId();
         if ($this->latestRev !== null) {
             $this->latestRevId = $this->latestRev->getRevisionId();
         } elseif ($id !== null) {
             $this->latestRevId = (int) $this->entityRevisionLookup->getLatestRevisionId($id, EntityRevisionLookup::LATEST_FROM_MASTER);
         }
     }
     return $this->latestRevId;
 }
 private function addEntityToOutput(EntityRevision $entityRevision, $name)
 {
     $entityId = $entityRevision->getEntity()->getId();
     $revisionId = $entityRevision->getRevisionId();
     $this->resultBuilder->addBasicEntityInformation($entityId, $name);
     $this->resultBuilder->setValue($name, 'lastrevid', (int) $revisionId);
 }
 /**
  * Notifies the cache that an Entity was created or updated.
  *
  * @param EntityRevision $entityRevision
  */
 public function entityUpdated(EntityRevision $entityRevision)
 {
     $key = $this->getCacheKey($entityRevision->getEntity()->getId());
     $this->cache->set($key, $entityRevision, $this->cacheTimeout);
 }
 /**
  * @since 0.4
  * @see EntityRevisionLookup::getEntityRevision
  *
  * @param EntityId $entityId
  * @param int|string $revisionId The desired revision id, or LATEST_FROM_SLAVE or LATEST_FROM_MASTER.
  *
  * @throws RevisionedUnresolvedRedirectException
  * @throws StorageException
  * @return EntityRevision|null
  */
 public function getEntityRevision(EntityId $entityId, $revisionId = self::LATEST_FROM_SLAVE)
 {
     $key = $entityId->getSerialization();
     if (isset($this->redirects[$key])) {
         $redirRev = $this->redirects[$key];
         throw new RevisionedUnresolvedRedirectException($entityId, $redirRev->getRedirect()->getTargetId(), $redirRev->getRevisionId(), $redirRev->getTimestamp());
     }
     if (empty($this->entities[$key])) {
         return null;
     }
     // default changed from false to 0 and then to LATEST_FROM_SLAVE
     if ($revisionId === false || $revisionId === 0) {
         wfWarn('getEntityRevision() called with $revisionId = false or 0, ' . 'use EntityRevisionLookup::LATEST_FROM_SLAVE or EntityRevisionLookup::LATEST_FROM_MASTER instead.');
         $revisionId = self::LATEST_FROM_SLAVE;
     }
     /** @var EntityRevision[] $revisions */
     $revisions = $this->entities[$key];
     if (!is_int($revisionId)) {
         $revisionIds = array_keys($revisions);
         $revisionId = end($revisionIds);
     } elseif (!isset($revisions[$revisionId])) {
         throw new StorageException("no such revision for entity {$key}: {$revisionId}");
     }
     $revision = $revisions[$revisionId];
     $revision = new EntityRevision(unserialize(serialize($revision->getEntity())), $revision->getRevisionId(), $revision->getTimestamp());
     return $revision;
 }
Ejemplo n.º 10
0
 /**
  * Get serialized entity for the EntityRevision and add it to the result
  *
  * @param string|null $sourceEntityIdSerialization EntityId used to retreive $entityRevision
  *        Used as the key for the entity in the 'entities' structure and for adding redirect
  *     info Will default to the entity's serialized ID if null. If given this must be the
  *     entity id before any redirects were resolved.
  * @param EntityRevision $entityRevision
  * @param string[]|string $props a list of fields to include, or "all"
  * @param string[]|null $filterSiteIds A list of site IDs to filter by
  * @param string[] $filterLangCodes A list of language codes to filter by
  * @param LanguageFallbackChain[] $fallbackChains with keys of the origional language
  *
  * @since 0.5
  */
 public function addEntityRevision($sourceEntityIdSerialization, EntityRevision $entityRevision, $props = 'all', array $filterSiteIds = null, array $filterLangCodes = array(), array $fallbackChains = array())
 {
     $entity = $entityRevision->getEntity();
     $entityId = $entity->getId();
     if ($sourceEntityIdSerialization === null) {
         $sourceEntityIdSerialization = $entityId->getSerialization();
     }
     $record = array();
     //if there are no props defined only return type and id..
     if ($props === array()) {
         $record['id'] = $entityId->getSerialization();
         $record['type'] = $entityId->getEntityType();
     } else {
         if ($props == 'all' || in_array('info', $props)) {
             $title = $this->entityTitleLookup->getTitleForId($entityId);
             $record['pageid'] = $title->getArticleID();
             $record['ns'] = $title->getNamespace();
             $record['title'] = $title->getPrefixedText();
             $record['lastrevid'] = $entityRevision->getRevisionId();
             $record['modified'] = wfTimestamp(TS_ISO_8601, $entityRevision->getTimestamp());
         }
         if ($sourceEntityIdSerialization !== $entityId->getSerialization()) {
             $record['redirects'] = array('from' => $sourceEntityIdSerialization, 'to' => $entityId->getSerialization());
         }
         $entitySerialization = $this->getEntityArray($entity, $props, $filterSiteIds, $filterLangCodes, $fallbackChains);
         $record = array_merge($record, $entitySerialization);
     }
     $this->appendValue(array('entities'), $sourceEntityIdSerialization, $record, 'entity');
     if ($this->addMetaData) {
         $this->result->addArrayType(array('entities'), 'kvp', 'id');
         $this->result->addValue(array('entities'), ApiResult::META_KVP_MERGE, true, ApiResult::OVERRIDE);
     }
 }
 /**
  * @param ParserOutput $parserOutput
  * @param EntityRevision $entityRevision
  * @param EntityInfo $entityInfo
  * @param bool $editable
  */
 private function addHtmlToParserOutput(ParserOutput $parserOutput, EntityRevision $entityRevision, EntityInfo $entityInfo, $editable = true)
 {
     $labelDescriptionLookup = new LanguageFallbackLabelDescriptionLookup(new EntityInfoTermLookup($entityInfo), $this->languageFallbackChain);
     $editSectionGenerator = $editable ? new ToolbarEditSectionGenerator(new RepoSpecialPageLinker(), $this->templateFactory) : new EmptyEditSectionGenerator();
     $entityView = $this->entityViewFactory->newEntityView($entityRevision->getEntity()->getType(), $this->languageCode, $labelDescriptionLookup, $this->languageFallbackChain, $editSectionGenerator);
     // Set the display title to display the label together with the item's id
     $titleHtml = $entityView->getTitleHtml($entityRevision);
     $parserOutput->setDisplayTitle($titleHtml);
     $html = $entityView->getHtml($entityRevision);
     $parserOutput->setText($html);
     $parserOutput->setExtensionData('wikibase-view-chunks', $entityView->getPlaceholders());
     // Force parser cache split by whether edit links are show.
     // MediaWiki core has the ability to split on editsection, but does not trigger it
     // automatically when $parserOptions->getEditSection() is called. Presumably this
     // is because core uses <mw:editsection> tags that are substituted by ParserOutput::getText
     // using the info from ParserOutput::getEditSectionTokens.
     $parserOutput->recordOption('editsection');
     // Since the output depends on the user language, we must make sure
     // ParserCache::getKey() includes it in the cache key.
     $parserOutput->recordOption('userlang');
 }
 /**
  * @param EntityRevision $entityRevision
  * @param RedirectRevision|null $followedRedirect a redirect leading to the entity for use in the output
  * @param EntityId[] $incomingRedirects Incoming redirects to include in the output
  * @param RdfBuilder $rdfBuilder
  * @param string|null $flavor The type of the output provided by serializer
  *
  * @return string RDF
  */
 private function rdfSerialize(EntityRevision $entityRevision, RedirectRevision $followedRedirect = null, array $incomingRedirects, RdfBuilder $rdfBuilder, $flavor = null)
 {
     $rdfBuilder->startDocument();
     $redir = null;
     if ($followedRedirect) {
         $redir = $followedRedirect->getRedirect();
         $rdfBuilder->addEntityRedirect($redir->getEntityId(), $redir->getTargetId());
         if ($followedRedirect->getRevisionId() > 0) {
             $rdfBuilder->addEntityRevisionInfo($redir->getEntityId(), $followedRedirect->getRevisionId(), $followedRedirect->getTimestamp());
         }
     }
     if ($followedRedirect && $flavor === 'dump') {
         // For redirects, don't output the target entity data if the "dump" flavor is requested.
         // @todo: In this case, avoid loading the Entity all together.
         // However we want to output the revisions for redirects
     } else {
         $rdfBuilder->addEntityRevisionInfo($entityRevision->getEntity()->getId(), $entityRevision->getRevisionId(), $entityRevision->getTimestamp());
         $rdfBuilder->addEntity($entityRevision->getEntity());
         $rdfBuilder->resolveMentionedEntities($this->entityLookup);
     }
     if ($flavor !== 'dump') {
         // For $flavor === 'dump' we don't need to output incoming redirects.
         $targetId = $entityRevision->getEntity()->getId();
         $this->addIncomingRedirects($targetId, $redir, $incomingRedirects, $rdfBuilder);
     }
     $rdfBuilder->finishDocument();
     return $rdfBuilder->getRDF();
 }
 /**
  * @see EntityStoreWatcher::entityDeleted
  *
  * @param EntityRevision $entityRevision
  */
 public function entityUpdated(EntityRevision $entityRevision)
 {
     $this->purge($entityRevision->getEntity()->getId());
 }
 /**
  * Builds and returns the HTML for the entity's fingerprint.
  *
  * @param EntityRevision $entityRevision
  *
  * @return string HTML
  */
 protected function getHtmlForFingerprint(EntityRevision $entityRevision)
 {
     $entity = $entityRevision->getEntity();
     $id = $entity->getId();
     if ($entity instanceof FingerprintProvider) {
         return $this->entityTermsView->getHtml($entity->getFingerprint(), $id, $this->getHtmlForTermBox($id, $entityRevision->getRevisionId()), $this->textInjector);
     }
     return '';
 }