Semantic MediaWiki and related extensions
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SMWDataValue Class Reference
Inheritance diagram for SMWDataValue:
Inheritance graph
[legend]

Public Member Functions

 __construct ( $typeid)
 
 getTypeID ()
 
 setUserValue ( $value, $caption=false)
 
 setDataItem (SMWDataItem $dataItem)
 
 setDataValueServiceFactory (DataValueServiceFactory $dataValueServiceFactory)
 
 setProperty (DIProperty $property)
 
 getProperty ()
 
 setContextPage (SMWDIWikiPage $contextPage=null)
 
 getContextPage ()
 
 setCaption ( $caption)
 
 getCaption ()
 
 getPreferredCaption ()
 
 setOutputFormat ( $formatString)
 
 getOutputFormat ()
 
 addError ( $error)
 
 addErrorMsg ( $error, $type=Message::TEXT)
 
 getErrorText ()
 
 getErrors ()
 
 getErrorsByType ( $type=null)
 
 getRestrictionError ()
 
 clearErrors ()
 
 getQueryDescription ( $value)
 
 getDataItem ()
 
 __toString ()
 
 getShortWikiText ( $linker=null)
 
 getShortHTMLText ( $linker=null)
 
 getLongWikiText ( $linker=null)
 
 getLongHTMLText ( $linker=null)
 
 getWikiValue ()
 
 getShortText ( $outputFormat, $linker=null)
 
 getLongText ( $outputFormat, $linker=null)
 
 getInfolinkText ( $outputFormat, $linker=null)
 
 getInfolinks ()
 
 getHash ()
 
 isNumeric ()
 
 isValid ()
 
 canUse ()
 
 isRestricted ()
 
 addCallable ( $key, callable $callable)
 
 hasCallable ( $key)
 
 getCallable ( $key)
 
 clearCallable ( $key)
 
 copyOptions (Options $options=null)
 
 setOption ( $key, $value)
 
 getOption ( $key, $default=false)
 
 hasFeature ( $feature)
 
 isEnabledFeature ( $feature)
 
 checkConstraints ()
 

Static Public Member Functions

static prepareValue (&$value, &$comparator)
 

Public Attributes

const OPT_USER_LANGUAGE = 'user.language'
 
const OPT_CONTENT_LANGUAGE = 'content.language'
 
const OPT_QUERY_CONTEXT = 'query.context'
 
const OPT_QUERY_COMP_CONTEXT = 'query.comparator.context'
 
const OPT_DISABLE_INFOLINKS = 'disable.infolinks'
 
const OPT_DISABLE_SERVICELINKS = 'disable.servicelinks'
 
const OPT_COMPACT_INFOLINKS = 'compact.infolinks'
 

Protected Member Functions

 getOptions ()
 
 parseUserValue ( $value)
 
 loadDataItem (SMWDataItem $dataItem)
 
 getServiceLinkParams ()
 
 checkAllowedValues ()
 

Protected Attributes

 $m_dataitem
 
 $m_property = null
 
 $m_contextPage = null
 
 $m_caption
 
 $m_typeid
 
 $m_outformat = false
 
 $restrictionError = false
 
 $dataValueServiceFactory
 

Detailed Description

Objects of this type represent all that is known about a certain user-provided data value, especially its various representations as strings, tooltips, numbers, etc. Objects can be created as "empty" containers of a certain type, but are then usually filled with data to present one particular data value.

Data values have two chief representation forms: the user-facing syntax and the internal representation. In user syntax, every value is (necessarily) a single string, however complex the value is. For example, a string such as "Help:editing" may represent a wiki page called "Editing" in the namespace for "Help". The internal representation may be any numerical array of strings and numbers. In the example, it might be array("Editing",12), where 12 is the number used for identifying the namespace "Help:". Of course, the internal representation could also use a single string value, such as in array("Help:Editing"), but this might be less useful for certain operations (e.g. filterng by namespace). Moreover, all values that are restored from the database are given in the internal format, so it wise to choose a format that allows for very fast and easy processing without unnecessary parsing.

The main functions of data value objects are:

In addition, there are a number of get-functions that provide useful output versions for displaying and serializing the value.

Author
Markus Krötzsch

Constructor & Destructor Documentation

◆ __construct()

SMWDataValue::__construct (   $typeid)

Constructor.

Parameters
string$typeid

Member Function Documentation

◆ __toString()

SMWDataValue::__toString ( )
Since
2.2
Returns
string

◆ addCallable()

SMWDataValue::addCallable (   $key,
callable  $callable 
)
Since
3.1
Parameters
string$key
callable$callable
Exceptions
RuntimeException

◆ addError()

SMWDataValue::addError (   $error)

Add a new error string or array of such strings to the error list.

Note
Errors should not be escaped here in any way, in contradiction to what the docs used to say here in 1.5 and before. Escaping should happen at the output.
Parameters
array | string | ProcessingError$error

◆ addErrorMsg()

SMWDataValue::addErrorMsg (   $error,
  $type = Message::TEXT 
)

Messages are not resolved until the output and instead will be kept with the message and argument keys (e.g. [2,"smw_baduri","~*0123*"]). This allows to switch the a representation without requiring language context by the object that reports an error.

Since
2.4
Parameters
array | string | ProcessingError$error
integer | null$type

◆ canUse()

SMWDataValue::canUse ( )

Whether a datavalue can be used or not (can be made more restrictive then isValid).

Note
Validity defines a processable state without any technical restrictions while usability is determined by its accessibility to a context (permission, convention etc.)
Since
2.2
Returns
boolean

◆ checkAllowedValues()

SMWDataValue::checkAllowedValues ( )
protected
Deprecated:
since 3.1, use DataValue::checkConstraints

◆ checkConstraints()

SMWDataValue::checkConstraints ( )
Since
3.1

◆ clearCallable()

SMWDataValue::clearCallable (   $key)
Since
3.1
Parameters
string$key

◆ clearErrors()

SMWDataValue::clearErrors ( )
Since
2.4

◆ copyOptions()

SMWDataValue::copyOptions ( Options  $options = null)
Since
2.4
Returns
Options|null $options

◆ getCallable()

SMWDataValue::getCallable (   $key)
Since
3.1
Parameters
string$key
Returns
callable
Exceptions
RuntimeException

◆ getCaption()

SMWDataValue::getCaption ( )
Since
2.4
Parameters
string$caption

◆ getContextPage()

SMWDataValue::getContextPage ( )
Since
2.4
Returns
DIWikiPage|null

◆ getDataItem()

SMWDataValue::getDataItem ( )

Get the actual data contained in this object or null if the data is not defined (due to errors or due to not being set at all).

Note
Most implementations ensure that a data item is always set, even if errors occurred, to avoid additional checks for not accessing null. Hence, one must not assume that a non-null return value here implies that isValid() returns true.
Since
1.6
Returns
SMWDataItem|SMWDIError

◆ getErrors()

SMWDataValue::getErrors ( )

Return an array of error messages, or an empty array if no errors occurred.

Returns
array

◆ getErrorsByType()

SMWDataValue::getErrorsByType (   $type = null)
Since
3.1
Parameters
string | null$type
Returns
array

◆ getErrorText()

SMWDataValue::getErrorText ( )

Return a string that displays all error messages as a tooltip, or an empty string if no errors happened.

Returns
string

◆ getHash()

SMWDataValue::getHash ( )

Return a string that identifies the value of the object, and that can be used to compare different value objects. Possibly overwritten by subclasses (e.g. to ensure that returned value is normalized first)

Returns
string

◆ getInfolinks()

SMWDataValue::getInfolinks ( )

Return an array of SMWLink objects that provide additional resources for the given value. Captions can contain some HTML markup which is admissible for wiki text, but no more. Result might have no entries but is always an array.

◆ getInfolinkText()

SMWDataValue::getInfolinkText (   $outputFormat,
  $linker = null 
)

Return text serialisation of info links. Ensures more uniform layout throughout wiki (Factbox, Property pages, ...).

Parameters
integer$outputFormatElement of the SMW_OUTPUT_ enum
Linker | null | bool$linker
Returns
string

◆ getLongHTMLText()

SMWDataValue::getLongHTMLText (   $linker = null)
abstract

Return the long textual description of the value, as printed for example in the factbox. If errors occurred, return the error message The result always is an HTML string.

The parameter $linker controls linking of values such as titles and should be some Linker object (or NULL for no linking).

Parameters
Linker | null | bool$linker

◆ getLongText()

SMWDataValue::getLongText (   $outputFormat,
  $linker = null 
)

Return the long textual description of the value, as printed for example in the factbox. If errors occurred, return the error message. The output is in the specified format.

The parameter $linker controls linking of values such as titles and should be some Linker object (for HTML output), or NULL for no linking.

Parameters
int$outputFormat
Linker | null | bool$linker

◆ getLongWikiText()

SMWDataValue::getLongWikiText (   $linker = null)
abstract

Return the long textual description of the value, as printed for example in the factbox. If errors occurred, return the error message The result always is a wiki-source string.

The parameter $linked controls linking of values such as titles and should be non-NULL and non-false if this is desired.

Parameters
Linker | null | bool$linker

◆ getOption()

SMWDataValue::getOption (   $key,
  $default = false 
)
Since
2.4
Parameters
string$key
Returns
mixed|false

◆ getOptions()

SMWDataValue::getOptions ( )
protected
Since
2.5
Returns
Options

◆ getOutputFormat()

SMWDataValue::getOutputFormat ( )
Since
2.4
Returns
string

◆ getPreferredCaption()

SMWDataValue::getPreferredCaption ( )

Returns a preferred caption and may deviate from the standard caption as a subclass is permitted to override this method and provide a more contextualized display representation (language or value context etc.).

Since
2.4
Returns
string

◆ getProperty()

SMWDataValue::getProperty ( )

Returns the property to which this value refers.

Since
1.8
Returns
DIProperty|null

◆ getQueryDescription()

SMWDataValue::getQueryDescription (   $value)

FIXME 3.0, allow NULL as value

See also
DataValueDescriptionDeserializer::deserialize
Note
Descriptions of values need to know their property to be able to create a parsable wikitext version of a query condition again. Thus it might be necessary to call setProperty() before using this method.
Parameters
string$value
Returns
Description
Exceptions
InvalidArgumentException

◆ getRestrictionError()

SMWDataValue::getRestrictionError ( )
Since
3.0
Returns
array|false

◆ getServiceLinkParams()

SMWDataValue::getServiceLinkParams ( )
protected

Overwritten by callers to supply an array of parameters that can be used for creating servicelinks. The number and content of values in the parameter array may vary, depending on the concrete datatype.

◆ getShortHTMLText()

SMWDataValue::getShortHTMLText (   $linker = null)
abstract

Returns a short textual representation for this data value. If the value was initialised from a user supplied string, then this original string should be reflected in this short version (i.e. no normalisation should normally happen). There might, however, be additional parts such as code for generating tooltips. The output is in HTML text.

The parameter $linker controls linking of values such as titles and should be some Linker object (or NULL for no linking).

Parameters
Linker | null | bool$linker

◆ getShortText()

SMWDataValue::getShortText (   $outputFormat,
  $linker = null 
)

Returns a short textual representation for this data value. If the value was initialised from a user supplied string, then this original string should be reflected in this short version (i.e. no normalisation should normally happen). There might, however, be additional parts such as code for generating tooltips. The output is in the specified format.

The parameter $linker controls linking of values such as titles and should be some Linker object (for HTML output), or NULL for no linking.

Parameters
int$outputFormat
Linker | null | bool$linker

◆ getShortWikiText()

SMWDataValue::getShortWikiText (   $linker = null)
abstract

Returns a short textual representation for this data value. If the value was initialised from a user supplied string, then this original string should be reflected in this short version (i.e. no normalisation should normally happen). There might, however, be additional parts such as code for generating tooltips. The output is in wiki text.

The parameter $linked controls linking of values such as titles and should be non-NULL and non-false if this is desired.

Parameters
Linker | null | bool$linker

◆ getTypeID()

SMWDataValue::getTypeID ( )

Return a short string that unambiguously specify the type of this value. This value will globally be used to identify the type of a value (in spite of the class it actually belongs to, which can still implement various types).

◆ getWikiValue()

SMWDataValue::getWikiValue ( )
abstract

Return the plain wiki version of the value, or FALSE if no such version is available. The returned string suffices to reobtain the same DataValue when passing it as an input string to setUserValue().

◆ hasCallable()

SMWDataValue::hasCallable (   $key)
Since
3.2
Parameters
string$key
Returns
bool

◆ hasFeature()

SMWDataValue::hasFeature (   $feature)
Since
3.0
Parameters
integer$feature
Returns
boolean

◆ isEnabledFeature()

SMWDataValue::isEnabledFeature (   $feature)
Deprecated:
since 3.0, use DataValue::hasFeature
Since
2.4

◆ isNumeric()

SMWDataValue::isNumeric ( )

Convenience method that checks if the value that is used to sort data of this type is numeric. This only works if the value is set.

Returns
boolean

◆ isRestricted()

SMWDataValue::isRestricted ( )
Since
3.0
Returns
boolean

◆ isValid()

SMWDataValue::isValid ( )

Return true if a value was defined and understood by the given type, and false if parsing errors occurred or no value was given.

Returns
boolean

◆ loadDataItem()

SMWDataValue::loadDataItem ( SMWDataItem  $dataItem)
abstractprotected

Set the actual data contained in this object. The method returns true if this was successful (requiring the type of the dataitem to match the data value). If false is returned, the data value is left unchanged (the data item was rejected).

Note
Even if this function returns true, the data value object might become invalid if the content of the data item caused errors in spite of it being of the right basic type. False is only returned if the data item is fundamentally incompatible with the data value.
Since
1.6
Parameters
SMWDataItem$dataItem
Returns
boolean

◆ parseUserValue()

SMWDataValue::parseUserValue (   $value)
abstractprotected

Initialise the datavalue from the given value string. The format of this strings might be any acceptable user input and especially includes the output of getWikiValue().

Parameters
string$value

◆ prepareValue()

static SMWDataValue::prepareValue ( $value,
$comparator 
)
static
Deprecated:
since 2.3
See also
DescriptionBuilder::prepareValue

This method should no longer be used for direct public access, instead a DataValue is expected to register a DescriptionBuilder with DVDescriptionDeserializerRegistry.

◆ setCaption()

SMWDataValue::setCaption (   $caption)

Change the caption (the text used for displaying this datavalue). The given value must be a string.

Parameters
string$caption

◆ setContextPage()

SMWDataValue::setContextPage ( SMWDIWikiPage  $contextPage = null)

Specify the wiki page to which this value refers. This information is used to parse user values such as "#subsection" which only make sense when used on a certain page.

Since
1.7
Parameters
SMWDIWikiPage | null$contextPage

◆ setDataItem()

SMWDataValue::setDataItem ( SMWDataItem  $dataItem)

Set the actual data contained in this object. The method returns true if this was successful (requiring the type of the dataitem to match the data value). If false is returned, the data value is left unchanged (the data item was rejected).

Note
Even if this function returns true, the data value object might become invalid if the content of the data item caused errors in spite of it being of the right basic type. False is only returned if the data item is fundamentally incompatible with the data value.
Parameters
$dataitemSMWDataItem
Returns
boolean

◆ setDataValueServiceFactory()

SMWDataValue::setDataValueServiceFactory ( DataValueServiceFactory  $dataValueServiceFactory)
Since
2.5
Parameters
DataValueServiceFactory$dataValueServiceFactory

◆ setOption()

SMWDataValue::setOption (   $key,
  $value 
)
Since
2.4
Returns
string $key
Parameters
mxied$value

◆ setOutputFormat()

SMWDataValue::setOutputFormat (   $formatString)

Define a particular output format. Output formats are user-supplied strings that the datavalue may (or may not) use to customise its return value. For example, quantities with units of measurement may interpret the string as a desired output unit. In other cases, the output format might be built-in and subject to internationalisation (which the datavalue has to implement). In any case, an empty string resets the output format to the default.

There is one predefined output format that all datavalues should respect: the format '-' indicates "plain" output that is most useful for further processing the value in a template. It should not use any wiki markup or beautification, and it should also avoid localization to the current language. When users explicitly specify an empty format string in a query, it is normalized to "-" to avoid confusion. Note that empty format strings are not interpreted in this way when directly passed to this function.

Parameters
string$formatString

◆ setProperty()

SMWDataValue::setProperty ( DIProperty  $property)

Specify the property to which this value refers. Property pages are used to make settings that affect parsing and display, hence it is sometimes needed to know them.

Since
1.6
Parameters
DIProperty$property

◆ setUserValue()

SMWDataValue::setUserValue (   $value,
  $caption = false 
)

Set the user value (and compute other representations if possible). The given value is a string as supplied by some user. An alternative label for printout might also be specified.

Parameters
string$value
mixed$caption

Member Data Documentation

◆ OPT_COMPACT_INFOLINKS

const SMWDataValue::OPT_COMPACT_INFOLINKS = 'compact.infolinks'

Option to use compact infolinks

◆ OPT_CONTENT_LANGUAGE

const SMWDataValue::OPT_CONTENT_LANGUAGE = 'content.language'

Contains either the global "site" content language or a specified page content language invoked by the context page.

◆ OPT_DISABLE_INFOLINKS

const SMWDataValue::OPT_DISABLE_INFOLINKS = 'disable.infolinks'

Option to disable related infolinks

◆ OPT_DISABLE_SERVICELINKS

const SMWDataValue::OPT_DISABLE_SERVICELINKS = 'disable.servicelinks'

Option to disable service links

◆ OPT_QUERY_COMP_CONTEXT

const SMWDataValue::OPT_QUERY_COMP_CONTEXT = 'query.comparator.context'

Describes a state where a DataValue is part of a query condition and contains a comparator.

◆ OPT_QUERY_CONTEXT

const SMWDataValue::OPT_QUERY_CONTEXT = 'query.context'

Describes a state where a DataValue is part of a query condition and may (or not) require a different treatment.

◆ OPT_USER_LANGUAGE

const SMWDataValue::OPT_USER_LANGUAGE = 'user.language'

Contains the user language a user operates in.


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

About | General disclaimer | Privacy policy