Wikibase
MediaWiki Wikibase extension
|
Builder of MediaWiki ApiResult objects with various convenience functions for adding Wikibase concepts and result parts to results in a uniform way. More...
Public Member Functions | |
__construct (ApiResult $result, EntityTitleStoreLookup $entityTitleStoreLookup, SerializerFactory $serializerFactory, Serializer $entitySerializer, SiteLookup $siteLookup, PropertyDataTypeLookup $dataTypeLookup, EntityIdParser $entityIdParser, $addMetaData=null) | |
markSuccess ( $success=true) | |
Mark the ApiResult as successful. | |
setList ( $path, $name, array $values, $tag) | |
Adds a list of values for the given path and name. | |
setValue ( $path, $name, $value) | |
Set an atomic value (or record) for the given path and name. | |
appendValue ( $path, $key, $value, $tag) | |
Appends a value to the list at the given path. | |
addEntityRevision ( $sourceEntityIdSerialization, EntityRevision $entityRevision, $props='all', array $filterSiteIds=null, array $filterLangCodes=[], array $termFallbackChains=[]) | |
Get serialized entity for the EntityRevision and add it to the result alongside other needed properties. | |
getModifiedEntityArray (EntityDocument $entity, $props, ?array $filterSiteIds, array $filterLangCodes, array $termFallbackChains) | |
Gets the standard serialization of an EntityDocument and modifies it in a standard way. | |
addBasicEntityInformation (EntityId $entityId, $path) | |
Get serialized information for the EntityId and add them to result. | |
addLabels (TermList $labels, $path) | |
Get serialized labels and add them to result. | |
addRemovedLabel ( $language, $path) | |
Adds fake serialization to show a label has been removed. | |
addDescriptions (TermList $descriptions, $path) | |
Get serialized descriptions and add them to result. | |
addRemovedDescription ( $language, $path) | |
Adds fake serialization to show a label has been removed. | |
addAliasGroupList (AliasGroupList $aliasGroupList, $path) | |
Get serialized AliasGroupList and add it to result. | |
addSiteLinkList (SiteLinkList $siteLinkList, $path, $addUrl=false) | |
Get serialized sitelinks and add them to result. | |
addRemovedSiteLinks (SiteLinkList $siteLinkList, $path) | |
Adds fake serialization to show a sitelink has been removed. | |
addStatements (StatementList $statements, $path, $props='all') | |
Get serialized claims and add them to result. | |
addStatement (Statement $statement) | |
Get serialized claim and add it to result. | |
addReference (Reference $reference) | |
Get serialized reference and add it to result. | |
addMissingEntity ( $key, array $missingDetails) | |
Add an entry for a missing entity... | |
addNormalizedTitle ( $from, $to, $name='n') | |
addRevisionIdFromStatusToResult (Status $status, $path, $oldRevId=null) | |
Adds the ID of the new revision from the Status object to the API result structure. | |
Private Member Functions | |
checkPathType ( $path) | |
checkKeyType ( $key) | |
checkValueIsNotList ( $value) | |
addEntityInfoToRecord (array $record, EntityId $entityId) | |
addEntityRedirectInfoToRecord (array $record, $sourceEntityIdSerialization, EntityId $entityId) | |
filterEntitySerializationUsingProps (array $serialization, $props) | |
injectEntitySerializationWithSiteLinkUrls (array $serialization) | |
sortEntitySerializationSiteLinks (array $serialization) | |
filterEntitySerializationUsingSiteIds (array $serialization, array $siteIds=null) | |
addEntitySerializationFallbackInfo (array $serialization, array $termFallbackChains) | |
getTermsSerializationWithFallbackInfo (array $serialization, array $termFallbackChains) | |
filterEntitySerializationUsingLangCodes (array $serialization, array $langCodes) | |
getEntitySerializationWithMetaData (array $serialization) | |
addTermList (TermList $termList, $name, $tag, $path) | |
Get serialized TermList and add it to the result. | |
addRemovedTerm ( $language, $name, $tag, $path) | |
Adds fake serialization to show a term has been removed. | |
getSiteLinkListArrayWithUrls (array $array) | |
getSiteLinkListArrayWithMetaData (array $array) | |
getArrayWithAlteredClaims (array $array, $claimPath='') | |
getClaimsArrayWithMetaData (array $array, $claimPath='') | |
getReferenceArrayWithMetaData (array $array) | |
Builder of MediaWiki ApiResult objects with various convenience functions for adding Wikibase concepts and result parts to results in a uniform way.
This class was introduced when Wikibase was reduced from 2 sets of serializers (lib & data-model) to one. This class makes various modifications to the 1 standard serialization of Wikibase concepts for public exposure. The resulting format can be seen as the public serialization of Wikibase concepts.
Many concepts such as "tag name" relate to concepts explained within ApiResult.
Wikibase\Repo\Api\ResultBuilder::__construct | ( | ApiResult | $result, |
EntityTitleStoreLookup | $entityTitleStoreLookup, | ||
SerializerFactory | $serializerFactory, | ||
Serializer | $entitySerializer, | ||
SiteLookup | $siteLookup, | ||
PropertyDataTypeLookup | $dataTypeLookup, | ||
EntityIdParser | $entityIdParser, | ||
$addMetaData = null ) |
ApiResult | $result | |
EntityTitleStoreLookup | $entityTitleStoreLookup | |
SerializerFactory | $serializerFactory | |
Serializer | $entitySerializer | |
SiteLookup | $siteLookup | |
PropertyDataTypeLookup | $dataTypeLookup | |
EntityIdParser | $entityIdParser | |
bool | null | $addMetaData | when special elements such as '_element' are needed |
Wikibase\Repo\Api\ResultBuilder::addAliasGroupList | ( | AliasGroupList | $aliasGroupList, |
$path ) |
Get serialized AliasGroupList and add it to result.
AliasGroupList | $aliasGroupList | the AliasGroupList to set in the result |
array | string | null | $path | where the data is located |
Wikibase\Repo\Api\ResultBuilder::addBasicEntityInformation | ( | EntityId | $entityId, |
$path ) |
Get serialized information for the EntityId and add them to result.
EntityId | $entityId | |
string | array | null | $path |
Wikibase\Repo\Api\ResultBuilder::addDescriptions | ( | TermList | $descriptions, |
$path ) |
Get serialized descriptions and add them to result.
TermList | $descriptions | the descriptions to insert in the result |
array | string | null | $path | where the data is located |
|
private |
|
private |
Wikibase\Repo\Api\ResultBuilder::addEntityRevision | ( | $sourceEntityIdSerialization, | |
EntityRevision | $entityRevision, | ||
$props = 'all', | |||
array | $filterSiteIds = null, | ||
array | $filterLangCodes = [], | ||
array | $termFallbackChains = [] ) |
Get serialized entity for the EntityRevision and add it to the result alongside other needed properties.
string | null | $sourceEntityIdSerialization | EntityId used to retrieve $entityRevision Used as the key for the entity in the 'entities' structure and for adding redirect info Will default to the entity's serialized ID if null. If given this must be the entity id before any redirects were resolved. |
EntityRevision | $entityRevision | |
string[] | string | $props | a list of fields to include, or "all" |
string[] | null | $filterSiteIds | A list of site IDs to filter by |
string[] | $filterLangCodes | A list of language codes to filter by |
TermLanguageFallbackChain[] | $termFallbackChains | with keys of the origional language |
|
private |
array | $serialization | |
TermLanguageFallbackChain[] | $termFallbackChains |
Wikibase\Repo\Api\ResultBuilder::addLabels | ( | TermList | $labels, |
$path ) |
Get serialized labels and add them to result.
TermList | $labels | the labels to insert in the result |
array | string | null | $path | where the data is located |
Wikibase\Repo\Api\ResultBuilder::addMissingEntity | ( | $key, | |
array | $missingDetails ) |
Add an entry for a missing entity...
string | null | $key | The key under which to place the missing entity in the 'entities' structure. If null, defaults to the 'id' field in $missingDetails if that is set; otherwise, it defaults to using a unique negative number. |
array | $missingDetails | array containing key value pair missing details |
Wikibase\Repo\Api\ResultBuilder::addNormalizedTitle | ( | $from, | |
$to, | |||
$name = 'n' ) |
string | $from | |
string | $to | |
string | $name |
Wikibase\Repo\Api\ResultBuilder::addReference | ( | Reference | $reference | ) |
Get serialized reference and add it to result.
Reference | $reference |
Wikibase\Repo\Api\ResultBuilder::addRemovedDescription | ( | $language, | |
$path ) |
Adds fake serialization to show a label has been removed.
string | $language | |
array | string | null | $path | where the data is located |
Wikibase\Repo\Api\ResultBuilder::addRemovedLabel | ( | $language, | |
$path ) |
Adds fake serialization to show a label has been removed.
string | $language | |
array | string | null | $path | where the data is located |
Wikibase\Repo\Api\ResultBuilder::addRemovedSiteLinks | ( | SiteLinkList | $siteLinkList, |
$path ) |
Adds fake serialization to show a sitelink has been removed.
SiteLinkList | $siteLinkList | |
array | string | null | $path | where the data is located |
|
private |
Adds fake serialization to show a term has been removed.
string | $language | |
string | $name | |
string | $tag | |
array | string | null | $path | where the data is located |
Wikibase\Repo\Api\ResultBuilder::addRevisionIdFromStatusToResult | ( | Status | $status, |
$path, | |||
$oldRevId = null ) |
Adds the ID of the new revision from the Status object to the API result structure.
The status value is expected to be structured in the way that EditEntity::attemptSave() resp WikiPage::doUserEditContent() do it: as an array, with an EntityRevision object in the 'revision' field. If $oldRevId is set and the latest edit was null, a 'nochange' flag is also added.
If no revision is found in the Status object, this method does nothing.
Status | $status | The status to get the revision ID from. |
string | null | array | $path | Where in the result to put the revision id |
int | null | $oldRevId | The id of the latest revision of the entity before the last (possibly null) edit |
Wikibase\Repo\Api\ResultBuilder::addSiteLinkList | ( | SiteLinkList | $siteLinkList, |
$path, | |||
$addUrl = false ) |
Get serialized sitelinks and add them to result.
SiteLinkList | $siteLinkList | the site links to insert in the result |
array | string | null | $path | where the data is located |
bool | $addUrl |
Wikibase\Repo\Api\ResultBuilder::addStatement | ( | Statement | $statement | ) |
Get serialized claim and add it to result.
Statement | $statement |
Wikibase\Repo\Api\ResultBuilder::addStatements | ( | StatementList | $statements, |
$path, | |||
$props = 'all' ) |
Get serialized claims and add them to result.
StatementList | $statements | the labels to set in the result |
array | string | null | $path | where the data is located |
array | string | $props | a list of fields to include, or "all" |
|
private |
Get serialized TermList and add it to the result.
TermList | $termList | |
string | $name | |
string | $tag | |
array | string | null | $path | where the data is located |
Wikibase\Repo\Api\ResultBuilder::appendValue | ( | $path, | |
$key, | |||
$value, | |||
$tag ) |
Appends a value to the list at the given path.
This automatically sets the indexed tag name, if appropriate.
If the value is an array, it should be associative, not a list. For adding lists, use setList().
array | string | null | $path | |
int | string | null | $key | the key to use when appending, or null for automatic. May be ignored even if given, based on $this->addMetaData. |
mixed | $value | |
string | $tag | tag name to use for $value in indexed mode |
|
private |
int | string | null | $key | the key to use when appending, or null for automatic. |
|
private |
array | string | null | $path |
|
private |
mixed | $value |
|
private |
array | $serialization | |
string[] | $langCodes |
|
private |
array | $serialization | |
string | array | $props |
|
private |
|
private |
array | $array | |
string | $claimPath | to the claim array/arrays with trailing / |
|
private |
array | $array | |
string | $claimPath | to the claim array/arrays with trailing / |
|
private |
Wikibase\Repo\Api\ResultBuilder::getModifiedEntityArray | ( | EntityDocument | $entity, |
$props, | |||
?array | $filterSiteIds, | ||
array | $filterLangCodes, | ||
array | $termFallbackChains ) |
Gets the standard serialization of an EntityDocument and modifies it in a standard way.
This code was created for Items and Properties and since new entity types have been introduced it may not work in the desired way.
EntityDocument | $entity | |
array | string | $props | |
string[] | null | $filterSiteIds | |
string[] | $filterLangCodes | |
TermLanguageFallbackChain[] | $termFallbackChains |
|
private |
|
private |
|
private |
|
private |
array | $serialization | |
TermLanguageFallbackChain[] | $termFallbackChains |
|
private |
Wikibase\Repo\Api\ResultBuilder::markSuccess | ( | $success = true | ) |
Mark the ApiResult as successful.
{ "success": 1 }
bool | int | null | $success |
Wikibase\Repo\Api\ResultBuilder::setList | ( | $path, | |
$name, | |||
array | $values, | ||
$tag ) |
Adds a list of values for the given path and name.
This automatically sets the indexed tag name, if appropriate.
To set atomic values or records, use setValue() or appendValue().
array | string | null | $path | |
string | $name | |
array | $values | |
string | $tag | tag name to use for elements of $values if not already present |
Wikibase\Repo\Api\ResultBuilder::setValue | ( | $path, | |
$name, | |||
$value ) |
Set an atomic value (or record) for the given path and name.
If the value is an array, it should be a record (associative), not a list. For adding lists, use setList().
array | string | null | $path | |
string | $name | |
mixed | $value |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |