r37116 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37115‎ | r37116 | r37117 >
Date:16:32, 5 July 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
Separate datavalue object for handling concept descriptions, support for short docu per concept
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Concept.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -153,7 +153,7 @@
154154 break;
155155 case SMW_SQL2_CONC2:
156156 $from = 'smw_conc2';
157 - $select = 'concept_txt as value';
 157+ $select = 'concept_txt as concept, concept_docu as docu';
158158 $where = 's_id=' . $db->addQuotes($sid);
159159 break;
160160 }
@@ -194,7 +194,7 @@
195195 $this->m_semdata[$sid]->addSpecialValue(SMW_SP_INSTANCE_OF, $dv);
196196 } elseif ($task == SMW_SQL2_CONC2) {
197197 $dv = SMWDataValueFactory::newSpecialValue(SMW_SP_CONCEPT_DESC);
198 - $dv->setXSDValue($row->value, '');
 198+ $dv->setValues($row->concept, $row->docu);
199199 $this->m_semdata[$sid]->addSpecialValue(SMW_SP_CONCEPT_DESC, $dv);
200200 }
201201 }
@@ -784,7 +784,9 @@
785785 }
786786 $value = end($propertyValueArray); // only one value per page!
787787 if ( ($value->isValid()) ) {
788 - $up_conc2[] = array('s_id' => $sid, 'concept_txt' => $value->getXSDValue());
 788+ $up_conc2[] = array('s_id' => $sid,
 789+ 'concept_txt' => $value->getXSDValue(),
 790+ 'concept_docu' => $value->getDocu());
789791 }
790792 break;
791793 default: // normal special value
@@ -1097,7 +1099,8 @@
10981100
10991101 $this->setupTable($smw_conc2, // concept descriptions
11001102 array('s_id' => 'INT(8) UNSIGNED NOT NULL KEY',
1101 - 'concept_txt' => 'MEDIUMBLOB'), $db, $verbose);
 1103+ 'concept_txt' => 'MEDIUMBLOB',
 1104+ 'concept_docu'=> 'MEDIUMBLOB'), $db, $verbose);
11021105 $this->setupIndex($smw_conc2, array('s_id'), $db);
11031106
11041107 $this->reportProgress("Database initialised successfully.\n",$verbose);
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -115,7 +115,7 @@
116116 $result = SMWDataValueFactory::newTypeIDValue('_wpg', $value, $caption);
117117 break;
118118 case SMW_SP_CONCEPT_DESC:
119 - $result = SMWDataValueFactory::newTypeIDValue('_txt', $value, $caption);
 119+ $result = SMWDataValueFactory::newTypeIDValue('__con', $value, $caption);
120120 break;
121121 default:
122122 /// NOTE: unstable hook, future versions might have better ways of enabling extensions to add properties
@@ -252,6 +252,7 @@
253253 $wgAutoloadClasses['SMWTimeValue'] = $smwgIP . '/includes/SMW_DV_Time.php';
254254 $wgAutoloadClasses['SMWGeoCoordsValue'] = $smwgIP . '/includes/SMW_DV_GeoCoords.php';
255255 $wgAutoloadClasses['SMWBoolValue'] = $smwgIP . '/includes/SMW_DV_Bool.php';
 256+ $wgAutoloadClasses['SMWConceptValue'] = $smwgIP . '/includes/SMW_DV_Concept.php';
256257 SMWDataValueFactory::$m_typeclasses = array(
257258 '_txt' => 'SMWStringValue',
258259 '_cod' => 'SMWStringValue',
@@ -268,7 +269,8 @@
269270 '__typ' => 'SMWTypesValue',
270271 '__lin' => 'SMWLinearValue',
271272 '__nry' => 'SMWNAryValue',
272 - '__err' => 'SMWErrorValue'
 273+ '__err' => 'SMWErrorValue',
 274+ '__con' => 'SMWConceptValue'
273275 );
274276
275277 wfRunHooks( 'smwInitDatatypes' );
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Concept.php
@@ -0,0 +1,94 @@
 2+<?php
 3+
 4+/**
 5+ * This datavalue is used as a container for concept descriptions as used
 6+ * on Concept pages with the #concept parserfunction. It has a somewhat
 7+ * non-standard interface as compared to other datavalues, but this is not
 8+ * an issue.
 9+ *
 10+ * @author Markus Krötzsch
 11+ * @note AUTOLOADED
 12+ */
 13+class SMWConceptValue extends SMWDataValue {
 14+
 15+ protected $m_concept = ''; // XML-safe, HTML-safe, Wiki-compatible concept expression (query string)
 16+ protected $m_docu = ''; // text description of concept, can only be set by special function "setvalues"
 17+
 18+ protected function parseUserValue($value) {
 19+ // this function is normally not used for this class, not created from user input directly
 20+ $this->m_concept = smwfXMLContentEncode($value);
 21+ if ($this->m_caption === false) {
 22+ $this->m_caption = $value;
 23+ }
 24+ return true;
 25+ }
 26+
 27+ protected function parseXSDValue($value, $unit) {
 28+ // normally not used, store should use setValues
 29+ $this->m_concept = $value;
 30+ $this->m_caption = $this->m_concept; // this is our output text
 31+ }
 32+
 33+ public function getShortWikiText($linked = NULL) {
 34+ return $this->m_caption;
 35+ }
 36+
 37+ public function getShortHTMLText($linker = NULL) {
 38+ return $this->getShortWikiText($linker); // should be save (based on xsdvalue)
 39+ }
 40+
 41+ public function getLongWikiText($linked = NULL) {
 42+ if (!$this->isValid()) {
 43+ return $this->getErrorText();
 44+ } else {
 45+ return $this->m_caption;
 46+ }
 47+ }
 48+
 49+ public function getLongHTMLText($linker = NULL) {
 50+ if (!$this->isValid()) {
 51+ return $this->getErrorText();
 52+ } else {
 53+ return $this->m_caption; // should be save (based on xsdvalue)
 54+ }
 55+ }
 56+
 57+ public function getXSDValue() {
 58+ return $this->m_concept;
 59+ }
 60+
 61+ public function getWikiValue(){
 62+ return $this->m_concept;
 63+ }
 64+
 65+ public function getExportData() {
 66+ if ($this->isValid()) {
 67+// $lit = new SMWExpLiteral(smwfHTMLtoUTF8($this->m_value), $this, 'http://www.w3.org/2001/XMLSchema#string');
 68+// return new SMWExpData($lit);
 69+ return NULL; /// TODO
 70+ } else {
 71+ return NULL;
 72+ }
 73+ }
 74+
 75+ /**
 76+ * Special features for Type:Code formating.
 77+ */
 78+ protected function getCodeDisplay($value, $scroll = false) {
 79+ $result = str_replace( array('<', '>', ' ', '://', '=', "'"), array('&lt;', '&gt;', '&nbsp;', '<!-- -->://<!-- -->', '&#x003D;', '&#x0027;'), $value);
 80+ if ($scroll) {
 81+ $result = "<div style=\"height:5em; overflow:auto;\">$result</div>";
 82+ }
 83+ return "<pre>$result</pre>";
 84+ }
 85+
 86+ public function setValues($concept, $docu) {
 87+ $this->setUserValue($concept); // must be called to make object valid (parent implementation)
 88+ $this->m_docu = $docu?smwfXMLContentEncode($docu):'';
 89+ }
 90+
 91+ public function getDocu() {
 92+ return $this->m_docu;
 93+ }
 94+
 95+}
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Concept.php
___________________________________________________________________
Added: svn:eol-style
196 + native
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -320,10 +320,13 @@
321321 // process input:
322322 $params = func_get_args();
323323 array_shift( $params ); // we already know the $parser ...
324 - $concept_input = array_shift( $params ); // use only first parameter, ignore rest (may get meaning later)
 324+ $concept_input = array_shift( $params ); // use first parameter as concept (query) string
325325 $query = SMWQueryProcessor::createQuery($concept_input, array('limit' => -1), SMWQueryProcessor::CONCEPT_DESC);
326 - $conceptText = $query->getDescription()->getQueryString();
327 - $dv = SMWDataValueFactory::newSpecialValue(SMW_SP_CONCEPT_DESC, $conceptText);
 326+ $concept_text = $query->getDescription()->getQueryString();
 327+ $concept_docu = array_shift( $params ); // second parameter, if any, might be a description
 328+
 329+ $dv = SMWDataValueFactory::newSpecialValue(SMW_SP_CONCEPT_DESC);
 330+ $dv->setValues($concept_text, $concept_docu);
328331 SMWFactbox::$semdata->addSpecialValue(SMW_SP_CONCEPT_DESC,$dv);
329332
330333 // display concept box:
@@ -333,8 +336,9 @@
334337 smwfRequireHeadItem(SMW_HEADER_STYLE);
335338 $result = '<div class="smwfact"><span class="smwfactboxhead">' . wfMsgForContent('smw_concept_description',$title->getText()) .
336339 //(count($query->getErrors())>0?' ' . smwfEncodeMessages($query->getErrors()):'') . // errors are shown by $resultlink anyway
337 - '</span> &nbsp;&nbsp;&nbsp;' . $resultlink . '<br/>' .
338 - '<pre>' . str_replace('[', '&#x005B;', $conceptText) . '</pre></div>';
 340+ '</span> &nbsp;&nbsp;&nbsp;' . $resultlink . '<br />' .
 341+ ($concept_docu?"<p>$concept_docu</p>":'') .
 342+ '<pre>' . str_replace('[', '&#x005B;', $concept_text) . '</pre></div>';
339343 return $result;
340344 }
341345

Status & tagging log