/**
  * Returns the page updates implied by the given the change.
  *
  * @param EntityChange $change
  *
  * @return Traversable of PageEntityUsages
  */
 private function getAffectedPages(EntityChange $change)
 {
     $entityId = $change->getEntityId();
     $changedAspects = $this->getChangedAspects($change);
     $usages = $this->usageLookup->getPagesUsing(array($entityId), array_merge($changedAspects, array(EntityUsage::ALL_USAGE)));
     // @todo: use iterators throughout!
     $usages = iterator_to_array($usages, true);
     $usages = $this->transformAllPageEntityUsages($usages, $entityId, $changedAspects);
     if ($change instanceof ItemChange && in_array(EntityUsage::TITLE_USAGE, $changedAspects)) {
         $siteLinkDiff = $change->getSiteLinkDiff();
         $namesFromDiff = $this->getPagesReferencedInDiff($siteLinkDiff);
         $titlesFromDiff = $this->getTitlesFromTexts($namesFromDiff);
         $usagesFromDiff = $this->makeVirtualUsages($titlesFromDiff, $entityId, array(EntityUsage::SITELINK_USAGE));
         //FIXME: we can't really merge if $usages is an iterator, not an array.
         //TODO: Inject $usagesFromDiff "on the fly" while streaming other usages.
         //NOTE: $usages must pass through mergeUsagesInto for re-indexing
         $mergedUsages = array();
         $this->mergeUsagesInto($usages, $mergedUsages);
         $this->mergeUsagesInto($usagesFromDiff, $mergedUsages);
         $usages = $mergedUsages;
     }
     return new ArrayIterator($usages);
 }
 /**
  * Returns a human readable comment representing the change.
  *
  * @since 0.4
  *
  * @param EntityChange $change the change to get a comment for
  * @param Title|null $target The page we create an edit summary for. Needed to create an article
  *         specific edit summary on site link changes. Ignored otherwise.
  *
  * @throws MWException
  * @return string
  */
 private function getEditComment(EntityChange $change, Title $target = null)
 {
     $siteLinkDiff = $change instanceof ItemChange ? $change->getSiteLinkDiff() : null;
     $editComment = '';
     if ($siteLinkDiff !== null && !$siteLinkDiff->isEmpty()) {
         $action = $change->getAction();
         $siteLinkComment = $this->siteLinkCommentCreator->getEditComment($siteLinkDiff, $action, $target);
         $editComment = $siteLinkComment === null ? '' : $siteLinkComment;
     }
     if ($editComment === '') {
         $editComment = $change->getComment();
     }
     if ($editComment === '') {
         // If there is no comment, use something generic. This shouldn't happen.
         wfWarn('Failed to find edit comment for EntityChange');
         $editComment = $this->msg('wikibase-comment-update')->text();
     }
     Assert::postcondition(is_string($editComment), '$editComment must be a string');
     return $editComment;
 }
 private static function applyDefaults(EntityChange $change, array $defaults)
 {
     foreach ($defaults as $name => $value) {
         if (!$change->hasField($name)) {
             $change->setField($name, $value);
         }
     }
 }
 private function combineChanges(EntityChange $first, EntityChange $last)
 {
     $firstmeta = $first->getMetadata();
     $lastmeta = $last->getMetadata();
     return $this->makeChange(array('id' => null, 'type' => $first->getField('type'), 'time' => $last->getField('time'), 'object_id' => $last->getField('object_id'), 'revision_id' => $last->getField('revision_id'), 'user_id' => $last->getField('user_id'), 'info' => array('metadata' => array('bot' => 0, 'comment' => $lastmeta['comment'], 'parent_id' => $firstmeta['parent_id']))));
 }
 public function testGivenNonStatementSerialization_objectifyArraysReturnsOriginal()
 {
     $data = array('foo');
     $change = new EntityChange();
     $this->assertSame($data, $change->objectifyArrays($data));
 }