/**
  * @see EntityStore::saveRedirect
  * @see WikiPage::doEditContent
  *
  * @param EntityRedirect $redirect
  * @param string $summary
  * @param User $user
  * @param int $flags
  * @param int|bool $baseRevId
  *
  * @throws StorageException
  * @return int The new revision ID
  */
 public function saveRedirect(EntityRedirect $redirect, $summary, User $user, $flags = 0, $baseRevId = false)
 {
     $content = $this->contentFactory->newFromRedirect($redirect);
     if (!$content) {
         throw new StorageException('Failed to create redirect' . ' from ' . $redirect->getEntityId()->getSerialization() . ' to ' . $redirect->getTargetId()->getSerialization());
     }
     $revision = $this->saveEntityContent($content, $summary, $user, $flags, $baseRevId);
     $this->dispatcher->dispatch('redirectUpdated', $redirect, $revision->getId());
     return $revision->getId();
 }
 /**
  * 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;
 }