r18179 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r18178‎ | r18179 | r18180 >
Date:11:19, 5 December 2006
Author:skierpage
Status:old
Tags:
Comment:
Support formatting booleans in inline queries; remove DEBUG output.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Datatype.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Datatype.php
@@ -166,7 +166,6 @@
167167 SMWTypeHandlerFactory::$typeHandlersByLabel[$typelabel] = $instance;
168168 return SMWTypeHandlerFactory::$typeHandlersByLabel[$typelabel];
169169 }
170 - // if (count($conversionFactors) == 0) print "DEBUG: in getTypeHandlerByLabel(), tried and failed to find conversionFactors for $typelabel, this shouldn't happen!!?'\n<br />";
171170
172171 return new SMWErrorTypeHandler(wfMsgForContent('smw_unknowntype',$typelabel));
173172 }
@@ -187,7 +186,6 @@
188187 if (count($typearray)==1) {
189188 SMWTypeHandlerFactory::$typeHandlersByAttribute[$attribute] =
190189 SMWTypeHandlerFactory::getTypeHandlerByLabel($typearray[0]);
191 - // print "DEBUG: getTypeHandler() found value $typearray[0] with new smwfGetSpecialPropertyValues\n<br />";
192190 } elseif (count($typearray)==0) {
193191 SMWTypeHandlerFactory::$typeHandlersByAttribute[$attribute] =
194192 new SMWErrorTypeHandler(wfMsgForContent('smw_notype'));
@@ -248,7 +246,6 @@
249247 if ( ($ttitle !== NULL) && ($ttitle->exists()) ) {
250248 $result = smwfGetSpecialPropertyValues($ttitle, SMW_SP_CONVERSION_FACTOR);
251249 if (count($result) == 0) {
252 - // print "DEBUG: getConversionFactors() for $type found nothing!<br />\n";
253250 $result = array();
254251 }
255252 }
@@ -281,7 +278,10 @@
282279 } // SMWTypeHandlerFactory
283280
284281 //*** Make other typehandlers known that are shipped with SMW ***//
285 -
 282+/**
 283+ * If you add a typehandler in a separate file from this one (SMW_Datatype.php)
 284+ * then you must add it to this list!
 285+ */
286286 // Integer
287287 SMWTypeHandlerFactory::announceTypeHandler($smwgContLang->getDatatypeLabel('smw_int'),'int','Integer','SMWIntegerTypeHandler');
288288 // URLs etc.
@@ -546,6 +546,7 @@
547547 $xsdvalue = -1; // initialize to failure
548548 // See http://en.wikipedia.org/wiki/Boolean_datatype
549549 // TODO: To save code, trim values before they get to processValue().
 550+
550551 $vlc = strtolower(trim($value));
551552 if ($vlc!='') { //do not accept empty strings
552553 // Look for universal true/false and 1/0,
@@ -564,10 +565,23 @@
565566 } else {
566567 $datavalue->setError(wfMsgForContent('smw_emptystring'));
567568 }
 569+
568570 if ($xsdvalue === 'true' || $xsdvalue === 'false') {
569571 // Store numeric 1 or 0 as number.
570572 $datavalue->setProcessedValues($value, $xsdvalue, $xsdvalue === 'true' ? 1 : 0);
571 - $datavalue->setPrintoutString($xsdvalue);
 573+ // For a boolean, "units" is really a format from an inline query
 574+ // rather than the units of a float.
 575+ $desiredUnits = $datavalue->getDesiredUnits();
 576+ // Determine the user-visible string.
 577+ if (count($desiredUnits) ==0) {
 578+ $datavalue->setPrintoutString($xsdvalue);
 579+ } else {
 580+ // The units is a string for 'true', a comma, and a string for 'false'.
 581+ foreach ($desiredUnits as $wantedFormat) {
 582+ list($true_text, $false_text) = explode(',', $wantedFormat, 2);
 583+ $datavalue->setPrintoutString($xsdvalue === 'true' ? $true_text : $false_text);
 584+ }
 585+ }
572586 $datavalue->addQuicksearchLink();
573587 }
574588 return true;

Status & tagging log