/** * @see EntityStore::saveEntity * @see WikiPage::doEditContent * * @param EntityDocument $entity * @param string $summary * @param User $user * @param int $flags * @param int|bool $baseRevId * * @throws StorageException * @return EntityRevision */ public function saveEntity(EntityDocument $entity, $summary, User $user, $flags = 0, $baseRevId = false) { if ($entity->getId() === null) { if (($flags & EDIT_NEW) !== EDIT_NEW) { throw new StorageException(Status::newFatal('edit-gone-missing')); } $this->assignFreshId($entity); } $content = $this->contentFactory->newFromEntity($entity); $revision = $this->saveEntityContent($content, $summary, $user, $flags, $baseRevId); $entityRevision = new EntityRevision($entity, $revision->getId(), $revision->getTimestamp()); $this->dispatcher->dispatch('entityUpdated', $entityRevision); return $entityRevision; }
/** * Call EditFilterMergedContent hook, if registered. * * @param EntityDocument|EntityRedirect|null $new The entity or redirect we are trying to save * @param User $user the user performing the edit * @param string $summary The edit summary * * @throws RuntimeException * @throws InvalidArgumentException * @return Status */ public function run($new, User $user, $summary) { $filterStatus = Status::newGood(); if (!Hooks::isRegistered('EditFilterMergedContent')) { return $filterStatus; } if ($new instanceof EntityDocument) { $entityContent = $this->entityContentFactory->newFromEntity($new); $context = $this->getContextForEditFilter($new->getId(), $new->getType()); } elseif ($new instanceof EntityRedirect) { $entityContent = $this->entityContentFactory->newFromRedirect($new); if ($entityContent === null) { throw new RuntimeException('Cannot get EntityContent from EntityRedirect of type ' . $new->getEntityId()->getEntityType()); } $context = $this->getContextForEditFilter($new->getEntityId(), $new->getEntityId()->getEntityType()); } else { throw new InvalidArgumentException('$new must be instance of Entity or EntityRedirect'); } if (!Hooks::run('EditFilterMergedContent', array($context, $entityContent, &$filterStatus, $summary, $user, false))) { // Error messages etc. were handled inside the hook. $filterStatus->setResult(false, $filterStatus->getValue()); } return $filterStatus; }