Wikibase
MediaWiki Wikibase extension
Wikibase\Repo\Content\EntityContent Class Reference

Abstract content object for articles representing Wikibase entities. More...

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

Public Member Functions

 isValid ()
 
 isCountable ( $hasLinks=null)
 
 getEntityRedirect ()
 Returns the EntityRedirect represented by this EntityContent, or null if this EntityContent is not a redirect. More...
 
 getEntity ()
 Returns the entity contained by this entity content. More...
 
 getEntityId ()
 
 getParserOutput (Title $title, $revisionId=null, ParserOptions $options=null, $generateHtml=true)
 Returns a ParserOutput object containing the HTML. More...
 
 getTextForSearchIndex ()
 
 getTextForFilters ()
 
 getWikitextForTransclusion ()
 
 getTextForSummary ( $maxLength=250)
 Returns a textual representation of the content suitable for use in edit summaries and log messages. More...
 
 getNativeData ()
 
 getSize ()
 returns the content's nominal size in bogo-bytes. More...
 
 equals (Content $that=null)
 Both contents will be considered equal if they have the same ID and equal Entity data. More...
 
 getDiff (EntityContent $toContent)
 Returns a diff between this EntityContent and the given EntityContent. More...
 
 getPatchedCopy (EntityContentDiff $patch)
 Returns a patched copy of this Content object. More...
 
 isEmpty ()
 
 copy ()
 
 prepareSave (WikiPage $page, $flags, $baseRevId, User $user)
 
 getEntityPageProperties ()
 Returns a map of properties about the entity, to be recorded in MediaWiki's page_props table. More...
 

Public Attributes

const EDIT_IGNORE_CONSTRAINTS = 1024
 Flag for use with prepareSave(), indicating that no pre-save validation should be applied. More...
 

Protected Member Functions

 getEntityHolder ()
 Returns a holder for the entity contained in this EntityContent object. More...
 
 getParserOutputForRedirect ( $generateHtml)
 
 getParserOutputFromEntityView ( $revisionId, ParserOptions $options, $generateHtml=true)
 
 getRedirectText ()
 
 getIgnoreKeysForFilters ()
 Get the keys within this Contents Entity JSON that should be removed for text passed to edit filters. More...
 

Private Member Functions

 getValidUserLanguage (Language $language)
 
 getEntityRevision ( $revisionId=null)
 
 getRedirectData ()
 Returns an array structure for the redirect represented by this EntityContent, if any. More...
 
 makeEmptyEntity ()
 
 getPatchedRedirect (Diff $redirectPatch)
 
 applyValidators (array $validators)
 Apply the given validators. More...
 
 applyEntityPageProperties (ParserOutput $output)
 Registers any properties returned by getEntityPageProperties() in $output. More...
 

Detailed Description

Abstract content object for articles representing Wikibase entities.

For more information on the relationship between entities and wiki pages, see docs/entity-storage.wiki.

Author
Jeroen De Dauw < jeroe.nosp@m.nded.nosp@m.auw@g.nosp@m.mail.nosp@m..com >
Daniel Kinzler
Bene* < benes.nosp@m.tar..nosp@m.wikim.nosp@m.edia.nosp@m.@gmai.nosp@m.l.co.nosp@m.m >

@method \Wikibase\Repo\Content\EntityHandler getContentHandler()

Member Function Documentation

◆ applyEntityPageProperties()

Wikibase\Repo\Content\EntityContent::applyEntityPageProperties ( ParserOutput  $output)
private

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

Parameters
ParserOutput$output

◆ applyValidators()

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

Apply the given validators.

Parameters
EntityValidator[]$validators
Returns
Status

◆ copy()

Wikibase\Repo\Content\EntityContent::copy ( )
See also
Content::copy
Returns
self

◆ equals()

Wikibase\Repo\Content\EntityContent::equals ( Content  $that = null)

Both contents will be considered equal if they have the same ID and equal Entity data.

If one of the contents is considered "new", then matching IDs is not a criteria for them to be considered equal.

See also
Content::equals
Parameters
Content | null$that
Returns
bool

◆ getDiff()

Wikibase\Repo\Content\EntityContent::getDiff ( EntityContent  $toContent)

Returns a diff between this EntityContent and the given EntityContent.

Parameters
self$toContent
Returns
EntityContentDiff

◆ getEntity()

Wikibase\Repo\Content\EntityContent::getEntity ( )
abstract

Returns the entity contained by this entity content.

Deriving classes typically have a more specific get method as for greater clarity and type hinting.

Exceptions
MWExceptionwhen it's a redirect (targets will never be resolved)
LogicExceptionif the content object is empty and does not contain an entity.
Returns
EntityDocument

Reimplemented in Wikibase\Repo\Content\PropertyContent, and Wikibase\Repo\Content\ItemContent.

◆ getEntityHolder()

Wikibase\Repo\Content\EntityContent::getEntityHolder ( )
abstractprotected

Returns a holder for the entity contained in this EntityContent object.

Exceptions
MWExceptionwhen it's a redirect (targets will never be resolved)
Returns
EntityHolder|null

Reimplemented in Wikibase\Repo\Content\PropertyContent, and Wikibase\Repo\Content\ItemContent.

◆ getEntityId()

Wikibase\Repo\Content\EntityContent::getEntityId ( )
Exceptions
RuntimeExceptionif the content object is empty or no entity ID is set
Returns
EntityId

◆ getEntityPageProperties()

Wikibase\Repo\Content\EntityContent::getEntityPageProperties ( )

Returns a map of properties about the entity, to be recorded in MediaWiki's page_props table.

The idea is to allow efficient lookups of entities based on such properties.

Returns
array A map from property names to property values.

Reimplemented in Wikibase\Repo\Content\PropertyContent, and Wikibase\Repo\Content\ItemContent.

◆ getEntityRedirect()

Wikibase\Repo\Content\EntityContent::getEntityRedirect ( )

Returns the EntityRedirect represented by this EntityContent, or null if this EntityContent is not a redirect.

Note
This default implementation will fail if isRedirect() is true. Subclasses that support redirects must override getEntityRedirect().
Exceptions
LogicException
Returns
EntityRedirect|null

Reimplemented in Wikibase\Repo\Content\ItemContent.

◆ getEntityRevision()

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

◆ getIgnoreKeysForFilters()

Wikibase\Repo\Content\EntityContent::getIgnoreKeysForFilters ( )
abstractprotected

Get the keys within this Contents Entity JSON that should be removed for text passed to edit filters.

Returns
string[] Keys to ignore

Reimplemented in Wikibase\Repo\Content\PropertyContent, and Wikibase\Repo\Content\ItemContent.

◆ getNativeData()

Wikibase\Repo\Content\EntityContent::getNativeData ( )
See also
Content::getNativeData
Note
Avoid relying on this method! It bypasses EntityContentCodec, and does not make any guarantees about the structure of the array returned.
Returns
array|EntityDocument An undefined data structure representing the content. This is not guaranteed to conform to any serialization structure used in the database or externally.

◆ getParserOutput()

Wikibase\Repo\Content\EntityContent::getParserOutput ( Title  $title,
  $revisionId = null,
ParserOptions  $options = null,
  $generateHtml = true 
)

Returns a ParserOutput object containing the HTML.

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.
See also
Content::getParserOutput
Parameters
Title$title
int | null$revisionId
ParserOptions | null$options
bool$generateHtml
Returns
ParserOutput

◆ getParserOutputForRedirect()

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

◆ getParserOutputFromEntityView()

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

Reimplemented in Wikibase\Repo\Content\PropertyContent, and Wikibase\Repo\Content\ItemContent.

◆ getPatchedCopy()

Wikibase\Repo\Content\EntityContent::getPatchedCopy ( EntityContentDiff  $patch)

Returns a patched copy of this Content object.

Parameters
EntityContentDiff$patch
Exceptions
PatcherException
Returns
self

◆ getPatchedRedirect()

Wikibase\Repo\Content\EntityContent::getPatchedRedirect ( Diff  $redirectPatch)
private
Parameters
Diff$redirectPatch
Returns
EntityRedirect|null

◆ getRedirectData()

Wikibase\Repo\Content\EntityContent::getRedirectData ( )
private

Returns an array structure for the redirect represented by this EntityContent, if any.

Note
This may or may not be consistent with what EntityContentCodec does. It it intended to be used primarily for diffing.

◆ getRedirectText()

Wikibase\Repo\Content\EntityContent::getRedirectText ( )
protected
Returns
string Returns the string representation of the redirect represented by this EntityContent (if any).
Note
Will fail if this EntityContent is not a redirect.

◆ getSize()

Wikibase\Repo\Content\EntityContent::getSize ( )

returns the content's nominal size in bogo-bytes.

Returns
int

◆ getTextForFilters()

Wikibase\Repo\Content\EntityContent::getTextForFilters ( )
Returns
string A string representing the content in a way useful for content filtering as performed by extensions like AbuseFilter.

◆ getTextForSearchIndex()

Wikibase\Repo\Content\EntityContent::getTextForSearchIndex ( )
Returns
string A string representing the content in a way useful for building a full text search index.

Reimplemented in Wikibase\Repo\Content\ItemContent.

◆ getTextForSummary()

Wikibase\Repo\Content\EntityContent::getTextForSummary (   $maxLength = 250)

Returns a textual representation of the content suitable for use in edit summaries and log messages.

Parameters
int$maxLengthmaximum length of the summary text
Returns
string
Exceptions
MWException

◆ getValidUserLanguage()

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

◆ getWikitextForTransclusion()

Wikibase\Repo\Content\EntityContent::getWikitextForTransclusion ( )
Returns
string The wikitext to include when another page includes this content, or false if the content is not includable in a wikitext page.

◆ isCountable()

Wikibase\Repo\Content\EntityContent::isCountable (   $hasLinks = null)
See also
EntityContent::isCountable
Parameters
bool | null$hasLinks
Returns
bool True if this is not a redirect and the item is not empty.

◆ isEmpty()

Wikibase\Repo\Content\EntityContent::isEmpty ( )
Returns
bool True if this is not a redirect and the page is empty.

Reimplemented in Wikibase\Repo\Content\PropertyContent, and Wikibase\Repo\Content\ItemContent.

◆ isValid()

Wikibase\Repo\Content\EntityContent::isValid ( )
See also
Content::isValid()
Returns
bool True if this content object is valid for saving. False if there is no entity, or the entity does not have an ID set.

Reimplemented in Wikibase\Repo\Content\PropertyContent.

◆ makeEmptyEntity()

Wikibase\Repo\Content\EntityContent::makeEmptyEntity ( )
private
Returns
EntityDocument

◆ prepareSave()

Wikibase\Repo\Content\EntityContent::prepareSave ( WikiPage  $page,
  $flags,
  $baseRevId,
User  $user 
)
See also
Content::prepareSave
Parameters
WikiPage$page
int$flags
int$baseRevId
User$user
Returns
Status

Member Data Documentation

◆ EDIT_IGNORE_CONSTRAINTS

const Wikibase\Repo\Content\EntityContent::EDIT_IGNORE_CONSTRAINTS = 1024

Flag for use with prepareSave(), indicating that no pre-save validation should be applied.

Can be passed in via EditEntity::attemptSave, EntityStore::saveEntity, as well as WikiPage::doEditContent()

Note
: must not collide with the EDIT_XXX flags defined by MediaWiki core in Defines.php.

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