r60727 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60726‎ | r60727 | r60728 >
Date:11:36, 6 January 2010
Author:mkroetzsch
Status:deferred
Tags:
Comment:
Added new functions to datavalue API: value classes now can specify their signature (as documented for SMWDataValue), based on which the new store will select a DB table to put them in (if possible).
This obsoletes many special API functions in datavalues that had been used to cover their different shapes, and it decouples DB layout and datatype classes, making SMW yet more modular.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Bool.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Concept.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Container.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_GeoCoords.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Import.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -258,7 +258,80 @@
259259
260260 ///// Get methods /////
261261
 262+
262263 /**
 264+ * Return an array of values that characterize the given datavalue
 265+ * completely, and that are sufficient to reproduce a value of identical
 266+ * content using the function setDBkeys(). The value array must use number
 267+ * keys that agree with the array's natural order (in which the data was
 268+ * added), and the array MUST contain at least one value in any case.
 269+ * Moreover, the order and type of the array's entries must be as described
 270+ * in by getSignature(); see its documentation for details. The only
 271+ * exception are classes that inherit from SMWContainerValue which must
 272+ * adhere to the special format of this class.
 273+ *
 274+ * The array should only contain components required for storing and
 275+ * sorting. It should provide a compact form for the data that is still
 276+ * easy to unserialize into a new object. Many datatypes will use arrays
 277+ * with only one entry here.
 278+ */
 279+ abstract public function getDBkeys();
 280+
 281+ /**
 282+ * Return a signature string that encodes the order and type of the data
 283+ * that is contained in the array given by getDBkeys(). Single letters are
 284+ * used to encode different datatypes. The signature is used to determine
 285+ * how to store data of this kind. The available type letters are:
 286+ * - t for strings of the same maximal length as MediaWiki title names,
 287+ * - l for arbitrarily long strings; searching/sorting with such data may
 288+ * be limited for performance reasons,
 289+ * - w for strings as used in MediaWiki for encoding interwiki prefixes
 290+ * - u for short ("unit") strings; used for units of measurement in SMW
 291+ * - n for namespace numbers (or other similar integers)
 292+ * - f for floating point numbers of double precision
 293+ * - c for the special container format used by SMWContainerValue; if used
 294+ * then the signature must be 'c' without any other fields.
 295+ *
 296+ * Do not use any other letters in signatures of datavalues. For example,
 297+ * a wiki page consists of a title, namespace, interwiki prefix, and a
 298+ * sortkey for ordering it, so its signature is "tnwt". The below default
 299+ * definition provides a workable fallback, but it is recommended to
 300+ * define the signature explicitly in all datavalues that implement
 301+ * getDBkeys() anew.
 302+ */
 303+ public function getSignature() {
 304+ return 't';
 305+ }
 306+
 307+ /**
 308+ * This function specifies the index of the DB key that should be used for
 309+ * sorting values of this type. It refers to the array that is returned by
 310+ * getDBkeys() and specified by getSignature(), where the first index is 0.
 311+ * For example, a wiki page type with signature "tnwt" would set this value
 312+ * to 3 so that page are ordered by their sortkey (the second "t" field).
 313+ * The order that is used (e.g. numeric or lexicographic) is determined by
 314+ * the type of the resepctive field. If no ordering is supported for this
 315+ * data value, then -1 can be returned here.
 316+ */
 317+ public function getValueIndex() {
 318+ return 0;
 319+ }
 320+
 321+ /**
 322+ * This function specifies the index of the DB key that should be used for
 323+ * string-matching values of this type. SMW supports some query conditions
 324+ * that involve string patterns. Since numerical sort fields cannot be used
 325+ * for this, this index might differ from getValueIndex(). Otherwise, all
 326+ * documentation of getValueIndex() applies.
 327+ * @note Any given storage implementation might decide to not support
 328+ * string matching conditions for the specified value if not available for
 329+ * its type.
 330+ */
 331+ public function getLabelIndex() {
 332+ return 0;
 333+ }
 334+
 335+ /**
263336 * Returns a short textual representation for this data value. If the value
264337 * was initialised from a user supplied string, then this original string
265338 * should be reflected in this short version (i.e. no normalisation should
@@ -372,21 +445,6 @@
373446 }
374447
375448 /**
376 - * Return an array of values that characterize the given datavalue completely,
377 - * and that are sufficient to reproduce a value of identical content using the
378 - * function setDBkeys(). The value array must use number keys that agree with
379 - * the array's natural order (in which the data was added), and the array MUST
380 - * contain at least one value in any case.
381 - * Moreover, each entry of the array must be of a basic type, typically string
382 - * or int. Do not use arrays or objects!
383 - * The array should only contain components required for storing, but no derived
384 - * versions of the value. It should provide a compact form for the data that is
385 - * still easy to unserialize into a new object. Many datatypes will use arrays
386 - * with only one entry here.
387 - */
388 - abstract public function getDBkeys();
389 -
390 - /**
391449 * Return the plain wiki version of the value, or
392450 * FALSE if no such version is available. The returned
393451 * string suffices to reobtain the same DataValue
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_GeoCoords.php
@@ -193,6 +193,18 @@
194194 return array($this->m_lat . ',' . $this->m_long);
195195 }
196196
 197+ public function getSignature() {
 198+ return 't';
 199+ }
 200+
 201+ public function getValueIndex() {
 202+ return 0;
 203+ }
 204+
 205+ public function getLabelIndex() {
 206+ return 0;
 207+ }
 208+
197209 public function getWikiValue(){
198210 $this->unstub();
199211 return $this->m_wikivalue;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php
@@ -245,6 +245,18 @@
246246 return array($this->m_uri);
247247 }
248248
 249+ public function getSignature() {
 250+ return 't';
 251+ }
 252+
 253+ public function getValueIndex() {
 254+ return 0;
 255+ }
 256+
 257+ public function getLabelIndex() {
 258+ return 0;
 259+ }
 260+
249261 public function getWikiValue(){
250262 $this->unstub();
251263 return $this->m_value;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php
@@ -67,6 +67,18 @@
6868 return array($this->m_value);
6969 }
7070
 71+ public function getSignature() {
 72+ return 't';
 73+ }
 74+
 75+ public function getValueIndex() {
 76+ return 0;
 77+ }
 78+
 79+ public function getLabelIndex() {
 80+ return 0;
 81+ }
 82+
7183 public function getWikiValue(){
7284 $this->unstub();
7385 return $this->m_value;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Import.php
@@ -157,6 +157,18 @@
158158 return array($this->m_namespace . ' ' . $this->m_section . ' ' . $this->m_uri);
159159 }
160160
 161+ public function getSignature() {
 162+ return 't';
 163+ }
 164+
 165+ public function getValueIndex() {
 166+ return 0;
 167+ }
 168+
 169+ public function getLabelIndex() {
 170+ return 0;
 171+ }
 172+
161173 public function getWikiValue(){
162174 $this->unstub();
163175 return $this->m_value;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Container.php
@@ -65,6 +65,18 @@
6666 return array($data);
6767 }
6868
 69+ public function getSignature() {
 70+ return 'c';
 71+ }
 72+
 73+ public function getValueIndex() {
 74+ return -1;
 75+ }
 76+
 77+ public function getLabelIndex() {
 78+ return -1;
 79+ }
 80+
6981 public function getHash() {
7082 if ( $this->isValid() ) {
7183 return $this->m_data->getHash();
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php
@@ -240,6 +240,18 @@
241241 return $this->isVisible()?array($this->m_wikipage->getDBkey()):array($this->m_propertyid);
242242 }
243243
 244+ public function getSignature() {
 245+ return 't';
 246+ }
 247+
 248+ public function getValueIndex() {
 249+ return 0;
 250+ }
 251+
 252+ public function getLabelIndex() {
 253+ return 0;
 254+ }
 255+
244256 public function getWikiValue() {
245257 return $this->isVisible()?(($this->isInverse()?'-':'') . $this->m_wikipage->getWikiValue()):'';
246258 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php
@@ -76,7 +76,7 @@
7777
7878 protected function parseDBkeys($args) {
7979 $this->m_value = $args[0];
80 - $this->m_unit = array_key_exists(1,$args)?$args[1]:'';
 80+ $this->m_unit = array_key_exists(2,$args)?$args[2]:'';
8181 $this->m_caption = false;
8282 $this->m_unitin = false;
8383 $this->makeUserValue();
@@ -88,7 +88,7 @@
8989 $this->m_outformat = $formatstring;
9090 if ( ($formatstring != $oldformat) && $this->isValid() ) {
9191 // recompute conversion if outputformat is changed after initialisation
92 - $this->m_stubvalues = array($this->m_value, $this->m_unit);
 92+ $this->m_stubvalues = array($this->m_value, $this->m_value, $this->m_unit);
9393 }
9494 }
9595
@@ -163,9 +163,21 @@
164164 public function getDBkeys() {
165165 $this->unstub();
166166 $this->convertToMainUnit();
167 - return array($this->m_value, $this->m_unit);
 167+ return array($this->m_value, intval($this->m_value), $this->m_unit);
168168 }
169169
 170+ public function getSignature() {
 171+ return 'tfu';
 172+ }
 173+
 174+ public function getValueIndex() {
 175+ return 1;
 176+ }
 177+
 178+ public function getLabelIndex() {
 179+ return 0;
 180+ }
 181+
170182 public function getWikiValue(){
171183 $this->unstub();
172184 return $this->m_wikivalue;
@@ -179,7 +191,7 @@
180192
181193 public function getUnit() {
182194 $values = $this->getDBkeys();
183 - return $values[1];
 195+ return $values[2];
184196 }
185197
186198 public function getHash() {
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Bool.php
@@ -92,26 +92,30 @@
9393 }
9494
9595 public function getLongWikiText($linked = NULL) {
96 - if (!$this->isValid()) {
97 - return $this->getErrorText();
98 - } else {
99 - return $this->m_stdcaption;
100 - }
 96+ return $this->isValid()?$this->m_stdcaption:$this->getErrorText();
10197 }
10298
10399 public function getLongHTMLText($linker = NULL) {
104 - if (!$this->isValid()) {
105 - return $this->getErrorText();
106 - } else {
107 - return $this->m_stdcaption;
108 - }
 100+ return $this->isValid()?$this->m_stdcaption:$this->getErrorText();
109101 }
110102
111103 public function getDBkeys() {
112104 $this->unstub();
113 - return $this->m_value?array('1'):array('0');
 105+ return $this->m_value?array('1',1):array('0',0);
114106 }
115107
 108+ public function getSignature() {
 109+ return 'tn';
 110+ }
 111+
 112+ public function getValueIndex() {
 113+ return 1;
 114+ }
 115+
 116+ public function getLabelIndex() {
 117+ return 0;
 118+ }
 119+
116120 public function getWikiValue(){
117121 $this->unstub();
118122 return $this->m_stdcaption;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Concept.php
@@ -75,6 +75,18 @@
7676 return array($this->m_concept, $this->m_docu, $this->m_queryfeatures, $this->m_size, $this->m_depth);
7777 }
7878
 79+ public function getSignature() {
 80+ return 'tllnnn';
 81+ }
 82+
 83+ public function getValueIndex() {
 84+ return 0;
 85+ }
 86+
 87+ public function getLabelIndex() {
 88+ return 0;
 89+ }
 90+
7991 public function getWikiValue(){
8092 $this->unstub();
8193 return str_replace(array('&lt;','&gt;','&amp;'),array('<','>','&'), $this->m_concept);
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php
@@ -362,9 +362,22 @@
363363 if ($this->m_xsdvalue === false) {
364364 $this->m_xsdvalue = $this->m_year."/".$this->m_month."/".$this->m_day."T".$this->m_time;
365365 }
366 - return array($this->m_xsdvalue);
 366+ $this->createJD();
 367+ return array($this->m_xsdvalue,$this->m_jd);
367368 }
368369
 370+ public function getSignature() {
 371+ return 'tf';
 372+ }
 373+
 374+ public function getValueIndex() {
 375+ return 1;
 376+ }
 377+
 378+ public function getLabelIndex() {
 379+ return 0;
 380+ }
 381+
369382 public function getNumericValue() {
370383 $this->unstub();
371384 $this->createJD();
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
@@ -185,6 +185,18 @@
186186 return array($this->m_dbkeyform, $this->m_namespace, $this->m_interwiki, $this->getSortkey());
187187 }
188188
 189+ public function getSignature() {
 190+ return 'tnwt';
 191+ }
 192+
 193+ public function getValueIndex() {
 194+ return 3;
 195+ }
 196+
 197+ public function getLabelIndex() {
 198+ return 3;
 199+ }
 200+
189201 public function getWikiValue() {
190202 $this->unstub();
191203 if ($this->m_fixNamespace != NS_MAIN) { // no explicit namespace needed!
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php
@@ -181,6 +181,18 @@
182182 return ($this->isValid())?array($this->getDBkey()):array(false);
183183 }
184184
 185+ public function getSignature() {
 186+ return 't';
 187+ }
 188+
 189+ public function getValueIndex() {
 190+ return 0;
 191+ }
 192+
 193+ public function getLabelIndex() {
 194+ return 0;
 195+ }
 196+
185197 public function getWikiValue() {
186198 return implode('; ', $this->getTypeLabels());
187199 }

Status & tagging log