Handler for editing activity, providing a unified interface for saving modified entities while performing permission checks and handling edit conflicts.
More...
|
| __construct (EntityTitleStoreLookup $titleLookup, EntityRevisionLookup $entityLookup, EntityStore $entityStore, EntityPermissionChecker $permissionChecker, EntityDiffer $entityDiffer, EntityPatcher $entityPatcher, ?EntityId $entityId, IContextSource $context, EditFilterHookRunner $editFilterHookRunner, UserOptionsLookup $userOptionsLookup, TempUserCreator $tempUserCreator, int $maxSerializedEntitySize, array $localEntityTypes, int $baseRevId=0, bool $allowMasterConnection=true) |
|
| getEntityId () |
| Returns the ID of the entity being edited.
|
|
| getLatestRevision () |
| Returns the latest revision of the entity.
|
|
| getBaseRevision () |
| Return the base revision for the edit.
|
|
| getStatus () |
| Get the status object.
|
|
| isSuccess () |
| Determines whether the last call to attemptSave was successful.
|
|
| hasError ( $errorType=EditEntity::ANY_ERROR) |
| Checks whether this EditEntity encountered any of the given error types while executing attemptSave().
|
|
| hasEditConflict () |
| Determines whether an edit conflict exists, that is, whether another user has edited the same item after the base revision was created.
|
|
| isTokenOK ( $token) |
| Make sure the given WebRequest contains a valid edit token.
|
|
| attemptSave (EntityDocument $newEntity, string $summary, $flags, $token, $watch=null, array $tags=[]) |
| Attempts to save the given Entity object.
|
|
|
const | PERMISSION_ERROR = 1 |
| indicates a permission error
|
|
const | EDIT_CONFLICT_ERROR = 2 |
| indicates an unresolved edit conflict
|
|
const | TOKEN_ERROR = 4 |
| indicates a token or session error
|
|
const | SAVE_ERROR = 8 |
| indicates that an error occurred while saving
|
|
const | PRECONDITION_FAILED_ERROR = 16 |
| Indicates that the content failed some precondition to saving, such as a global uniqueness constraint.
|
|
const | FILTERED_ERROR = 32 |
| Indicates that the content triggered an edit filter that uses the EditFilterMergedContent hook to supervise edits.
|
|
const | RATE_LIMIT_ERROR = 64 |
| Indicates that the edit exceeded a rate limit.
|
|
const | ANY_ERROR = 0xFFFFFFFF |
| bit mask for asking for any error.
|
|
Handler for editing activity, providing a unified interface for saving modified entities while performing permission checks and handling edit conflicts.
- Copyright
- GPL-2.0-or-later
- Author
- John Erling Blad < jebla.nosp@m.d@gm.nosp@m.ail.c.nosp@m.om >
-
Daniel Kinzler
-
Thiemo Kreuz
◆ __construct()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::__construct |
( |
EntityTitleStoreLookup | $titleLookup, |
|
|
EntityRevisionLookup | $entityLookup, |
|
|
EntityStore | $entityStore, |
|
|
EntityPermissionChecker | $permissionChecker, |
|
|
EntityDiffer | $entityDiffer, |
|
|
EntityPatcher | $entityPatcher, |
|
|
?EntityId | $entityId, |
|
|
IContextSource | $context, |
|
|
EditFilterHookRunner | $editFilterHookRunner, |
|
|
UserOptionsLookup | $userOptionsLookup, |
|
|
TempUserCreator | $tempUserCreator, |
|
|
int | $maxSerializedEntitySize, |
|
|
array | $localEntityTypes, |
|
|
int | $baseRevId = 0, |
|
|
bool | $allowMasterConnection = true ) |
- Parameters
-
EntityTitleStoreLookup | $titleLookup | |
EntityRevisionLookup | $entityLookup | |
EntityStore | $entityStore | |
EntityPermissionChecker | $permissionChecker | |
EntityDiffer | $entityDiffer | |
EntityPatcher | $entityPatcher | |
EntityId | null | $entityId | the ID of the entity being edited. May be null when creating a new entity. |
IContextSource | $context | the request context for the edit |
EditFilterHookRunner | $editFilterHookRunner | |
UserOptionsLookup | $userOptionsLookup | |
TempUserCreator | $tempUserCreator | |
int | $maxSerializedEntitySize | the maximal allowed entity size in Kilobytes |
string[] | $localEntityTypes | |
int | $baseRevId | the base revision ID for conflict checking. Use 0 to indicate that the current revision should be used as the base revision, effectively disabling conflict detections. Note that the behavior of this class changed so that "late" conflicts that arise between edit conflict detection and database update are always detected, and result in the update to fail. |
bool | $allowMasterConnection | |
◆ attemptSave()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::attemptSave |
( |
EntityDocument | $newEntity, |
|
|
string | $summary, |
|
|
| $flags, |
|
|
| $token, |
|
|
| $watch = null, |
|
|
array | $tags = [] ) |
Attempts to save the given Entity object.
This method performs entity level permission checks, checks the edit token, enforces rate limits, resolves edit conflicts, and updates user watchlists if appropriate.
Success or failure are reported via the Status object returned by this method.
- Todo
- $flags here should ideally not refer to EDIT_ constants from mediawiki core.
- Parameters
-
EntityDocument | $newEntity | |
string | $summary | The edit summary. |
int | $flags | The EDIT_XXX flags as used by WikiPage::doUserEditContent(). Additionally, the EntityContent::EDIT_XXX constants can be used. |
string | bool | $token | Edit token to check, or false to disable the token check. Null will fail the token text, as will the empty string. |
bool | null | $watch | Whether the user wants to watch the entity. Set to null to apply default according to getWatchDefault(). |
string[] | $tags | Change tags to add to the edit. Callers are responsible for checking that the user is permitted to add these tags (typically using ChangeTags::canAddTagsAccompanyingChange ). |
- Returns
- EditEntityStatus
- Exceptions
-
- See also
- WikiPage::doUserEditContent
-
EntityStore::saveEntity
Implements Wikibase\Repo\EditEntity\EditEntity.
◆ checkEditFilter()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::checkEditFilter |
( |
EntityDocument | $newEntity, |
|
|
string | $summary ) |
|
private |
◆ checkEditPermissions()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::checkEditPermissions |
( |
EntityDocument | $newEntity | ) |
|
|
private |
Checks the necessary permissions to perform this edit.
The 'edit' permission is always checked (currently not configurable).
◆ checkEntityId()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::checkEntityId |
( |
EntityId | $id = null | ) |
|
|
private |
◆ checkLocal()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::checkLocal |
( |
EntityDocument | $entity | ) |
|
|
private |
Modifies $this->status and $this->errorType.
Does not throw.
◆ checkRateLimits()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::checkRateLimits |
( |
| ) |
|
|
private |
Checks if rate limits have been exceeded.
◆ checkReadOnly()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::checkReadOnly |
( |
EntityDocument | $entity | ) |
|
|
private |
◆ createTempUserIfNeeded()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::createTempUserIfNeeded |
( |
| ) |
|
|
private |
If a temp user ought to be created then create and return it, and update $this->user and $this->context.
Also update $this->status with any potential error. Returns null (and leaves $this->user unmodified, i.e. nonnull) if no temp user is needed.
◆ entityTypeIsLocal()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::entityTypeIsLocal |
( |
EntityDocument | $entity | ) |
|
|
private |
◆ entityTypeIsReadOnly()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::entityTypeIsReadOnly |
( |
EntityDocument | $entity | ) |
|
|
private |
◆ fixEditConflict()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::fixEditConflict |
( |
EntityDocument | $newEntity | ) |
|
|
private |
Attempts to fix an edit conflict by patching the intended change into the latest revision after checking for conflicts.
- Parameters
-
- Returns
- null|EntityDocument The patched Entity, or null if patching failed.
◆ getBaseRevision()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::getBaseRevision |
( |
| ) |
|
Return the base revision for the edit.
If no base revision ID was supplied to the constructor, this returns the latest revision. If the entity does not exist yet, this returns null.
- Returns
- EntityRevision|null
- Exceptions
-
RevisionedUnresolvedRedirectException | |
StorageException | |
Implements Wikibase\Repo\EditEntity\EditEntity.
◆ getBaseRevisionId()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::getBaseRevisionId |
( |
| ) |
|
|
private |
Return the ID of the base revision for the edit.
If no base revision ID was supplied to the constructor, this returns the ID of the latest revision. If the entity does not exist yet, this returns 0.
◆ getDesiredWatchState()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::getDesiredWatchState |
( |
?bool | $watch | ) |
|
|
private |
Resolve user specific default default for watch state, if $watch is null.
◆ getEntityId()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::getEntityId |
( |
| ) |
|
◆ getLatestRevision()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::getLatestRevision |
( |
| ) |
|
◆ getLatestRevisionId()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::getLatestRevisionId |
( |
| ) |
|
|
private |
- Returns
- int 0 if the entity doesn't exist
◆ getReplicaMode()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::getReplicaMode |
( |
| ) |
|
|
private |
◆ getStatus()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::getStatus |
( |
| ) |
|
◆ getTitle()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::getTitle |
( |
| ) |
|
|
private |
Returns the Title of the page holding the entity that is being edited.
◆ getWatchDefault()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::getWatchDefault |
( |
| ) |
|
|
private |
Returns whether the present edit would, per default, lead to the user watching the page.
This uses the user's watchdefault and watchcreations settings and considers whether the entity is already watched by the user.
- Note
- Keep in sync with logic in \MediaWiki\EditPage\EditPage!
◆ hasEditConflict()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::hasEditConflict |
( |
| ) |
|
Determines whether an edit conflict exists, that is, whether another user has edited the same item after the base revision was created.
In other words, this method checks whether the base revision (as provided to the constructor) is still current. If no base revision was provided to the constructor, this will always return false.
If the base revision is different from the current revision, this will return true even if the edit conflict is resolvable. Indeed, it is used to determine whether conflict resolution should be attempted.
Implements Wikibase\Repo\EditEntity\EditEntity.
◆ hasError()
Checks whether this EditEntity encountered any of the given error types while executing attemptSave().
- Parameters
-
int | $errorType | bit field using the EditEntity::XXX_ERROR constants. Defaults to EditEntity::ANY_ERROR. |
- Returns
- bool true if this EditEntity encountered any of the error types in $errorType, false otherwise.
Implements Wikibase\Repo\EditEntity\EditEntity.
◆ isNew()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::isNew |
( |
| ) |
|
|
private |
◆ isNewPage()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::isNewPage |
( |
| ) |
|
|
private |
Does this entity belong to a new page? (An entity may be new
, and yet not belong to a new page, e.g.
if it is stored in a non-main slot.)
◆ isSuccess()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::isSuccess |
( |
| ) |
|
◆ isTokenOK()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::isTokenOK |
( |
| $token | ) |
|
Make sure the given WebRequest contains a valid edit token.
- Parameters
-
string | $token | The token to check. |
- Returns
- bool true if the token is valid
Implements Wikibase\Repo\EditEntity\EditEntity.
◆ updateWatchlist()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::updateWatchlist |
( |
bool | $watch | ) |
|
|
private |
Watches or unwatches the entity.
- Note
- Keep in sync with logic in \MediaWiki\EditPage\EditPage!
- Todo
- move to separate service
- Parameters
-
bool | $watch | whether to watch or unwatch the page. |
◆ userWasLastToEdit()
Wikibase\Repo\EditEntity\MediaWikiEditEntity::userWasLastToEdit |
( |
User | $user = null, |
|
|
EntityId | $entityId = null, |
|
|
| $lastRevId = false ) |
|
private |
Check if no edits were made by other users since the given revision.
This makes the assumption that revision ids are monotonically increasing.
- Parameters
-
User | null | $user | |
EntityId | null | $entityId | |
int | bool | $lastRevId | |
- Returns
- bool
◆ $allowMasterConnection
bool Wikibase\Repo\EditEntity\MediaWikiEditEntity::$allowMasterConnection |
|
private |
◆ $baseRev
EntityRevision Wikibase\Repo\EditEntity\MediaWikiEditEntity::$baseRev = null |
|
private |
◆ $baseRevId
Wikibase\Repo\EditEntity\MediaWikiEditEntity::$baseRevId |
|
private |
◆ $context
IContextSource Wikibase\Repo\EditEntity\MediaWikiEditEntity::$context |
|
private |
◆ $editFilterHookRunner
◆ $entityDiffer
EntityDiffer Wikibase\Repo\EditEntity\MediaWikiEditEntity::$entityDiffer |
|
private |
◆ $entityId
EntityId Wikibase\Repo\EditEntity\MediaWikiEditEntity::$entityId |
|
private |
The ID of the entity to edit.
May be null if a new entity is being created.
◆ $entityPatcher
EntityPatcher Wikibase\Repo\EditEntity\MediaWikiEditEntity::$entityPatcher |
|
private |
◆ $entityRevisionLookup
◆ $entityStore
EntityStore Wikibase\Repo\EditEntity\MediaWikiEditEntity::$entityStore |
|
private |
◆ $errorType
int Wikibase\Repo\EditEntity\MediaWikiEditEntity::$errorType = 0 |
|
private |
◆ $latestRev
EntityRevision Wikibase\Repo\EditEntity\MediaWikiEditEntity::$latestRev = null |
|
private |
◆ $latestRevId
int Wikibase\Repo\EditEntity\MediaWikiEditEntity::$latestRevId = 0 |
|
private |
◆ $localEntityTypes
array Wikibase\Repo\EditEntity\MediaWikiEditEntity::$localEntityTypes |
|
private |
◆ $maxSerializedEntitySize
int Wikibase\Repo\EditEntity\MediaWikiEditEntity::$maxSerializedEntitySize |
|
private |
◆ $permissionChecker
◆ $status
◆ $tempUserCreator
TempUserCreator Wikibase\Repo\EditEntity\MediaWikiEditEntity::$tempUserCreator |
|
private |
◆ $title
Title Wikibase\Repo\EditEntity\MediaWikiEditEntity::$title = null |
|
private |
◆ $titleLookup
◆ $user
User Wikibase\Repo\EditEntity\MediaWikiEditEntity::$user |
|
private |
◆ $userOptionsLookup
UserOptionsLookup Wikibase\Repo\EditEntity\MediaWikiEditEntity::$userOptionsLookup |
|
private |
The documentation for this class was generated from the following file: