/** * @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()); }
/** * Format the given summary * * @since 0.5 * * @param Summary $summary * * @return string to be used for the summary */ public function formatSummary(Summary $summary) { $userSummary = $summary->getUserSummary(); return $this->assembleSummaryString($this->formatAutoComment($summary), $this->formatAutoSummary($summary), $userSummary === null ? '' : $userSummary); }
/** * @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)); }
/** * @param string $direction either 'from' or 'to' * @param ItemId $getId * @param string|null $customSummary * * @return Summary */ private function getSummary($direction, $getId, $customSummary = null) { $summary = new Summary('wbmergeitems', $direction, null, array($getId->getSerialization())); if ($customSummary !== null) { $summary->setUserSummary($customSummary); } return $summary; }
/** * @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()); }
/** * 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); }
/** * Create a new Summary instance suitable for representing the action performed by this module. * * @param array $params * * @return Summary */ protected function createSummary(array $params) { $summary = new Summary($this->getModuleName()); $summary->setUserSummary($params['summary']); return $summary; }
/** * 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; }
/** * Creates a new Summary instance suitable for representing the action performed by this module. * * @param array $params * @param ApiBase $module * * @return Summary */ public function createSummary(array $params, ApiBase $module) { $summary = new Summary($module->getModuleName()); if (isset($params['summary'])) { $summary->setUserSummary($params['summary']); } return $summary; }
/** * Create a redirect at $fromId pointing to $toId. * * @param EntityId $fromId The ID of the entity to be replaced by the redirect. The entity * must exist and be empty (or be a redirect already). * @param EntityId $toId The ID of the entity the redirect should point to. The Entity must * exist and must not be a redirect. * @param bool $bot Whether the edit should be marked as bot * * @return EntityRedirect * * @throws RedirectCreationException If creating the redirect fails. Calling code may use * RedirectCreationException::getErrorCode() to get further information about the cause of * the failure. An explanation of the error codes can be obtained from getErrorCodeInfo(). */ public function createRedirect(EntityId $fromId, EntityId $toId, $bot) { $this->checkCompatible($fromId, $toId); $this->checkPermissions($fromId); $this->checkExistsNoRedirect($toId); $this->checkEmpty($fromId); $summary = new Summary('wbcreateredirect'); $summary->addAutoCommentArgs($fromId->getSerialization(), $toId->getSerialization()); $redirect = new EntityRedirect($fromId, $toId); $this->saveRedirect($redirect, $summary, $bot); return $redirect; }
/** * @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; }