On Samstag, 22. März 2008, Matt Williamson wrote: > Devs, > > Quick question: I was trying to instantiate a SMWWikiPageValue object, > and got a class not found error. Come to find, that it's not added to > $wgAutoloadClasses in SMW_GlobalFunctions.php like most of the others, > but instead in SMWDataValueFactory::initDatatypes(). From there, I > traced it back a bit and perhaps it is supposed to get called by some > smwInitDatatypes hook? Then I got lost. > > So, what is the "proper" way to make sure this function is called? Am > I supposed to manually call initDatatypes() before directly > instantiating any DV objects? Or was that supposed to already happen > through some prerequisite step that I missed?
Extensions can overwrite any of SMW's datatypes (which are identified by internal type IDs, not by class names), or add new such datatypes. This is done in the smwInitDatatypes hook, where it is assumed that any such overwrites preserve the public interface of the original implementation (which extends SMWDataValue in some cases, e.g., SMWWikipageValue has a method getDBkey()). To make this overwriting possible, the proper way of creating datavalue objects is via the static methods from the SMWDataValueFactory: SMWDataValueFactory::newTypeIDValue($typeid, $value=false, $caption=false, $propertyname=false) Examples: * Make a date value container that is not holding a value yet: SMWDataValueFactory::newTypeIDValue('_dat') // the value's setUserValue() can be used to set a value later * Make a numerical value representing the input "1234.560": SMWDataValueFactory::newTypeIDValue('_num', '1234.560') * Make a wikipage value container and initialise it from known title data: $value = SMWDataValueFactory::newTypeIDValue('_wpg'); $value->setValues('DB_Key', NS_MAIN, 123); // 123 is the optional page id; // performance improvement if the ID is known but not cached by MediaWiki The propertyname is needed only to create things like the search links shown in the Factbox, the caption is the alternative string given by the user, and the value is always a user-supplied string (i.e. its format may depend on the wiki language -- setXSDValue() can be used if this should be a problem). The type ids are defined in SMWDataValueFactory::initDatatypes(). IDs of built-in types start with one underscore if wiki users can directly use those types for properties (i.e. they have a translated label in the wiki language), and with two underscores if the datatype is used internally by SMW only (e.g. for special properties). Extension datatypes should use no underscores in order to prevent name clashes with future SMW extensions. The SMWDatavalueFactory also has methods for making datavalue objects from SMWTypesValue-objects (the container object for the values of SMW's property "has type"), and some methods for making datavalues for properties (described by their name or by their Title object). The property-related interfaces might change slightly in the future, but the methods newTypeIDValue and newTypeObjectValue are rather stable. -- Markus > > -Matt > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Semediawiki-devel mailing list > Semediawiki-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/semediawiki-devel -- Markus Krötzsch Institut AIFB, Universität Karlsruhe (TH), 76128 Karlsruhe phone +49 (0)721 608 7362 fax +49 (0)721 608 5998 [EMAIL PROTECTED] www http://korrekt.org
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel