Пример #1
0
 /**
  * @since 0.4
  *
  * @param Summary|null $summary
  * @param string $action
  * @param string $language
  * @param string|array $args
  *
  * @throws InvalidArgumentException
  */
 protected function updateSummary(Summary $summary = null, $action, $language = '', $args = '')
 {
     if ($summary !== null) {
         $summary->setAction($action);
         $summary->setLanguage($language);
         $summary->addAutoSummaryArgs($args);
     }
 }
 public function testGetMessageKey()
 {
     $summary = new Summary('summarytest');
     $this->assertEquals("summarytest", $summary->getMessageKey());
     $summary->setAction("testing");
     $this->assertEquals("summarytest-testing", $summary->getMessageKey());
     $summary->setModuleName("");
     $this->assertEquals("testing", $summary->getMessageKey());
 }
 /**
  * Checks what has actually changed inside a statement by looking at a ClaimDifference,
  * constructs an edit-summary based upon that information and returns
  * a Summary object holding this edit-summary
  *
  * @param Statement|null $oldStatement
  * @param Statement $newStatement
  *
  * @return Summary
  */
 public function buildClaimSummary(Statement $oldStatement = null, Statement $newStatement)
 {
     $guid = $newStatement->getGuid();
     $summary = new Summary($this->apiModuleName);
     // Only one statement touched, so we're always having singular here.
     $summary->addAutoCommentArgs(1);
     $summaryArgs = $this->buildSummaryArgs($newStatement, $guid);
     $summary->addAutoSummaryArgs($summaryArgs);
     if ($oldStatement !== null) {
         //claim is changed
         $claimDifference = $this->claimDiffer->diffClaims($oldStatement, $newStatement);
         if ($claimDifference->isAtomic()) {
             if ($claimDifference->getMainSnakChange() !== null) {
                 $summary->setAction('update');
             } elseif ($claimDifference->getQualifierChanges()->isEmpty() === false) {
                 $summary->addAutoCommentArgs($claimDifference->getQualifierChanges()->count());
                 $summary->setAction('update-qualifiers');
             } elseif ($claimDifference->getReferenceChanges()->isEmpty() === false) {
                 $summary->addAutoCommentArgs($claimDifference->getReferenceChanges()->count());
                 $summary->setAction('update-references');
             } elseif ($claimDifference->getRankChange() !== null) {
                 $summary->setAction('update-rank');
             } else {
                 // something "else" has changed inside the claim, so falling back to plain update message
                 $summary->setAction('update');
             }
         } else {
             // TODO: decide what to do if changes affect multiple part of the claim
             // e.g. concat several autocomments into one?
             $summary->setAction('update');
         }
     } else {
         //new claim is added
         $summary->setAction('create');
     }
     return $summary;
 }
 /**
  * @dataProvider provideFormatSummary
  */
 public function testFormatSummary($module, $action, $language, $commentArgs, $summaryArgs, $userSummary, $expected)
 {
     $summary = new Summary($module);
     if ($action !== null) {
         $summary->setAction($action);
     }
     if ($language !== null) {
         $summary->setLanguage($language);
     }
     if ($commentArgs) {
         call_user_func_array(array($summary, 'addAutoCommentArgs'), $commentArgs);
     }
     if ($summaryArgs) {
         call_user_func_array(array($summary, 'addAutoSummaryArgs'), $summaryArgs);
     }
     if ($userSummary !== null) {
         $summary->setUserSummary($userSummary);
     }
     $formatter = $this->newFormatter();
     $this->assertEquals($expected, $formatter->formatSummary($summary));
 }
 /**
  * Main method. Does the actual work and sets the result.
  *
  * @since 0.1
  */
 public function execute()
 {
     $lookup = $this->revisionLookup;
     $params = $this->extractRequestParams();
     $this->validateParameters($params);
     // Sites are already tested through allowed params ;)
     $sites = $this->siteLinkTargetProvider->getSiteList($this->siteLinkGroups);
     /** @var Site $fromSite */
     list($fromSite, $fromPage) = $this->getSiteAndNormalizedPageName($sites, $params['fromsite'], $params['fromtitle']);
     /** @var Site $toSite */
     list($toSite, $toPage) = $this->getSiteAndNormalizedPageName($sites, $params['tosite'], $params['totitle']);
     $siteLinkStore = WikibaseRepo::getDefaultInstance()->getStore()->newSiteLinkStore();
     $fromId = $siteLinkStore->getItemIdForLink($fromSite->getGlobalId(), $fromPage);
     $toId = $siteLinkStore->getItemIdForLink($toSite->getGlobalId(), $toPage);
     $siteLinkList = new SiteLinkList();
     $flags = 0;
     $item = null;
     $summary = new Summary($this->getModuleName());
     $summary->addAutoSummaryArgs($fromSite->getGlobalId() . ':' . $fromPage, $toSite->getGlobalId() . ':' . $toPage);
     //FIXME: use ChangeOps for consistency!
     // Figure out which parts to use and what to create anew
     if ($fromId === null && $toId === null) {
         // create new item
         $item = new Item();
         $toLink = new SiteLink($toSite->getGlobalId(), $toPage);
         $item->addSiteLink($toLink);
         $siteLinkList->addSiteLink($toLink);
         $fromLink = new SiteLink($fromSite->getGlobalId(), $fromPage);
         $item->addSiteLink($fromLink);
         $siteLinkList->addSiteLink($fromLink);
         $flags |= EDIT_NEW;
         $summary->setAction('create');
     } elseif ($fromId === null && $toId !== null) {
         // reuse to-site's item
         /** @var Item $item */
         $itemRev = $lookup->getEntityRevision($toId, EntityRevisionLookup::LATEST_FROM_MASTER);
         $item = $itemRev->getEntity();
         $fromLink = new SiteLink($fromSite->getGlobalId(), $fromPage);
         $item->addSiteLink($fromLink);
         $siteLinkList->addSiteLink($fromLink);
         $summary->setAction('connect');
     } elseif ($fromId !== null && $toId === null) {
         // reuse from-site's item
         /** @var Item $item */
         $itemRev = $lookup->getEntityRevision($fromId, EntityRevisionLookup::LATEST_FROM_MASTER);
         $item = $itemRev->getEntity();
         $toLink = new SiteLink($toSite->getGlobalId(), $toPage);
         $item->addSiteLink($toLink);
         $siteLinkList->addSiteLink($toLink);
         $summary->setAction('connect');
     } elseif ($fromId->equals($toId)) {
         // no-op
         $this->errorReporter->dieError('Common item detected, sitelinks are both on the same item', 'common-item');
     } else {
         // dissimilar items
         $this->errorReporter->dieError('No common item detected, unable to link titles', 'no-common-item');
     }
     $this->resultBuilder->addSiteLinkList($siteLinkList, 'entity');
     $status = $this->getAttemptSaveStatus($item, $summary, $flags);
     $this->buildResult($item, $status);
 }