Wikibase
MediaWiki Wikibase extension
Wikibase\Repo\EditEntity\MediawikiEditEntity Class Reference

Handler for editing activity, providing a unified interface for saving modified entities while performing permission checks and handling edit conflicts. More...

+ Inheritance diagram for Wikibase\Repo\EditEntity\MediawikiEditEntity:
+ Collaboration diagram for Wikibase\Repo\EditEntity\MediawikiEditEntity:

Public Member Functions

 __construct (EntityTitleStoreLookup $titleLookup, EntityRevisionLookup $entityLookup, EntityStore $entityStore, EntityPermissionChecker $permissionChecker, EntityDiffer $entityDiffer, EntityPatcher $entityPatcher, ?EntityId $entityId, IContextSource $context, EditFilterHookRunner $editFilterHookRunner, UserOptionsLookup $userOptionsLookup, $maxSerializedEntitySize, array $localEntityTypes, $baseRevId=0, $allowMasterConnection=true)
 
 getEntityId ()
 Returns the ID of the entity being edited. More...
 
 getLatestRevision ()
 Returns the latest revision of the entity. More...
 
 getBaseRevision ()
 Return the base revision for the edit. More...
 
 getStatus ()
 Get the status object. More...
 
 isSuccess ()
 Determines whether the last call to attemptSave was successful. More...
 
 hasError ( $errorType=EditEntity::ANY_ERROR)
 Checks whether this EditEntity encountered any of the given error types while executing attemptSave(). More...
 
 hasEditConflict ()
 Determines whether an edit conflict exists, that is, whether another user has edited the same item after the base revision was created. More...
 
 isTokenOK ( $token)
 Make sure the given WebRequest contains a valid edit token. More...
 
 attemptSave (EntityDocument $newEntity, string $summary, $flags, $token, $watch=null, array $tags=[])
 Attempts to save the given Entity object. More...
 

Private Member Functions

 getTitle ()
 Returns the Title of the page holding the entity that is being edited. More...
 
 getLatestRevisionId ()
 
 isNew ()
 Is the entity new? More...
 
 isNewPage ()
 Does this entity belong to a new page? (An entity may be new, and yet not belong to a new page, e. More...
 
 getBaseRevisionId ()
 Return the ID of the base revision for the edit. More...
 
 getReplicaMode ()
 
 fixEditConflict (EntityDocument $newEntity)
 Attempts to fix an edit conflict by patching the intended change into the latest revision after checking for conflicts. More...
 
 userWasLastToEdit (User $user=null, EntityId $entityId=null, $lastRevId=false)
 Check if no edits were made by other users since the given revision. More...
 
 checkEditPermissions (EntityDocument $newEntity)
 Checks the necessary permissions to perform this edit. More...
 
 checkRateLimits ()
 Checks if rate limits have been exceeded. More...
 
 getDesiredWatchState ( $watch)
 Resolve user specific default default for watch state, if $watch is null. More...
 
 checkEntityId (EntityId $id=null)
 
 checkReadOnly (EntityDocument $entity)
 
 entityTypeIsReadOnly (EntityDocument $entity)
 
 checkLocal (EntityDocument $entity)
 Modifies $this->status and $this->errorType. More...
 
 entityTypeIsLocal (EntityDocument $entity)
 
 getWatchDefault ()
 Returns whether the present edit would, per default, lead to the user watching the page. More...
 
 updateWatchlist ( $watch)
 Watches or unwatches the entity. More...
 

Private Attributes

 $entityRevisionLookup
 
 $titleLookup
 
 $entityStore
 
 $permissionChecker
 
 $entityDiffer
 
 $entityPatcher
 
 $entityId
 
 $baseRev = null
 
 $baseRevId
 
 $latestRev = null
 
 $latestRevId = 0
 
 $status
 
 $context
 
 $user
 
 $title = null
 
 $editFilterHookRunner
 
 $userOptionsLookup
 
 $errorType = 0
 
 $maxSerializedEntitySize
 
 $localEntityTypes
 
 $allowMasterConnection
 

Additional Inherited Members

- Public Attributes inherited from Wikibase\Repo\EditEntity\EditEntity
const PERMISSION_ERROR = 1
 indicates a permission error More...
 
const EDIT_CONFLICT_ERROR = 2
 indicates an unresolved edit conflict More...
 
const TOKEN_ERROR = 4
 indicates a token or session error More...
 
const SAVE_ERROR = 8
 indicates that an error occurred while saving More...
 
const PRECONDITION_FAILED = 16
 Indicates that the content failed some precondition to saving, such as a global uniqueness constraint. More...
 
const FILTERED = 32
 Indicates that the content triggered an edit filter that uses the EditFilterMergedContent hook to supervise edits. More...
 
const RATE_LIMIT = 64
 Indicates that the edit exceeded a rate limit. More...
 
const ANY_ERROR = 0xFFFFFFFF
 bit mask for asking for any error. More...
 

Detailed Description

Handler for editing activity, providing a unified interface for saving modified entities while performing permission checks and handling edit conflicts.

Author
John Erling Blad < jebla.nosp@m.d@gm.nosp@m.ail.c.nosp@m.om >
Daniel Kinzler
Thiemo Kreuz

Constructor & Destructor Documentation

◆ __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,
  $maxSerializedEntitySize,
array  $localEntityTypes,
  $baseRevId = 0,
  $allowMasterConnection = true 
)
Parameters
EntityTitleStoreLookup$titleLookup
EntityRevisionLookup$entityLookup
EntityStore$entityStore
EntityPermissionChecker$permissionChecker
EntityDiffer$entityDiffer
EntityPatcher$entityPatcher
EntityId | null$entityIdthe ID of the entity being edited. May be null when creating a new entity.
IContextSource$contextthe request context for the edit
EditFilterHookRunner$editFilterHookRunner
UserOptionsLookup$userOptionsLookup
int$maxSerializedEntitySizethe maximal allowed entity size in Kilobytes
string[]$localEntityTypes
int$baseRevIdthe 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. true and false will be accepted for backwards compatibility, but both will be treated like 0. 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

Member Function Documentation

◆ 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 toke, 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.

Parameters
EntityDocument$newEntity
string$summaryThe edit summary.
int$flagsThe EDIT_XXX flags as used by WikiPage::doUserEditContent(). Additionally, the EntityContent::EDIT_XXX constants can be used.
string | bool$tokenEdit token to check, or false to disable the token check. Null will fail the token text, as will the empty string.
bool | null$watchWhether the user wants to watch the entity. Set to null to apply default according to getWatchDefault().
string[]$tagsChange 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
Status
Exceptions
MWException
ReadOnlyError
See also
WikiPage::doUserEditContent
EntityStore::saveEntity

Implements Wikibase\Repo\EditEntity\EditEntity.

◆ checkEditPermissions()

Wikibase\Repo\EditEntity\MediawikiEditEntity::checkEditPermissions ( EntityDocument  $newEntity)
private

Checks the necessary permissions to perform this edit.

Per default, the 'edit' permission is checked. Use addRequiredPermission() to check more permissions.

Parameters
EntityDocument$newEntity

◆ checkEntityId()

Wikibase\Repo\EditEntity\MediawikiEditEntity::checkEntityId ( EntityId  $id = null)
private
Parameters
EntityId | null$id
Exceptions
InvalidArgumentException

◆ 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
Parameters
EntityDocument$entity
Exceptions
ReadOnlyError

◆ entityTypeIsLocal()

Wikibase\Repo\EditEntity\MediawikiEditEntity::entityTypeIsLocal ( EntityDocument  $entity)
private

◆ entityTypeIsReadOnly()

Wikibase\Repo\EditEntity\MediawikiEditEntity::entityTypeIsReadOnly ( EntityDocument  $entity)
private
Parameters
EntityDocument$entity
Returns
bool

◆ 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
EntityDocument$newEntity
Exceptions
MWException
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
MWException

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.

Returns
int

◆ getDesiredWatchState()

Wikibase\Repo\EditEntity\MediawikiEditEntity::getDesiredWatchState (   $watch)
private

Resolve user specific default default for watch state, if $watch is null.

Parameters
bool | null$watch
Returns
bool

◆ getEntityId()

Wikibase\Repo\EditEntity\MediawikiEditEntity::getEntityId ( )

Returns the ID of the entity being edited.

May be null if a new entity is to be created.

Returns
null|EntityId

Implements Wikibase\Repo\EditEntity\EditEntity.

◆ getLatestRevision()

Wikibase\Repo\EditEntity\MediawikiEditEntity::getLatestRevision ( )

Returns the latest revision of the entity.

Returns
EntityRevision|null

Implements Wikibase\Repo\EditEntity\EditEntity.

◆ getLatestRevisionId()

Wikibase\Repo\EditEntity\MediawikiEditEntity::getLatestRevisionId ( )
private
Returns
int 0 if the entity doesn't exist

◆ getReplicaMode()

Wikibase\Repo\EditEntity\MediawikiEditEntity::getReplicaMode ( )
private
Returns
string

◆ getStatus()

Wikibase\Repo\EditEntity\MediawikiEditEntity::getStatus ( )

Get the status object.

Only defined after attemptSave() was called.

After a successful save, the Status object's value field will contain an array, just like the status returned by WikiPage::doUserEditContent(). Well known fields in the status value are:

  • new: bool whether the edit created a new page
  • revision: Revision the new revision object
  • errorFlags: bit field indicating errors, see the XXX_ERROR constants.
Returns
Status

Implements Wikibase\Repo\EditEntity\EditEntity.

◆ getTitle()

Wikibase\Repo\EditEntity\MediawikiEditEntity::getTitle ( )
private

Returns the Title of the page holding the entity that is being edited.

Returns
Title|null

◆ 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 EditPage!
Returns
bool

◆ 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.

Returns
bool

Implements Wikibase\Repo\EditEntity\EditEntity.

◆ hasError()

Wikibase\Repo\EditEntity\MediawikiEditEntity::hasError (   $errorType = EditEntity::ANY_ERROR)

Checks whether this EditEntity encountered any of the given error types while executing attemptSave().

Parameters
int$errorTypebit 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

Is the entity new?

Returns
bool

◆ 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.)

Returns
bool

◆ isSuccess()

Wikibase\Repo\EditEntity\MediawikiEditEntity::isSuccess ( )

Determines whether the last call to attemptSave was successful.

Returns
bool false if attemptSave() failed, true otherwise

Implements Wikibase\Repo\EditEntity\EditEntity.

◆ isTokenOK()

Wikibase\Repo\EditEntity\MediawikiEditEntity::isTokenOK (   $token)

Make sure the given WebRequest contains a valid edit token.

Parameters
string$tokenThe token to check.
Returns
bool true if the token is valid

Implements Wikibase\Repo\EditEntity\EditEntity.

◆ updateWatchlist()

Wikibase\Repo\EditEntity\MediawikiEditEntity::updateWatchlist (   $watch)
private

Watches or unwatches the entity.

Note
Keep in sync with logic in EditPage!
Todo:
move to separate service
Parameters
bool$watchwhether to watch or unwatch the page.
Exceptions
MWException

◆ 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

Member Data Documentation

◆ $allowMasterConnection

Wikibase\Repo\EditEntity\MediawikiEditEntity::$allowMasterConnection
private

◆ $baseRev

Wikibase\Repo\EditEntity\MediawikiEditEntity::$baseRev = null
private

◆ $baseRevId

Wikibase\Repo\EditEntity\MediawikiEditEntity::$baseRevId
private

◆ $context

Wikibase\Repo\EditEntity\MediawikiEditEntity::$context
private

◆ $editFilterHookRunner

Wikibase\Repo\EditEntity\MediawikiEditEntity::$editFilterHookRunner
private

◆ $entityDiffer

Wikibase\Repo\EditEntity\MediawikiEditEntity::$entityDiffer
private

◆ $entityId

Wikibase\Repo\EditEntity\MediawikiEditEntity::$entityId
private

◆ $entityPatcher

Wikibase\Repo\EditEntity\MediawikiEditEntity::$entityPatcher
private

◆ $entityRevisionLookup

Wikibase\Repo\EditEntity\MediawikiEditEntity::$entityRevisionLookup
private

◆ $entityStore

Wikibase\Repo\EditEntity\MediawikiEditEntity::$entityStore
private

◆ $errorType

Wikibase\Repo\EditEntity\MediawikiEditEntity::$errorType = 0
private

◆ $latestRev

Wikibase\Repo\EditEntity\MediawikiEditEntity::$latestRev = null
private

◆ $latestRevId

Wikibase\Repo\EditEntity\MediawikiEditEntity::$latestRevId = 0
private

◆ $localEntityTypes

Wikibase\Repo\EditEntity\MediawikiEditEntity::$localEntityTypes
private

◆ $maxSerializedEntitySize

Wikibase\Repo\EditEntity\MediawikiEditEntity::$maxSerializedEntitySize
private

◆ $permissionChecker

Wikibase\Repo\EditEntity\MediawikiEditEntity::$permissionChecker
private

◆ $status

Wikibase\Repo\EditEntity\MediawikiEditEntity::$status
private

◆ $title

Wikibase\Repo\EditEntity\MediawikiEditEntity::$title = null
private

◆ $titleLookup

Wikibase\Repo\EditEntity\MediawikiEditEntity::$titleLookup
private

◆ $user

Wikibase\Repo\EditEntity\MediawikiEditEntity::$user
private

◆ $userOptionsLookup

Wikibase\Repo\EditEntity\MediawikiEditEntity::$userOptionsLookup
private

The documentation for this class was generated from the following file: