Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Datatype.php |
— | — | @@ -30,6 +30,32 @@ |
31 | 31 | /** |
32 | 32 | * Static class for registering and retrieving typehandlers. |
33 | 33 | * It also caches information about attributes found during page parsing. |
| 34 | + * |
| 35 | + * Currently, types are identified in three different ways within the |
| 36 | + * storage and wiki. In the wiki, users always use the full name of some |
| 37 | + * page in the namespace "Type:" (or whatever its localised version is |
| 38 | + * called like). The annotation is stored internally without the namespace |
| 39 | + * prefix but still using the (possibly also localised) name of the page. |
| 40 | + * This abbreviated name is the "label" of the type. When storing attribute |
| 41 | + * values, types are identified via an "id". This is an language-independent |
| 42 | + * identifier for that type. For instance, English "Type:Integer" has the |
| 43 | + * label "Integer" and the ID "int". |
| 44 | + * |
| 45 | + * For custom types, IDs must depend on the label of the type, and (to distinguish |
| 46 | + * IDs from those of builtin types) is always prefixed with "Type:" (ignoring any |
| 47 | + * localisation for the label of the type namespace). For example, a German custom |
| 48 | + * type "Datentyp:Länge" has the label "Länge" and the ID "Type:Länge". |
| 49 | + * |
| 50 | + * Originally, the distinction of labels and ids was introduced to make the storage |
| 51 | + * contents less dependent on the wikis text content and language. After the |
| 52 | + * extension of the type system with custom types, this design should be revised. |
| 53 | + * The issue is that built-in types need a internationalisation lookup for |
| 54 | + * identifying them from their labels. Avoiding this was the intention of the IDs, |
| 55 | + * but the implementation does not really achieve this at the moment (type labels |
| 56 | + * are not part of the message system yet, and they are registered by their labels |
| 57 | + * anyway suc that no second lookup is necessary). |
| 58 | + * |
| 59 | + * TODO: This is a mess. Completely revise the type registration and identification system. |
34 | 60 | */ |
35 | 61 | class SMWTypeHandlerFactory { |
36 | 62 | |
— | — | @@ -76,7 +102,10 @@ |
77 | 103 | // maybe a custom type? |
78 | 104 | if ( (mb_substr($typeid,0,5) == 'Type:') || |
79 | 105 | ('geoarea' == $typeid) || ('geolength' == $typeid) ) { // compatibility with <0.5 DB entries |
| 106 | + //TODO: when restructuring the type system, provide an update method that "fixes" those old types |
80 | 107 | // Reuse existing float type handler: |
| 108 | + //FIXME: This is bad, since be create a cache entry with the wrong type. It is a good shortcut |
| 109 | + // for the given purpose, but not for other purposes where the same cache entry will be used! |
81 | 110 | SMWTypeHandlerFactory::$typeLabelsByID[$typeid] = SMWTypeHandlerFactory::$typeLabelsByID['float']; |
82 | 111 | $th = SMWTypeHandlerFactory::getTypeHandlerByLabel(SMWTypeHandlerFactory::$typeLabelsByID['float'], false); |
83 | 112 | return $th->getXSDType(); |
— | — | @@ -91,12 +120,13 @@ |
92 | 121 | * should be reasonably light-weight. |
93 | 122 | */ |
94 | 123 | static function getTypeHandlerByID($typeid) { |
95 | | - if (array_key_exists($typeid,SMWTypeHandlerFactory::$typeLabelsByID)) { |
96 | | - $label = SMWTypeHandlerFactory::$typeLabelsByID[$typeid]; |
| 124 | + $label = getTypeLabelByID($typeid); |
| 125 | + if ( $label !== NULL ) { |
97 | 126 | $th = SMWTypeHandlerFactory::getTypeHandlerByLabel($label); |
98 | 127 | return $th; |
| 128 | + } else { |
| 129 | + return NULL; |
99 | 130 | } |
100 | | - return NULL; |
101 | 131 | } |
102 | 132 | |
103 | 133 | /** |
— | — | @@ -108,6 +138,15 @@ |
109 | 139 | if (array_key_exists($typeid,SMWTypeHandlerFactory::$typeLabelsByID)) { |
110 | 140 | return SMWTypeHandlerFactory::$typeLabelsByID[$typeid]; |
111 | 141 | } |
| 142 | + // maybe a custom type? The label then is the string without the prefix "Type:" |
| 143 | + if (mb_substr($typeid,0,5) == 'Type:') { |
| 144 | + SMWTypeHandlerFactory::$typeLabelsByID[$typeid] = mb_substr($typeid,5); |
| 145 | + return mb_substr($typeid,5); |
| 146 | + } elseif ( ('geoarea' == $typeid) || ('geolength' == $typeid) ) { // compatibility with <0.5 DB entries |
| 147 | + //TODO: when restructuring the type system, provide an update method that "fixes" those old types |
| 148 | + SMWTypeHandlerFactory::$typeLabelsByID[$typeid] = SMWTypeHandlerFactory::$typeLabelsByID['float']; // the best we can do |
| 149 | + return SMWTypeHandlerFactory::$typeLabelsByID['float']; |
| 150 | + } |
112 | 151 | return NULL; |
113 | 152 | } |
114 | 153 | |