コード例 #1
0
 public function testAddAutoSummaryArgs()
 {
     $summary = new Summary('summarytest');
     $summary->addAutoSummaryArgs("one");
     $summary->addAutoSummaryArgs(2, new ItemId('Q3'));
     $summary->addAutoSummaryArgs(array("four", "five"));
     $expected = array('one', 2, new ItemId('Q3'), 'four', 'five');
     $this->assertEquals($expected, $summary->getAutoSummaryArgs());
 }
コード例 #2
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);
     }
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 /**
  * @dataProvider provideToStringArgs
  */
 public function testToStringArgHandling(array $commentArgs, array $summaryArgs, $expected)
 {
     $summary = new Summary('foobar');
     $summary->addAutoCommentArgs($commentArgs);
     $summary->addAutoSummaryArgs($summaryArgs);
     $formatter = $this->newFormatter();
     $this->assertEquals($expected, $formatter->formatSummary($summary));
 }
コード例 #5
0
 /**
  * @see SpecialWikibasePage::execute
  *
  * @since 0.1
  *
  * @param string|null $subPage
  */
 public function execute($subPage)
 {
     parent::execute($subPage);
     $this->checkPermissions();
     $this->checkBlocked();
     $this->checkReadOnly();
     $this->parts = $subPage === '' ? array() : explode('/', $subPage);
     $this->prepareArguments();
     $out = $this->getOutput();
     $uiLanguageCode = $this->getLanguage()->getCode();
     if ($this->getRequest()->wasPosted() && $this->getUser()->matchEditToken($this->getRequest()->getVal('wpEditToken'))) {
         if ($this->hasSufficientArguments()) {
             $entity = $this->createEntity();
             $status = $this->modifyEntity($entity);
             if ($status->isGood()) {
                 $summary = new Summary('wbeditentity', 'create');
                 $summary->setLanguage($uiLanguageCode);
                 $summary->addAutoSummaryArgs($this->label, $this->description);
                 $status = $this->saveEntity($entity, $summary, $this->getRequest()->getVal('wpEditToken'), EDIT_NEW);
                 $out = $this->getOutput();
                 if (!$status->isOK()) {
                     $out->addHTML('<div class="error">');
                     $out->addWikiText($status->getWikiText());
                     $out->addHTML('</div>');
                 } elseif ($entity !== null) {
                     $title = $this->getEntityTitle($entity->getId());
                     $entityUrl = $title->getFullUrl();
                     $this->getOutput()->redirect($entityUrl);
                 }
             } else {
                 $out->addHTML('<div class="error">');
                 $out->addHTML($status->getHTML());
                 $out->addHTML('</div>');
             }
         }
     }
     $this->getOutput()->addModuleStyles(array('wikibase.special'));
     foreach ($this->getWarnings() as $warning) {
         $out->addHTML(Html::element('div', array('class' => 'warning'), $warning));
     }
     $this->createForm($this->getLegend(), $this->additionalFormElements());
 }
コード例 #6
0
 /**
  * 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);
 }
コード例 #7
0
 /**
  * @return Summary
  */
 private function getSummaryForLabelDescriptionAliases()
 {
     // FIXME: Introduce more specific messages if only 2 of the 3 fields changed.
     $summary = new Summary('wbsetlabeldescriptionaliases');
     $summary->addAutoSummaryArgs($this->label, $this->description, $this->aliases);
     $summary->setLanguage($this->languageCode);
     return $summary;
 }