Wikibase
MediaWiki Wikibase extension
|
Helper class for api modules to save entities. More...
Public Member Functions | |
__construct (bool $isWriteMode, $needsToken, RevisionLookup $revisionLookup, TitleFactory $titleFactory, EntityIdParser $idParser, EntityRevisionLookup $entityRevisionLookup, EntityTitleStoreLookup $entityTitleStoreLookup, ApiErrorReporter $errorReporter, SummaryFormatter $summaryFormatter, MediaWikiEditEntityFactory $editEntityFactory, PermissionManager $permissionManager) | |
getBaseRevisionId () | |
getSaveFlags () | |
getEntityFactory () | |
setEntityFactory (EntityFactory $entityFactory) | |
getEntityStore () | |
setEntityStore (EntityStore $entityStore) | |
loadEntity (array $requestParams, ?EntityId $entityId=null, $assignFreshId=self::ASSIGN_FRESH_ID) | |
attemptSaveEntity (EntityDocument $entity, $summary, array $requestParams, IContextSource $context, int $flags=0) | |
Attempts to save the new entity content, while first checking for permissions, edit conflicts, etc. | |
Public Member Functions inherited from Wikibase\Repo\Api\EntityLoadingHelper | |
__construct (RevisionLookup $revisionLookup, TitleFactory $titleFactory, EntityIdParser $idParser, EntityRevisionLookup $entityRevisionLookup, EntityTitleStoreLookup $entityTitleStoreLookup, ApiErrorReporter $errorReporter) | |
getEntityIdParam () | |
Returns the name of the request parameter expected to contain the ID of the entity to load. | |
setEntityIdParam ( $entityIdParam) | |
Sets the name of the request parameter expected to contain the ID of the entity to load. | |
setEntityByLinkedTitleLookup (EntityByLinkedTitleLookup $lookup) | |
getDefaultRetrievalMode () | |
setDefaultRetrievalMode ( $defaultRetrievalMode) | |
loadEntity (array $requestParams, ?EntityId $entityId=null) | |
getEntityIdFromParams (array $params) | |
Public Attributes | |
const | ASSIGN_FRESH_ID = 'assignFreshId' |
const | NO_FRESH_ID = 'noFreshId' |
Private Member Functions | |
isEntityCreationSupported () | |
createEntity (?string $entityType, ?EntityId $customId, string $assignFreshId) | |
Create an empty entity. | |
evaluateTokenParam (array $params) | |
handleSaveStatus (EditEntityStatus $status) | |
Signal errors and warnings from a save operation to the API call's output. | |
handleStatus (Status $status, $errorCode) | |
Include messages from a Status object in the API call's output. | |
Private Attributes | |
$summaryFormatter | |
$editEntityFactory | |
$permissionManager | |
$entitySavingFlags = 0 | |
$entityId = null | |
$baseRevisionId = 0 | |
$entityFactory = null | |
$entityStore = null | |
$isApiModuleWriteMode = false | |
$apiModuleNeedsToken = false | |
Additional Inherited Members | |
Protected Member Functions inherited from Wikibase\Repo\Api\EntityLoadingHelper | |
loadEntityRevision (EntityId $entityId, $revId=0, $mode=null) | |
Load the entity content of the given revision. | |
Protected Attributes inherited from Wikibase\Repo\Api\EntityLoadingHelper | |
$revisionLookup | |
$titleFactory | |
$entityRevisionLookup | |
$entityTitleStoreLookup | |
$errorReporter | |
$defaultRetrievalMode = LookupConstants::LATEST_FROM_REPLICA | |
Helper class for api modules to save entities.
Wikibase\Repo\Api\EntitySavingHelper::__construct | ( | bool | $isWriteMode, |
$needsToken, | |||
RevisionLookup | $revisionLookup, | ||
TitleFactory | $titleFactory, | ||
EntityIdParser | $idParser, | ||
EntityRevisionLookup | $entityRevisionLookup, | ||
EntityTitleStoreLookup | $entityTitleStoreLookup, | ||
ApiErrorReporter | $errorReporter, | ||
SummaryFormatter | $summaryFormatter, | ||
MediaWikiEditEntityFactory | $editEntityFactory, | ||
PermissionManager | $permissionManager ) |
Wikibase\Repo\Api\EntitySavingHelper::attemptSaveEntity | ( | EntityDocument | $entity, |
$summary, | |||
array | $requestParams, | ||
IContextSource | $context, | ||
int | $flags = 0 ) |
Attempts to save the new entity content, while first checking for permissions, edit conflicts, etc.
Saving is done via EditEntityHandler::attemptSave().
This method automatically takes into account several parameters:
If an error occurs, it is automatically reported and execution of the API module is terminated using the ApiErrorReporter (via handleStatus()). If there were any warnings, they will automatically be included in the API call's output (again, via handleStatus()).
EntityDocument | $entity | The entity to save |
string | FormatableSummary | $summary | The edit summary |
array | $requestParams | |
IContextSource | $context | |
int | $flags | The edit flags (see WikiPage::doEditContent) |
LogicException | if not in write mode |
|
private |
Create an empty entity.
string | null | $entityType | The type of entity to create. Optional if an ID is given. |
EntityId | null | $customId | Optionally assigns a specific ID instead of generating a new one. |
string | $assignFreshId | Either of the ASSIGN_FRESH_ID/NO_FRESH_ID constants NOTE: We usually need to assign an ID early, for things like the ClaimIdGenerator. |
InvalidArgumentException | when entity type and ID are given but do not match. |
ApiUsageException | |
LogicException |
|
private |
array | $params |
Wikibase\Repo\Api\EntitySavingHelper::getBaseRevisionId | ( | ) |
Wikibase\Repo\Api\EntitySavingHelper::getEntityFactory | ( | ) |
Wikibase\Repo\Api\EntitySavingHelper::getEntityStore | ( | ) |
Wikibase\Repo\Api\EntitySavingHelper::getSaveFlags | ( | ) |
|
private |
Signal errors and warnings from a save operation to the API call's output.
This is much like handleStatus(), but specialized for Status objects returned by EditEntityHandler::attemptSave(). In particular, the 'errorFlags' field from the status value is used to determine the error code to return to the caller.
EditEntityStatus | $status | The status to report |
|
private |
Include messages from a Status object in the API call's output.
An ApiErrorHandler is used to report the status, if necessary. If $status->isOK() is false, this method will terminate with an ApiUsageException.
Status | $status | The status to report |
string | null | $errorCode | The API error code to use in case $status->isOK() returns false |
ApiUsageException | If $status->isOK() returns false. |
|
private |
Wikibase\Repo\Api\EntitySavingHelper::loadEntity | ( | array | $requestParams, |
?EntityId | $entityId = null, | ||
$assignFreshId = self::ASSIGN_FRESH_ID ) |
array | $requestParams | |
EntityId | null | $entityId | ID of the entity to load. If not given, the ID is taken from the request parameters. If $entityId is given, the 'baserevid' parameter must belong to it. |
string | $assignFreshId | Whether to allow assigning entity ids to new entities. Either of the ASSIGN_FRESH_ID/NO_FRESH_ID constants. NOTE: We usually need to assign an ID early, for things like the ClaimIdGenerator. |
ApiUsageException |
Wikibase\Repo\Api\EntitySavingHelper::setEntityFactory | ( | EntityFactory | $entityFactory | ) |
Wikibase\Repo\Api\EntitySavingHelper::setEntityStore | ( | EntityStore | $entityStore | ) |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
const Wikibase\Repo\Api\EntitySavingHelper::ASSIGN_FRESH_ID = 'assignFreshId' |
const Wikibase\Repo\Api\EntitySavingHelper::NO_FRESH_ID = 'noFreshId' |