/**
  * Generates and returns an HTML visualization of the provided redirect Diff.
  *
  * @since 0.5
  *
  * @param Diff $diff
  *
  * @return string
  */
 protected function visualizeRedirectDiff(Diff $diff)
 {
     if ($diff->isEmpty()) {
         return '';
     }
     //TODO: localize path (keys in the diff array)
     $linkDiffVisualizer = new DiffView(array(), $diff, $this->siteStore, $this->entityIdFormatter, $this->context);
     $html = $linkDiffVisualizer->getHtml();
     return $html;
 }
Beispiel #2
0
 public function testEmptyElementsInRecursiveDiff()
 {
     $old = array('en' => array('a' => 'en-foo', 'b' => 'en-bar'));
     $new = array('en' => array('a' => 'en-foo', 'b' => 'en-bar'));
     $differ = new MapDiffer(true);
     $diff = new Diff($differ->doDiff($old, $new));
     $this->assertTrue($diff->isEmpty());
     $this->assertTrue($diff->getOperations() === array());
 }
Beispiel #3
0
 /**
  * @dataProvider instanceProvider
  *
  * @since 0.6
  *
  * @param Diff $list
  */
 public function testUnset(Diff $list)
 {
     if ($list->isEmpty()) {
         $this->assertTrue(true);
         // We cannot test unset if there are no elements
     } else {
         $offset = $list->getIterator()->key();
         $count = $list->count();
         $list->offsetUnset($offset);
         $this->assertEquals($count - 1, $list->count());
     }
     if (!$list->isEmpty()) {
         $offset = $list->getIterator()->key();
         $count = $list->count();
         unset($list[$offset]);
         $this->assertEquals($count - 1, $list->count());
     }
 }
 /**
  * @param Diff $redirectPatch
  *
  * @return EntityRedirect|null
  */
 private function getPatchedRedirect(Diff $redirectPatch)
 {
     // See getRedirectData() for the structure of the data array.
     $redirData = $this->getRedirectData();
     if (!$redirectPatch->isEmpty()) {
         $patcher = new MapPatcher();
         $redirData = $patcher->patch($redirData, $redirectPatch);
     }
     if (isset($redirData['redirect'])) {
         /* @var EntityHandler $handler */
         $handler = $this->getContentHandler();
         $entityId = $this->getEntityId();
         $targetId = $handler->makeEntityId($redirData['redirect']);
         return new EntityRedirect($entityId, $targetId);
     } else {
         return null;
     }
 }
 /**
  * Returns an array structure suitable for building an edit summary for the respective
  * change to site links.
  *
  * @param string $action e.g. 'remove', see the constants in EntityChange
  * @param Diff $siteLinkDiff The change's site link diff
  * @param Title|null $title The page we create an edit summary for
  *
  * @return array|null
  */
 private function getSiteLinkMessage($action, Diff $siteLinkDiff, Title $title = null)
 {
     if ($siteLinkDiff->isEmpty()) {
         return null;
     }
     //TODO: Implement comments specific to the affected page.
     //       Different pages may be affected in different ways by the same change.
     //       Also, merged changes may affect the same page in multiple ways.
     $diffOps = $siteLinkDiff->getOperations();
     $siteId = $this->siteId;
     // change involved site link to client wiki
     if (array_key_exists($siteId, $diffOps)) {
         // $siteLinkDiff changed from containing atomic diffs to
         // containing map diffs. For B/C, handle both cases.
         $diffOp = $diffOps[$siteId];
         if ($diffOp instanceof Diff) {
             if (array_key_exists('name', $diffOp)) {
                 $diffOp = $diffOp['name'];
             } else {
                 // change to badges only, use original message
                 return null;
             }
         }
         $params = $this->getSiteLinkAddRemoveParams($diffOp, $action, $siteId, $title);
     } else {
         $diffOpCount = count($diffOps);
         if ($diffOpCount === 1) {
             $params = $this->getSiteLinkChangeParams($diffOps);
         } else {
             // multiple changes, use original message
             return null;
         }
     }
     return $params;
 }