Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Concept.php |
— | — | @@ -15,38 +15,21 @@ |
16 | 16 | */ |
17 | 17 | class SMWConceptValue extends SMWDataValue { |
18 | 18 | |
19 | | - protected $m_concept = ''; // XML-safe, HTML-safe, Wiki-compatible concept expression (query string) |
20 | | - protected $m_docu = ''; // text description of concept, can only be set by special function "setvalues" |
21 | | - |
22 | 19 | public function getBaseType() { |
23 | 20 | return SMWDataValue::TYPE_CONCEPT; |
24 | 21 | } |
25 | 22 | |
26 | 23 | protected function parseUserValue( $value ) { |
27 | | - $this->clear(); |
28 | | - // this function is normally not used for this class, not created from user input directly |
29 | | - $this->m_concept = smwfXMLContentEncode( $value ); |
30 | | - if ( $this->m_caption === false ) { |
31 | | - $this->m_caption = $value; |
32 | | - } |
33 | | - return true; |
| 24 | + throw new Exception( 'Concepts cannot be initialised from user-provided strings. This should not happen.' ); |
34 | 25 | } |
35 | 26 | |
36 | 27 | protected function parseDBkeys( $args ) { |
37 | | - $this->m_concept = $args[0]; |
38 | 28 | $this->m_caption = $args[0]; // is this useful? |
39 | | - $this->m_docu = $args[1] ? smwfXMLContentEncode( $args[1] ):''; |
40 | | - $this->m_queryfeatures = $args[2]; |
41 | | - $this->m_size = $args[3]; |
42 | | - $this->m_depth = $args[4]; |
| 29 | + $this->m_dataitem = new SMWDIConcept( $args[0], smwfXMLContentEncode( $args[1] ), $args[2], $args[3], $args[4], $this->m_typeid ); |
43 | 30 | } |
44 | 31 | |
45 | 32 | protected function clear() { |
46 | | - $this->m_concept = ''; |
47 | | - $this->m_docu = ''; |
48 | | - $this->m_queryfeatures = 0; |
49 | | - $this->m_size = -1; |
50 | | - $this->m_depth = -1; |
| 33 | + $this->m_dataitem = new SMWDIConcept( '', '', 0, -1, -1, $this->m_typeid ); |
51 | 34 | } |
52 | 35 | |
53 | 36 | public function getShortWikiText( $linked = null ) { |
— | — | @@ -76,7 +59,7 @@ |
77 | 60 | |
78 | 61 | public function getDBkeys() { |
79 | 62 | $this->unstub(); |
80 | | - return array( $this->m_concept, $this->m_docu, $this->m_queryfeatures, $this->m_size, $this->m_depth ); |
| 63 | + return array( $this->m_dataitem->getConceptQuery(), $this->m_dataitem->getDocumentation(), $this->m_dataitem->getQueryFeatures(), $this->m_dataitem->getSize(), $this->m_dataitem->getDepth() ); |
81 | 64 | } |
82 | 65 | |
83 | 66 | public function getSignature() { |
— | — | @@ -93,13 +76,14 @@ |
94 | 77 | |
95 | 78 | public function getWikiValue() { |
96 | 79 | $this->unstub(); |
97 | | - return str_replace( array( '<', '>', '&' ), array( '<', '>', '&' ), $this->m_concept ); |
| 80 | + /// This should not be used for anything. This class does not support wiki values. |
| 81 | + return str_replace( array( '<', '>', '&' ), array( '<', '>', '&' ), $this->m_dataitem->getConceptQuery() ); |
98 | 82 | } |
99 | 83 | |
100 | 84 | public function getExportData() { |
101 | 85 | if ( $this->isValid() ) { |
102 | 86 | $qp = new SMWQueryParser(); |
103 | | - $desc = $qp->getQueryDescription( $this->getWikiValue() ); |
| 87 | + $desc = $qp->getQueryDescription( str_replace( array( '<', '>', '&' ), array( '<', '>', '&' ), $this->m_dataitem->getConceptQuery() ) ); |
104 | 88 | $exact = true; |
105 | 89 | $owldesc = $this->descriptionToExpData( $desc, $exact ); |
106 | 90 | if ( $owldesc === false ) { |
— | — | @@ -193,31 +177,31 @@ |
194 | 178 | /// Return the concept's defining text (in SMW query syntax) |
195 | 179 | public function getConceptText() { |
196 | 180 | $this->unstub(); |
197 | | - return $this->m_concept; |
| 181 | + return $this->m_dataitem->getConceptQuery(); |
198 | 182 | } |
199 | 183 | |
200 | 184 | /// Return the optional concept documentation. |
201 | 185 | public function getDocu() { |
202 | 186 | $this->unstub(); |
203 | | - return $this->m_docu; |
| 187 | + return $this->m_dataitem->getDocumentation(); |
204 | 188 | } |
205 | 189 | |
206 | 190 | /// Return the concept's size (a metric used to estimate computation complexity). |
207 | 191 | public function getSize() { |
208 | 192 | $this->unstub(); |
209 | | - return $this->m_size; |
| 193 | + return $this->m_dataitem->getSize(); |
210 | 194 | } |
211 | 195 | |
212 | 196 | /// Return the concept's depth (a metric used to estimate computation complexity). |
213 | 197 | public function getDepth() { |
214 | 198 | $this->unstub(); |
215 | | - return $this->m_depth; |
| 199 | + return $this->m_dataitem->getDepth(); |
216 | 200 | } |
217 | 201 | |
218 | 202 | /// Return the concept's query feature bit field (a metric used to estimate computation complexity). |
219 | 203 | public function getQueryFeatures() { |
220 | 204 | $this->unstub(); |
221 | | - return $this->m_queryfeatures; |
| 205 | + return $this->m_dataitem->getQueryFeatures(); |
222 | 206 | } |
223 | 207 | |
224 | 208 | /// @deprecated Use setDBkeys(). This method will vanish before SMW 1.6 |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SetupLight.php |
— | — | @@ -111,6 +111,7 @@ |
112 | 112 | $wgAutoloadClasses['SMWDIURI'] = $diDir . 'SMW_DI_URI.php'; |
113 | 113 | $wgAutoloadClasses['SMWDIWikiPage'] = $diDir . 'SMW_DI_WikiPage.php'; |
114 | 114 | $wgAutoloadClasses['SMWDITime'] = $diDir . 'SMW_DI_Time.php'; |
| 115 | +// $wgAutoloadClasses['SMWDIConcept'] = $diDir . 'SMW_DI_Concept.php'; |
115 | 116 | |
116 | 117 | // Datavalues |
117 | 118 | $dvDir = $smwgIP . 'includes/datavalues/'; |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Concept.php |
— | — | @@ -0,0 +1,102 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * @ingroup SMWDataItems |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * This class implements Concept data items. |
| 10 | + * These special data items for storing concept declaration data in SMW may |
| 11 | + * well vanish at some point since Container values could encode this data |
| 12 | + * just as well. |
| 13 | + * |
| 14 | + * @author Markus Krötzsch |
| 15 | + * @ingroup SMWDataItems |
| 16 | + */ |
| 17 | +class SMWDIConcept extends SMWDataItem { |
| 18 | + |
| 19 | + /** |
| 20 | + * Query string for this concept. Possibly long. |
| 21 | + * @var string |
| 22 | + */ |
| 23 | + protected $m_concept; |
| 24 | + /** |
| 25 | + * Documentation for this concept. Possibly long. |
| 26 | + * @var string |
| 27 | + */ |
| 28 | + protected $m_docu; |
| 29 | + /** |
| 30 | + * Flags of query features. |
| 31 | + * @var integer |
| 32 | + */ |
| 33 | + protected $m_features; |
| 34 | + /** |
| 35 | + * Size of the query. |
| 36 | + * @var integer |
| 37 | + */ |
| 38 | + protected $m_size; |
| 39 | + /** |
| 40 | + * Depth of the query. |
| 41 | + * @var integer |
| 42 | + */ |
| 43 | + protected $m_depth; |
| 44 | + |
| 45 | + /** |
| 46 | + * Initialise the concept data. |
| 47 | + * @param $concept the concept query string |
| 48 | + * @param $docu string with user documentation |
| 49 | + * @param $queryefeatures integer flags about query features |
| 50 | + * @param $size integer concept query size |
| 51 | + * @param $depth integer concept query depth |
| 52 | + * @param $typeid string SMW type id |
| 53 | + */ |
| 54 | + public function __construct( $concept, $docu, $queryfeatures, $size, $depth, $typeid = '_con' ) { |
| 55 | + $this->m_concept = $concept; |
| 56 | + $this->m_docu = $docu; |
| 57 | + $this->m_features = $queryfeatures; |
| 58 | + $this->m_size = $size; |
| 59 | + $this->m_depth = $depth; |
| 60 | + } |
| 61 | + |
| 62 | + public function getDIType() { |
| 63 | + return SMWDataItem::TYPE_CONCEPT; |
| 64 | + } |
| 65 | + |
| 66 | + public function getConceptQuery() { |
| 67 | + return $this->m_concept; |
| 68 | + } |
| 69 | + |
| 70 | + public function getDocumentation() { |
| 71 | + return $this->m_docu; |
| 72 | + } |
| 73 | + |
| 74 | + public function getQueryFeatures() { |
| 75 | + return $this->m_features; |
| 76 | + } |
| 77 | + |
| 78 | + public function getSize() { |
| 79 | + return $this->m_size; |
| 80 | + } |
| 81 | + |
| 82 | + public function getDepth() { |
| 83 | + return $this->m_depth; |
| 84 | + } |
| 85 | + |
| 86 | + public function getSerialization() { |
| 87 | + return serialize( $this ); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Create a data item from the provided serialization string and type |
| 92 | + * ID. |
| 93 | + * @return SMWDIConcept |
| 94 | + */ |
| 95 | + public static function doUnserialize( $serialization, $typeid ) { |
| 96 | + $result = unserialize( $serialization ); |
| 97 | + if ( $result === false ) { |
| 98 | + throw new SMWDataItemException( "Unserialization failed." ); |
| 99 | + } |
| 100 | + return $result; |
| 101 | + } |
| 102 | + |
| 103 | +} |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -142,6 +142,7 @@ |
143 | 143 | $wgAutoloadClasses['SMWDIURI'] = $diDir . 'SMW_DI_URI.php'; |
144 | 144 | $wgAutoloadClasses['SMWDIWikiPage'] = $diDir . 'SMW_DI_WikiPage.php'; |
145 | 145 | $wgAutoloadClasses['SMWDITime'] = $diDir . 'SMW_DI_Time.php'; |
| 146 | + $wgAutoloadClasses['SMWDIConcept'] = $diDir . 'SMW_DI_Concept.php'; |
146 | 147 | |
147 | 148 | // Datavalues |
148 | 149 | $dvDir = $smwgIP . 'includes/datavalues/'; |