r85429 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85428‎ | r85429 | r85430 >
Date:08:30, 5 April 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
manage concept data in new concept dataitem; it is conceivable that the concept davalue class will vanish completely since it is hardly needed for anything else than storing the plain data (parsing and display already special for concepts)
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_SetupLight.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Concept.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Concept.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Concept.php
@@ -15,38 +15,21 @@
1616 */
1717 class SMWConceptValue extends SMWDataValue {
1818
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 -
2219 public function getBaseType() {
2320 return SMWDataValue::TYPE_CONCEPT;
2421 }
2522
2623 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.' );
3425 }
3526
3627 protected function parseDBkeys( $args ) {
37 - $this->m_concept = $args[0];
3828 $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 );
4330 }
4431
4532 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 );
5134 }
5235
5336 public function getShortWikiText( $linked = null ) {
@@ -76,7 +59,7 @@
7760
7861 public function getDBkeys() {
7962 $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() );
8164 }
8265
8366 public function getSignature() {
@@ -93,13 +76,14 @@
9477
9578 public function getWikiValue() {
9679 $this->unstub();
97 - return str_replace( array( '&lt;', '&gt;', '&amp;' ), array( '<', '>', '&' ), $this->m_concept );
 80+ /// This should not be used for anything. This class does not support wiki values.
 81+ return str_replace( array( '&lt;', '&gt;', '&amp;' ), array( '<', '>', '&' ), $this->m_dataitem->getConceptQuery() );
9882 }
9983
10084 public function getExportData() {
10185 if ( $this->isValid() ) {
10286 $qp = new SMWQueryParser();
103 - $desc = $qp->getQueryDescription( $this->getWikiValue() );
 87+ $desc = $qp->getQueryDescription( str_replace( array( '&lt;', '&gt;', '&amp;' ), array( '<', '>', '&' ), $this->m_dataitem->getConceptQuery() ) );
10488 $exact = true;
10589 $owldesc = $this->descriptionToExpData( $desc, $exact );
10690 if ( $owldesc === false ) {
@@ -193,31 +177,31 @@
194178 /// Return the concept's defining text (in SMW query syntax)
195179 public function getConceptText() {
196180 $this->unstub();
197 - return $this->m_concept;
 181+ return $this->m_dataitem->getConceptQuery();
198182 }
199183
200184 /// Return the optional concept documentation.
201185 public function getDocu() {
202186 $this->unstub();
203 - return $this->m_docu;
 187+ return $this->m_dataitem->getDocumentation();
204188 }
205189
206190 /// Return the concept's size (a metric used to estimate computation complexity).
207191 public function getSize() {
208192 $this->unstub();
209 - return $this->m_size;
 193+ return $this->m_dataitem->getSize();
210194 }
211195
212196 /// Return the concept's depth (a metric used to estimate computation complexity).
213197 public function getDepth() {
214198 $this->unstub();
215 - return $this->m_depth;
 199+ return $this->m_dataitem->getDepth();
216200 }
217201
218202 /// Return the concept's query feature bit field (a metric used to estimate computation complexity).
219203 public function getQueryFeatures() {
220204 $this->unstub();
221 - return $this->m_queryfeatures;
 205+ return $this->m_dataitem->getQueryFeatures();
222206 }
223207
224208 /// @deprecated Use setDBkeys(). This method will vanish before SMW 1.6
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SetupLight.php
@@ -111,6 +111,7 @@
112112 $wgAutoloadClasses['SMWDIURI'] = $diDir . 'SMW_DI_URI.php';
113113 $wgAutoloadClasses['SMWDIWikiPage'] = $diDir . 'SMW_DI_WikiPage.php';
114114 $wgAutoloadClasses['SMWDITime'] = $diDir . 'SMW_DI_Time.php';
 115+// $wgAutoloadClasses['SMWDIConcept'] = $diDir . 'SMW_DI_Concept.php';
115116
116117 // Datavalues
117118 $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 @@
143143 $wgAutoloadClasses['SMWDIURI'] = $diDir . 'SMW_DI_URI.php';
144144 $wgAutoloadClasses['SMWDIWikiPage'] = $diDir . 'SMW_DI_WikiPage.php';
145145 $wgAutoloadClasses['SMWDITime'] = $diDir . 'SMW_DI_Time.php';
 146+ $wgAutoloadClasses['SMWDIConcept'] = $diDir . 'SMW_DI_Concept.php';
146147
147148 // Datavalues
148149 $dvDir = $smwgIP . 'includes/datavalues/';

Status & tagging log