r60790 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60789‎ | r60790 | r60791 >
Date:10:04, 7 January 2010
Author:mkroetzsch
Status:deferred
Tags:
Comment:
Deprecated special function "getNumericValue" since it is no longer needed with the improved datavalue API based on DBkeys/signature.

The function will remain available for SMW 1.5.0, but is no longer used in SMW code.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Bool.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_GeoCoords.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Linear.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Linear.php
@@ -173,7 +173,7 @@
174174 $numdv = SMWDataValueFactory::newTypeIDValue('_num'); // used for parsing the factors
175175 foreach ($factors as $dv) {
176176 $numdv->setUserValue($dv->getWikiValue());
177 - if (!$numdv->isValid() || ($numdv->getNumericValue() === 0)) {
 177+ if (!$numdv->isValid() || ($numdv->getValueKey() === 0)) {
178178 continue; // ignore problematic conversions
179179 }
180180 $unit_aliases = preg_split('/\s*,\s*/u', $numdv->getUnit());
@@ -182,11 +182,11 @@
183183 $unit = $this->normalizeUnit($unit);
184184 if ($first) {
185185 $unitid = $unit;
186 - if ( $numdv->getNumericValue() == 1 ) { // add main unit to front of array (displyed first)
 186+ if ( $numdv->getValueKey() == 1 ) { // add main unit to front of array (displyed first)
187187 $this->m_mainunit = $unit;
188 - $this->m_unitfactors = array( $unit => $numdv->getNumericValue() ) + $this->m_unitfactors;
 188+ $this->m_unitfactors = array( $unit => $numdv->getValueKey() ) + $this->m_unitfactors;
189189 } else { // non-main units are not ordered -- they might come out in any way the DB likes (can be modified via display units)
190 - $this->m_unitfactors[$unit] = $numdv->getNumericValue();
 190+ $this->m_unitfactors[$unit] = $numdv->getValueKey();
191191 }
192192 $first = false;
193193 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -506,21 +506,6 @@
507507 abstract public function getWikiValue();
508508
509509 /**
510 - * Return the numeric representation of the value that can be
511 - * used for ordering values of this datatype. The given number
512 - * can be approximate and need not completely reflect the contents
513 - * of a data value. It merely is used for comparing two such
514 - * values. NULL is returned if no such number is provided, but
515 - * it is recommended to use isNumeric() to check for this case.
516 - * @note Storage implementations can assume numerical values to
517 - * be completely determined from the given datavalue (i.e. from the
518 - * vector returned by getDBkeys().
519 - */
520 - public function getNumericValue() {
521 - return null;
522 - }
523 -
524 - /**
525510 * Return a short string that unambiguously specify the type of this value.
526511 * This value will globally be used to identify the type of a value (in spite
527512 * of the class it actually belongs to, which can still implement various types).
@@ -568,15 +553,34 @@
569554 }
570555
571556 /**
572 - * Return TRUE if values of the given type generally have a numeric version,
573 - * i.e. if getNumericValue returns a meaningful numeric sortkey.
574 - * Possibly overwritten by subclasses.
 557+ * Convenience method that checks if the value that is used to sort data of
 558+ * this type is numeric.
575559 */
576560 public function isNumeric() {
577 - return false;
 561+ $sig = $this->getSignature();
 562+ $validx = $this->getValueIndex();
 563+ if ( ($validx >= 0) && ($validx < strlen($sig)) ) {
 564+ return ( ( $sig{$validx} == 'n' ) || ( $sig{$validx} == 'f' ) );
 565+ } else {
 566+ return false;
 567+ }
578568 }
579569
580570 /**
 571+ * Convenience method that returns the DB key that holds the value that is
 572+ * to be used for sorting data of this kind. If this datatype does not
 573+ * support sorting, then null is returned here.
 574+ */
 575+ public function getValueKey() {
 576+ $dbkeys = $this->getDBkeys();
 577+ if ( array_key_exists($this->getValueIndex(), $dbkeys) ) {
 578+ return $dbkeys[$this->getValueIndex()];
 579+ } else {
 580+ return null;
 581+ }
 582+ }
 583+
 584+ /**
581585 * Return TRUE if a value was defined and understood by the given type,
582586 * and false if parsing errors occured or no value was given.
583587 */
@@ -691,6 +695,16 @@
692696 return ''; // empty unit
693697 }
694698
 699+ /**
 700+ * Alias for getValueKey(). If you use this function and test if its result
 701+ * is null, then use isNumeric() instead to check this. If this is done,
 702+ * getValueKey() can be used instead.
 703+ * @deprecated This function will vanish before SMW 1.6.
 704+ */
 705+ public function getNumericValue() {
 706+ return $this->getValueKey();
 707+ }
 708+
695709 }
696710
697711
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php
@@ -361,7 +361,7 @@
362362 $excluded_dates = explode(';', $value);
363363 foreach ($excluded_dates as $date_str) {
364364 $date = SMWDataValueFactory::newTypeIDValue('_dat', $date_str);
365 - $excluded_dates_jd[] = $date->getNumericValue();
 365+ $excluded_dates_jd[] = $date->getValueKey();
366366 }
367367 }
368368 }
@@ -376,11 +376,11 @@
377377 if (is_null($period) || $period < 1 || $period > 500)
378378 $period = 1;
379379 // get the Julian day value for both the start and end date
380 - $start_date_jd = $start_date->getNumericValue();
 380+ $start_date_jd = $start_date->getValueKey();
381381 if (! is_null($end_date))
382 - $end_date_jd = $end_date->getNumericValue();
 382+ $end_date_jd = $end_date->getValueKey();
383383 $cur_date = $start_date;
384 - $cur_date_jd = $start_date->getNumericValue();
 384+ $cur_date_jd = $start_date->getValueKey();
385385 $i = 0;
386386 $reached_end_date = false;
387387 do {
@@ -408,7 +408,7 @@
409409 }
410410 $date_str = "$cur_year-$cur_month-$cur_day $cur_time";
411411 $cur_date = SMWDataValueFactory::newTypeIDValue('_dat', $date_str);
412 - $cur_date_jd = $cur_date->getNumericValue();
 412+ $cur_date_jd = $cur_date->getValueKey();
413413 } else { // $unit == 'day' or 'week'
414414 // assume 'day' if it's none of the above
415415 $cur_date_jd += ($unit === 'week') ? 7 * $period : $period;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_GeoCoords.php
@@ -244,7 +244,7 @@
245245 if ($angles[$i] !== false) {
246246 $numvalue->setUserValue($angles[$i]);
247247 if ($numvalue->isValid() && ($numvalue->getUnit() == '')) {
248 - $res += $numvalue->getNumericValue() / $factor;
 248+ $res += $numvalue->getValueKey() / $factor;
249249 } else {
250250 $this->addError(wfMsgForContent('smw_nofloat', $angles[$i]));
251251 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php
@@ -79,7 +79,7 @@
8080 $values[] = '"'.$value->getXSDValue().'"';
8181 break;
8282 case '_num':
83 - $values[] = $value->getNumericValue($outputmode,$this->getLinker(0));
 83+ $values[] = $value->getValueKey();
8484 break;
8585 case '_dat':
8686 $values[] = "\"".$value->getYear()."-".str_pad($value->getMonth(),2,'0',STR_PAD_LEFT)."-".str_pad($value->getDay(),2,'0',STR_PAD_LEFT)." ".$value->getTimeString()."\"";
@@ -99,7 +99,7 @@
100100 $count++;
101101 }
102102 $valuestack[] = '"uri" : "'.$wgServer.$wgScriptPath.'/index.php?title='.$prefixedtext.'"';
103 -
 103+
104104 //try to determine type/category
105105 $catlist = array();
106106 $dbr = &wfGetDB(DB_SLAVE);
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php
@@ -52,8 +52,8 @@
5353 $first = true;
5454 while ( ($object = $field->getNextObject()) !== false ) {
5555 if ($first) {
56 - if ($object->isNumeric()) { // use numeric sortkey
57 - $result .= '<span class="smwsortkey">' . $object->getNumericValue() . '</span>';
 56+ if ($object->isNumeric()) { // additional hidden sortkey for numeric entries
 57+ $result .= '<span class="smwsortkey">' . $object->getValueKey() . '</span>';
5858 }
5959 $first = false;
6060 } else {
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php
@@ -163,7 +163,7 @@
164164 public function getDBkeys() {
165165 $this->unstub();
166166 $this->convertToMainUnit();
167 - return array($this->m_value, intval($this->m_value), $this->m_unit);
 167+ return array($this->m_value, floatval($this->m_value), $this->m_unit);
168168 }
169169
170170 public function getSignature() {
@@ -183,12 +183,6 @@
184184 return $this->m_wikivalue;
185185 }
186186
187 - public function getNumericValue() {
188 - $this->unstub();
189 - $this->convertToMainUnit();
190 - return $this->m_value;
191 - }
192 -
193187 public function getUnit() {
194188 $values = $this->getDBkeys();
195189 return $values[2];
@@ -214,10 +208,6 @@
215209 return array((string)$this->m_value, (string)round($this->m_value), $this->m_unit);
216210 }
217211
218 - public function isNumeric() {
219 - return true;
220 - }
221 -
222212 public function getExportData() {
223213 $this->unstub();
224214 if ($this->isValid()) {
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Bool.php
@@ -121,15 +121,6 @@
122122 return $this->m_stdcaption;
123123 }
124124
125 - public function getNumericValue() {
126 - $this->unstub();
127 - return $this->m_value?'1':'0';
128 - }
129 -
130 - public function isNumeric() {
131 - return true;
132 - }
133 -
134125 public function getExportData() {
135126 if ($this->isValid()) {
136127 $xsdvalue = $this->m_value?'true':'false';
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php
@@ -378,12 +378,6 @@
379379 return 0;
380380 }
381381
382 - public function getNumericValue() {
383 - $this->unstub();
384 - $this->createJD();
385 - return $this->m_jd;
386 - }
387 -
388382 public function getWikiValue() {
389383 $this->unstub();
390384 return $this->m_wikivalue;
@@ -398,10 +392,6 @@
399393 }
400394 }
401395
402 - public function isNumeric() {
403 - return true;
404 - }
405 -
406396 public function getExportData() {
407397 if ($this->isValid()) {
408398 $lit = new SMWExpLiteral($this->getXMLSchemaDate(), $this, 'http://www.w3.org/2001/XMLSchema#dateTime');

Status & tagging log