/** * @param EntityRedirect|null $redirect * * @return RedirectCreationInteractor */ public function getMockRedirectCreationInteractor(EntityRedirect $redirect = null) { $mock = $this->getMockBuilder('Wikibase\\Repo\\Interactors\\RedirectCreationInteractor')->disableOriginalConstructor()->getMock(); if ($redirect) { $mock->expects($this->once())->method('createRedirect')->with($redirect->getEntityId(), $redirect->getTargetId())->will($this->returnCallback(function () use($redirect) { return $redirect; })); } else { $mock->expects($this->never())->method('createRedirect'); } return $mock; }
/** * Will return a new EntityContent representing the given EntityRedirect, * or null if the Content class does not support redirects (that is, if it does * not have a static newFromRedirect() function). * * @see makeRedirectContent() * @see supportsRedirects() * * @since 0.5 * * @param EntityRedirect $redirect * * @return EntityContent|null */ public function makeEntityRedirectContent(EntityRedirect $redirect) { $contentClass = $this->getContentClass(); if (!$this->supportsRedirects()) { return null; } else { $title = $this->getTitleForId($redirect->getTargetId()); return $contentClass::newFromRedirect($redirect, $title); } }
/** * Encodes an EntityRedirect into a blob for storage. * * @see EntityHandler::serializeContent() * * @param EntityRedirect $redirect * @param string|null $format The desired serialization format. * * @throws InvalidArgumentException If the format is not supported. * @throws MWContentSerializationException * @return string A blob representing the given Entity. */ public function encodeRedirect(EntityRedirect $redirect, $format) { // TODO: Use proper Serializer $data = array('entity' => $redirect->getEntityId()->getSerialization(), 'redirect' => $redirect->getTargetId()->getSerialization()); return $this->encodeEntityContentData($data, $format); }
/** * Notifies the cache that a redirect was created or updated. * * @param EntityRedirect $entityRedirect * @param int $revisionId */ public function redirectUpdated(EntityRedirect $entityRedirect, $revisionId) { //TODO: cache redirects $key = $this->getCacheKey($entityRedirect->getEntityId()); $this->cache->delete($key); }
/** * @see EntityStore::saveRedirect * * @param EntityRedirect $redirect * @param string $summary * @param User $user * @param int $flags * @param int|bool $baseRevisionId * * @throws StorageException If the given type of entity does not support redirects * @return int The revision id created by storing the redirect */ public function saveRedirect(EntityRedirect $redirect, $summary, User $user, $flags = 0, $baseRevisionId = false) { if (!$redirect->getEntityId() instanceof ItemId) { throw new StorageException('Entity type does not support redirects: ' . $redirect->getEntityId()->getEntityType()); } $this->putRedirect($redirect); $revisionId = ++$this->maxRevisionId; $this->putLog($revisionId, $redirect->getEntityId(), $summary, $user->getName()); return $revisionId; }
/** * @param EntityId $targetId * @param EntityRedirect|null $followedRedirect The followed redirect, will be omitted from the * output. * @param EntityId[] $incomingRedirects * @param RdfBuilder $rdfBuilder */ private function addIncomingRedirects(EntityId $targetId, EntityRedirect $followedRedirect = null, array $incomingRedirects, RdfBuilder $rdfBuilder) { foreach ($incomingRedirects as $rId) { // don't add the followed redirect again if (!$followedRedirect || !$followedRedirect->getEntityId()->equals($rId)) { $rdfBuilder->addEntityRedirect($rId, $targetId); } } }
public function testToString() { $redirect = new EntityRedirect(new ItemId('Q1'), new ItemId('Q2')); $this->assertSame('Q1->Q2', $redirect->__toString()); }
/** * @param EntityRedirect $redirect * @param Summary $summary * @param bool $bot Whether the edit should be marked as bot * * @throws RedirectCreationException */ private function saveRedirect(EntityRedirect $redirect, Summary $summary, $bot) { $summary = $this->summaryFormatter->formatSummary($summary); $flags = 0; if ($bot) { $flags = $flags | EDIT_FORCE_BOT; } if ($this->entityTitleLookup->getTitleForId($redirect->getEntityId())->isDeleted()) { $flags = $flags | EDIT_NEW; } else { $flags = $flags | EDIT_UPDATE; } $hookStatus = $this->editFilterHookRunner->run($redirect, $this->user, $summary); if (!$hookStatus->isOK()) { throw new RedirectCreationException('EditFilterHook stopped redirect creation', 'cant-redirect'); } try { $this->entityStore->saveRedirect($redirect, $summary, $this->user, $flags); } catch (StorageException $ex) { throw new RedirectCreationException($ex->getMessage(), 'cant-redirect', $ex); } }
/** * Constructs a new EntityContent from an EntityRedirect, * or null if the respective kind of entity does not support redirects. * * @see EntityHandler::makeEntityRedirectContent * * @since 0.5 * * @param EntityRedirect $redirect * * @return EntityContent|null */ public function newFromRedirect(EntityRedirect $redirect) { $handler = $this->getContentHandlerForType($redirect->getEntityId()->getEntityType()); return $handler->makeEntityRedirectContent($redirect); }
/** * @see EntityStoreWatcher::redirectUpdated * * @param EntityRedirect $entityRedirect * @param int $revisionId */ public function redirectUpdated(EntityRedirect $entityRedirect, $revisionId) { $this->purge($entityRedirect->getEntityId()); }