Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\Repo\Content\EntityHandler Class Reference

Base handler class for Entity content classes. More...

+ Inheritance diagram for Wikibase\Repo\Content\EntityHandler:
+ Collaboration diagram for Wikibase\Repo\Content\EntityHandler:

Public Member Functions

 __construct ( $modelId, $unused, EntityContentDataCodec $contentCodec, EntityConstraintProvider $constraintProvider, ValidatorErrorLocalizer $errorLocalizer, EntityIdParser $entityIdParser, FieldDefinitions $fieldDefinitions, $legacyExportFormatDetector=null)
 
 getLegacyExportFormatDetector ()
 Returns the callback used to determine whether a serialized blob needs to be re-serialized on export (or null of re-serialization is disabled).
 
 showMissingEntity (Title $title, IContextSource $context)
 Handle the fact that a given page does not contain an Entity, even though it could.
 
 getOnSaveValidators ( $forCreation, EntityId $entityId)
 Get EntityValidators for on-save validation.
 
 getValidationErrorLocalizer ()
 Error localizer for use together with getOnSaveValidators().
 
 makeEmptyContent ()
 
 makeEmptyEntity ()
 Returns an empty Entity object of the type supported by this handler.
 
 makeEntityRedirectContent (EntityRedirect $redirect)
 
 supportsCategories ()
 None of the Entity content models support categories.
 
 generateHTMLOnEdit ()
 Do not render HTML on edit (T285987)
 
 getAutosummary (Content $oldContent=null, Content $newContent=null, $flags=0)
 
 makeRedirectContent (Title $title, $text='')
 
 exportTransform ( $blob, $format=null)
 
 makeEntityContent (EntityHolder $entityHolder)
 
 makeEntityId ( $id)
 Parses the given ID string into an EntityId for the type of entity supported by this EntityHandler.
 
 getDefaultFormat ()
 
 serializeContent (Content $content, $format=null)
 
 unserializeContent ( $blob, $format=null)
 
 getIdForTitle (Title $target)
 Returns the ID of the entity contained by the page of the given title.
 
 getTitleForId (EntityId $id)
 Returns the appropriate page Title for the given EntityId.
 
 getTitlesForIds (array $ids)
 Returns the appropriate page Titles for the given EntityIds.
 
 getEntityNamespace ()
 Returns the namespace that is to be used for this kind of entities.
 
 getEntitySlotRole ()
 Returns the slot that is to be used for this kind of entities.
 
 canBeUsedOn (Title $title)
 
 isParserCacheSupported ()
 Returns true to indicate that the parser cache can be used for data items.
 
 getPageViewLanguage (Title $title, Content $content=null)
 
 getPageLanguage (Title $title, Content $content=null)
 
 getSpecialPageForCreation ()
 Returns the name of the special page responsible for creating a page for this type of entity content.
 
 getUndoContent (Content $latestContent, Content $newerContent, Content $olderContent, $undoIsLatest=false)
 
 getEntityType ()
 Returns the entity type ID for the kind of entity managed by this EntityContent implementation.
 
 allowAutomaticIds ()
 Whether IDs can automatically be assigned to entities of the kind supported by this EntityHandler.
 
 canCreateWithCustomId (EntityId $id)
 Whether the given custom ID is valid for creating a new entity of the kind supported by this EntityHandler.
 
 getFieldsForSearchIndex (SearchEngine $engine)
 
 getDataForSearchIndex (WikiPage $page, ParserOutput $parserOutput, SearchEngine $engine, RevisionRecord $revision=null)
 
 getContentDataForSearchIndex (Content $content)
 Extract fields data for the search index but only the fields related to the slot content.
 
 getParserOutputForIndexing (WikiPage $page, ParserCache $cache=null, RevisionRecord $revision=null)
 Produce page output suitable for indexing.
 
 validateSave (Content $content, ValidationParams $validationParams)
 

Public Attributes

const PARSER_VERSION = 3
 Added to parser options for EntityContent.
 

Protected Member Functions

 getDiffEngineClass ()
 
 getSlotDiffRendererWithOptions (IContextSource $context, $options=[])
 
 newEntityContent (EntityHolder $entityHolder=null)
 
 fillParserOutput (Content $content, ContentParseParams $cpoParams, ParserOutput &$parserOutput)
 
 getParserOutputForRedirect (EntityContent $content, bool $generateHtml)
 
 getParserOutputFromEntityView (EntityContent $content, $revisionId, ParserOptions $options, $generateHtml=true)
 

Protected Attributes

 $fieldDefinitions
 
 $contentCodec
 
 $constraintProvider
 

Private Member Functions

 getValidUserLanguage (Language $language)
 
 getEntityRevision (EntityContent $content, $revisionId=null)
 
 applyEntityPageProperties (EntityContent $content, ParserOutput $parserOutput)
 Registers any properties returned by getEntityPageProperties() in $parserOutput.
 
 applyValidators (EntityContent $content, array $validators)
 Apply the given validators.
 

Private Attributes

 $errorLocalizer
 
 $entityIdParser
 
 $legacyExportFormatDetector
 

Detailed Description

Base handler class for Entity content classes.

Author
Daniel Kinzler
Jeroen De Dauw < jeroe.nosp@m.nded.nosp@m.auw@g.nosp@m.mail.nosp@m..com >

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Repo\Content\EntityHandler::__construct ( $modelId,
$unused,
EntityContentDataCodec $contentCodec,
EntityConstraintProvider $constraintProvider,
ValidatorErrorLocalizer $errorLocalizer,
EntityIdParser $entityIdParser,
FieldDefinitions $fieldDefinitions,
$legacyExportFormatDetector = null )
Parameters
string$modelId
mixed$unused
Todo
Get rid of me
Parameters
EntityContentDataCodec$contentCodec
EntityConstraintProvider$constraintProvider
ValidatorErrorLocalizer$errorLocalizer
EntityIdParser$entityIdParser
FieldDefinitions$fieldDefinitions
callable | null$legacyExportFormatDetectorCallback to determine whether a serialized blob needs to be re-serialized on export. The callback must take two parameters, the blob an the serialization format. It must return true if re-serialization is needed. False positives are acceptable, false negatives are not.

Member Function Documentation

◆ allowAutomaticIds()

Wikibase\Repo\Content\EntityHandler::allowAutomaticIds ( )

Whether IDs can automatically be assigned to entities of the kind supported by this EntityHandler.

Returns
bool

◆ applyEntityPageProperties()

Wikibase\Repo\Content\EntityHandler::applyEntityPageProperties ( EntityContent $content,
ParserOutput $parserOutput )
private

Registers any properties returned by getEntityPageProperties() in $parserOutput.

Parameters
EntityContent$content
ParserOutput$parserOutput

◆ applyValidators()

Wikibase\Repo\Content\EntityHandler::applyValidators ( EntityContent $content,
array $validators )
private

Apply the given validators.

Parameters
EntityContent$content
EntityValidator[]$validators
Returns
Status

◆ canBeUsedOn()

Wikibase\Repo\Content\EntityHandler::canBeUsedOn ( Title $title)
See also
ContentHandler::canBeUsedOn

This implementation returns true if and only if the given title's namespace is the same as the one returned by $this->getEntityNamespace().

Parameters
Title$title
Returns
bool true if $title represents a page in the appropriate entity namespace.

◆ canCreateWithCustomId()

Wikibase\Repo\Content\EntityHandler::canCreateWithCustomId ( EntityId $id)

Whether the given custom ID is valid for creating a new entity of the kind supported by this EntityHandler.

Implementations are not required to check if an entity with the given ID already exists. If this method returns true, this means that an entity with the given ID could be created (or already existed) at the time the method was called. There is no guarantee that this continues to be true after the method call returned. Callers must be careful to handle race conditions.

Note
For entity types that cannot be created with custom IDs (that is, entity types that are defined to use automatic IDs), this should always return false.
See also
EntityStore::canCreateWithCustomId()
Parameters
EntityId$id
Returns
bool

◆ exportTransform()

Wikibase\Repo\Content\EntityHandler::exportTransform ( $blob,
$format = null )
See also
ContentHandler::exportTransform
Parameters
string$blob
string | null$format
Returns
string

◆ fillParserOutput()

Wikibase\Repo\Content\EntityHandler::fillParserOutput ( Content $content,
ContentParseParams $cpoParams,
ParserOutput & $parserOutput )
protected
Note
this calls ParserOutput::recordOption( 'userlang' ) to split the cache by user language, and ParserOutput::recordOption( 'wb' ) to split the cache on EntityHandler::PARSER_VERSION.

◆ generateHTMLOnEdit()

Wikibase\Repo\Content\EntityHandler::generateHTMLOnEdit ( )

Do not render HTML on edit (T285987)

◆ getAutosummary()

Wikibase\Repo\Content\EntityHandler::getAutosummary ( Content $oldContent = null,
Content $newContent = null,
$flags = 0 )
See also
ContentHandler::getAutosummary

We never want to use MediaWiki's autosummaries, used e.g. for new page creation. Override this to make sure they never overwrite our autosummaries (which look like the automatic summary prefixes with a section title, and so could be overwritten).

Parameters
Content | null$oldContent
Content | null$newContent
int$flags
Returns
string Empty string

◆ getContentDataForSearchIndex()

Wikibase\Repo\Content\EntityHandler::getContentDataForSearchIndex ( Content $content)

Extract fields data for the search index but only the fields related to the slot content.

Useful for EntityHandlers that may work on non-main slot contents.

@stable to override

Parameters
Content$contentthe Content to extract search data from
Returns
array fields to be indexed by the search engine

◆ getDataForSearchIndex()

Wikibase\Repo\Content\EntityHandler::getDataForSearchIndex ( WikiPage $page,
ParserOutput $parserOutput,
SearchEngine $engine,
RevisionRecord $revision = null )

◆ getDefaultFormat()

Wikibase\Repo\Content\EntityHandler::getDefaultFormat ( )
Returns
string

◆ getDiffEngineClass()

Wikibase\Repo\Content\EntityHandler::getDiffEngineClass ( )
protected

◆ getEntityNamespace()

Wikibase\Repo\Content\EntityHandler::getEntityNamespace ( )
final

Returns the namespace that is to be used for this kind of entities.

Returns
int

◆ getEntityRevision()

Wikibase\Repo\Content\EntityHandler::getEntityRevision ( EntityContent $content,
$revisionId = null )
private
Parameters
EntityContent$content
int | null$revisionId
Returns
EntityRevision

◆ getEntitySlotRole()

Wikibase\Repo\Content\EntityHandler::getEntitySlotRole ( )
final

Returns the slot that is to be used for this kind of entities.

Returns
string the role name of the slot

◆ getEntityType()

Wikibase\Repo\Content\EntityHandler::getEntityType ( )
abstract

Returns the entity type ID for the kind of entity managed by this EntityContent implementation.

Returns
string

Reimplemented in Wikibase\Repo\Content\ItemHandler, and Wikibase\Repo\Content\PropertyHandler.

◆ getFieldsForSearchIndex()

Wikibase\Repo\Content\EntityHandler::getFieldsForSearchIndex ( SearchEngine $engine)
Parameters
SearchEngine$engine
Returns
\SearchIndexField[] List of fields this content handler can provide.

◆ getIdForTitle()

Wikibase\Repo\Content\EntityHandler::getIdForTitle ( Title $target)

Returns the ID of the entity contained by the page of the given title.

Warning
This should not really be needed and may just go away!
Parameters
Title$target
Exceptions
EntityIdParsingException
Returns
EntityId

◆ getLegacyExportFormatDetector()

Wikibase\Repo\Content\EntityHandler::getLegacyExportFormatDetector ( )

Returns the callback used to determine whether a serialized blob needs to be re-serialized on export (or null of re-serialization is disabled).

Returns
callable|null

◆ getOnSaveValidators()

Wikibase\Repo\Content\EntityHandler::getOnSaveValidators ( $forCreation,
EntityId $entityId )

Get EntityValidators for on-save validation.

See also
getValidationErrorLocalizer()
Parameters
bool$forCreationWhether the entity is created (true) or updated (false).
Returns
EntityValidator[]

◆ getPageLanguage()

Wikibase\Repo\Content\EntityHandler::getPageLanguage ( Title $title,
Content $content = null )
See also
ContentHandler::getPageLanguage

This implementation unconditionally returns the wiki's content language. The PageContentLanguage hook is bypassed.

Note
Ideally, this would return 'mul' to indicate multilingual content. But MediaWiki currently doesn't support that.
in several places in mediawiki, most importantly the parser cache, getPageLanguage is used in places where getPageViewLanguage would be more appropriate.
Parameters
Title$titlethe page to determine the language for.
Content | null$contentthe page's content, if you have it handy, to avoid reloading it.
Returns
Language The page's language

◆ getPageViewLanguage()

Wikibase\Repo\Content\EntityHandler::getPageViewLanguage ( Title $title,
Content $content = null )
See also
ContentHandler::getPageViewLanguage

This implementation returns the user language, because entities get rendered in the user's language. The PageContentLanguage hook is bypassed.

Parameters
Title$titlethe page to determine the language for.
Content | null$contentthe page's content, if you have it handy, to avoid reloading it.
Returns
Language The page's language

◆ getParserOutputForIndexing()

Wikibase\Repo\Content\EntityHandler::getParserOutputForIndexing ( WikiPage $page,
ParserCache $cache = null,
RevisionRecord $revision = null )

Produce page output suitable for indexing.

Does not include HTML.

◆ getParserOutputForRedirect()

Wikibase\Repo\Content\EntityHandler::getParserOutputForRedirect ( EntityContent $content,
bool $generateHtml )
protected
Note
Will fail if this EntityContent does not represent a redirect.
Parameters
EntityContent$content
bool$generateHtml
Returns
ParserOutput

◆ getParserOutputFromEntityView()

Wikibase\Repo\Content\EntityHandler::getParserOutputFromEntityView ( EntityContent $content,
$revisionId,
ParserOptions $options,
$generateHtml = true )
protected
Note
Will fail if this EntityContent represents a redirect.
Parameters
EntityContent$content
int | null$revisionId
ParserOptions$options
bool$generateHtml
Returns
ParserOutput

Reimplemented in Wikibase\Repo\Content\ItemHandler, and Wikibase\Repo\Content\PropertyHandler.

◆ getSlotDiffRendererWithOptions()

Wikibase\Repo\Content\EntityHandler::getSlotDiffRendererWithOptions ( IContextSource $context,
$options = [] )
protected

◆ getSpecialPageForCreation()

Wikibase\Repo\Content\EntityHandler::getSpecialPageForCreation ( )

Returns the name of the special page responsible for creating a page for this type of entity content.

Returns null if there is no such special page.

Returns
string|null Always null in this default implementation.

Reimplemented in Wikibase\Repo\Content\ItemHandler, and Wikibase\Repo\Content\PropertyHandler.

◆ getTitleForId()

Wikibase\Repo\Content\EntityHandler::getTitleForId ( EntityId $id)

Returns the appropriate page Title for the given EntityId.

Warning
This should not really be needed and may just go away!
See also
EntityTitleStoreLookup::getTitleForId
Parameters
EntityId$id
Exceptions
InvalidArgumentExceptionif $id refers to an entity of the wrong type.
Returns
Title|null

◆ getTitlesForIds()

Wikibase\Repo\Content\EntityHandler::getTitlesForIds ( array $ids)

Returns the appropriate page Titles for the given EntityIds.

Parameters
EntityId[]$ids
Returns
Title[] Array of Title objects indexed by the entity id serializations

◆ getUndoContent()

Wikibase\Repo\Content\EntityHandler::getUndoContent ( Content $latestContent,
Content $newerContent,
Content $olderContent,
$undoIsLatest = false )
See also
ContentHandler::getUndoContent
Parameters
Content$latestContentThe current text
Content$newerContentThe revision to undo
Content$olderContentMust be an earlier revision than $newer
bool$undoIsLatestSet to true if $newer is from the current revision (since 1.32)
Returns
EntityContent|bool Content on success, false on failure

◆ getValidationErrorLocalizer()

Wikibase\Repo\Content\EntityHandler::getValidationErrorLocalizer ( )

Error localizer for use together with getOnSaveValidators().

See also
getOnSaveValidators()
Returns
ValidatorErrorLocalizer

◆ getValidUserLanguage()

Wikibase\Repo\Content\EntityHandler::getValidUserLanguage ( Language $language)
private

◆ isParserCacheSupported()

Wikibase\Repo\Content\EntityHandler::isParserCacheSupported ( )

Returns true to indicate that the parser cache can be used for data items.

Note
The html representation of entities depends on the user language, so EntityContent::getParserOutput needs to make sure ParserOutput::recordOption( 'userlang' ) is called to split the cache by user language.
See also
ContentHandler::isParserCacheSupported
Returns
bool Always true in this default implementation.

◆ makeEmptyContent()

Wikibase\Repo\Content\EntityHandler::makeEmptyContent ( )
See also
ContentHandler::makeEmptyContent
Returns
EntityContent

◆ makeEmptyEntity()

Wikibase\Repo\Content\EntityHandler::makeEmptyEntity ( )
abstract

Returns an empty Entity object of the type supported by this handler.

This is intended to provide a baseline for diffing and related operations.

Note
The Entity returned here will not have an ID set, and is thus not suitable for use in an EntityContent object.
Returns
EntityDocument

Reimplemented in Wikibase\Repo\Content\ItemHandler, and Wikibase\Repo\Content\PropertyHandler.

◆ makeEntityContent()

Wikibase\Repo\Content\EntityHandler::makeEntityContent ( EntityHolder $entityHolder)
Parameters
EntityHolder$entityHolder
Returns
EntityContent

◆ makeEntityId()

Wikibase\Repo\Content\EntityHandler::makeEntityId ( $id)
abstract

Parses the given ID string into an EntityId for the type of entity supported by this EntityHandler.

If the string is not a valid serialization of the correct type of entity ID, an exception is thrown.

Parameters
string$idString representation the entity ID
Returns
EntityId
Exceptions
InvalidArgumentException

Reimplemented in Wikibase\Repo\Content\ItemHandler, and Wikibase\Repo\Content\PropertyHandler.

◆ makeEntityRedirectContent()

Wikibase\Repo\Content\EntityHandler::makeEntityRedirectContent ( EntityRedirect $redirect)
Parameters
EntityRedirect$redirectUnused in this default implementation.
Returns
EntityContent|null Either a new EntityContent representing the given EntityRedirect, or null if the entity type does not support redirects. Always null in this default implementation.

Reimplemented in Wikibase\Repo\Content\ItemHandler.

◆ makeRedirectContent()

Wikibase\Repo\Content\EntityHandler::makeRedirectContent ( Title $title,
$text = '' )
See also
ContentHandler::makeRedirectContent
Warning
This always throws an exception, since an EntityRedirect needs to know its own ID in addition to the target ID. We have no way to guess that in makeRedirectContent(). Use makeEntityRedirectContent() instead.
See also
makeEntityRedirectContent()
Parameters
Title$title
string$text
Returns
never

◆ newEntityContent()

Wikibase\Repo\Content\EntityHandler::newEntityContent ( EntityHolder $entityHolder = null)
abstractprotected
Parameters
EntityHolder | null$entityHolder
Returns
EntityContent

Reimplemented in Wikibase\Repo\Content\ItemHandler, and Wikibase\Repo\Content\PropertyHandler.

◆ serializeContent()

Wikibase\Repo\Content\EntityHandler::serializeContent ( Content $content,
$format = null )
Parameters
Content$content
string | null$format
Exceptions
InvalidArgumentException
MWContentSerializationException
Returns
string

◆ showMissingEntity()

Wikibase\Repo\Content\EntityHandler::showMissingEntity ( Title $title,
IContextSource $context )

Handle the fact that a given page does not contain an Entity, even though it could.

Per default, this behaves similarly to Article::showMissingArticle: it shows a message to the user.

See also
Article::showMissingArticle
Parameters
Title$titleThe title of the page that potentially could, but does not, contain an entity.
IContextSource$contextContext to use for reporting. In particular, output will be written to $context->getOutput().

◆ supportsCategories()

Wikibase\Repo\Content\EntityHandler::supportsCategories ( )

None of the Entity content models support categories.

Returns
bool Always false.

◆ unserializeContent()

Wikibase\Repo\Content\EntityHandler::unserializeContent ( $blob,
$format = null )
See also
ContentHandler::unserializeContent
Parameters
string$blob
string | null$format
Exceptions
MWContentSerializationException
Returns
EntityContent

◆ validateSave()

Wikibase\Repo\Content\EntityHandler::validateSave ( Content $content,
ValidationParams $validationParams )

Member Data Documentation

◆ $constraintProvider

Wikibase\Repo\Content\EntityHandler::$constraintProvider
protected

◆ $contentCodec

Wikibase\Repo\Content\EntityHandler::$contentCodec
protected

◆ $entityIdParser

Wikibase\Repo\Content\EntityHandler::$entityIdParser
private

◆ $errorLocalizer

Wikibase\Repo\Content\EntityHandler::$errorLocalizer
private

◆ $fieldDefinitions

Wikibase\Repo\Content\EntityHandler::$fieldDefinitions
protected

◆ $legacyExportFormatDetector

Wikibase\Repo\Content\EntityHandler::$legacyExportFormatDetector
private

◆ PARSER_VERSION

const Wikibase\Repo\Content\EntityHandler::PARSER_VERSION = 3

Added to parser options for EntityContent.

Bump the version when making incompatible changes to parser output.


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