/**
  * @param OutputPage $out
  *
  * @return EntityId|null
  */
 public function getEntityIdFromOutputPage(OutputPage $out)
 {
     if (!$this->entityContentFactory->isEntityContentModel($out->getTitle()->getContentModel())) {
         return null;
     }
     $jsConfigVars = $out->getJsConfigVars();
     if (array_key_exists('wbEntityId', $jsConfigVars)) {
         $idString = $jsConfigVars['wbEntityId'];
         try {
             return $this->entityIdParser->parse($idString);
         } catch (EntityIdParsingException $ex) {
             wfLogWarning('Failed to parse EntityId config var: ' . $idString);
         }
     }
     return null;
 }
 /**
  * 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;
 }
 /**
  * @see EntityTitleLookup::getTitleForId
  *
  * @param EntityId $entityId
  *
  * @return Title|null
  */
 private function getTitleForEntity(EntityId $entityId)
 {
     $title = $this->contentFactory->getTitleForId($entityId);
     return $title;
 }
 /**
  * @dataProvider contentModelsProvider
  */
 public function testGetEntityContentModels(array $contentModelIds)
 {
     $factory = new EntityContentFactory($contentModelIds);
     $this->assertEquals(array_values($contentModelIds), array_values($factory->getEntityContentModels()));
 }