http://www.mediawiki.org/wiki/Special:Code/MediaWiki/66313

Revision: 66313
Author:   jeroendedauw
Date:     2010-05-12 22:38:29 +0000 (Wed, 12 May 2010)

Log Message:
-----------
Changes for 1.5.1
* Removed support for multiple value and label indexes as the desired 
functionality can be obtained easier

Modified Paths:
--------------
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Bool.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Concept.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Container.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Import.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_SimpleWikiPage.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_TypeList.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
    trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
    trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
    trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
    
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
    trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStoreLight.php

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Bool.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Bool.php 2010-05-12 
22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Bool.php 2010-05-12 
22:38:29 UTC (rev 66313)
@@ -108,12 +108,12 @@
                return 'tn';
        }
 
-       public function getValueIndexes() {
-               return array( 1 );
+       public function getValueIndex() {
+               return 1;
        }
 
-       public function getLabelIndexes() {
-               return array( 0 );
+       public function getLabelIndex() {
+               return 0;
        }
 
        public function getWikiValue() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Concept.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Concept.php      
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Concept.php      
2010-05-12 22:38:29 UTC (rev 66313)
@@ -79,12 +79,12 @@
                return 'tllnnn';
        }
 
-       public function getValueIndexes() {
-               return array( 0 );
+       public function getValueIndex() {
+               return 0;
        }
 
-       public function getLabelIndexes() {
-               return array( 0 );
+       public function getLabelIndex() {
+               return 0;
        }
 
        public function getWikiValue() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Container.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Container.php    
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Container.php    
2010-05-12 22:38:29 UTC (rev 66313)
@@ -69,12 +69,12 @@
                return 'c';
        }
 
-       public function getValueIndexes() {
-               return array();
+       public function getValueIndex() {
+               return -1;
        }
 
-       public function getLabelIndexes() {
-               return array();
+       public function getLabelIndex() {
+               return -1;
        }
 
        public function getHash() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Import.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Import.php       
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Import.php       
2010-05-12 22:38:29 UTC (rev 66313)
@@ -161,12 +161,12 @@
                return 't';
        }
 
-       public function getValueIndexes() {
-               return array( 0 );
+       public function getValueIndex() {
+               return 0;
        }
 
-       public function getLabelIndexes() {
-               return array( 0 );
+       public function getLabelIndex() {
+               return 0;
        }
 
        public function getWikiValue() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php       
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php       
2010-05-12 22:38:29 UTC (rev 66313)
@@ -170,12 +170,12 @@
                return 'tfu';
        }
 
-       public function getValueIndexes() {
-               return array( 1 );
+       public function getValueIndex() {
+               return 1;
        }
 
-       public function getLabelIndexes() {
-               return array( 0 );
+       public function getLabelIndex() {
+               return 0;
        }
 
        public function getWikiValue() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php     
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php     
2010-05-12 22:38:29 UTC (rev 66313)
@@ -245,12 +245,12 @@
                return 't';
        }
 
-       public function getValueIndexes() {
-               return array( 0 );
+       public function getValueIndex() {
+               return 0;
        }
 
-       public function getLabelIndexes() {
-               return array( 0 );
+       public function getLabelIndex() {
+               return 0;
        }
 
        public function getWikiValue() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_SimpleWikiPage.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_SimpleWikiPage.php       
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_SimpleWikiPage.php       
2010-05-12 22:38:29 UTC (rev 66313)
@@ -40,12 +40,12 @@
                return 't';
        }
 
-       public function getValueIndexes() {
-               return array( 1 );
+       public function getValueIndex() {
+               return 1;
        }
 
-       public function getLabelIndexes() {
-               return array( 1 );
+       public function getLabelIndex() {
+               return 1;
        }
 
 }
\ No newline at end of file

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php       
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php       
2010-05-12 22:38:29 UTC (rev 66313)
@@ -75,16 +75,16 @@
         * For perfomance reasons, long text data like _txt and _cod does not
         * support sorting. This class can be subclassed to change this.
         */
-       public function getValueIndexes() {
-               return array( ( $this->m_typeid == '_txt' || $this->m_typeid == 
'_cod' )  ? - 1 : 0 );
+       public function getValueIndex() {
+               return ( $this->m_typeid == '_txt' || $this->m_typeid == '_cod' 
)  ? - 1 : 0;
        }
 
        /**
         * For perfomance reasons, long text data like _txt and _cod does not
         * support string matching. This class can be subclassed to change this.
         */
-       public function getLabelIndexes() {
-               return array( ( $this->m_typeid == '_txt' || $this->m_typeid == 
'_cod' )  ? - 1 : 0 );
+       public function getLabelIndex() {
+               return ( $this->m_typeid == '_txt' || $this->m_typeid == '_cod' 
)  ? - 1 : 0;
        }
 
        public function getWikiValue() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php 2010-05-12 
22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php 2010-05-12 
22:38:29 UTC (rev 66313)
@@ -517,12 +517,12 @@
                return 'tf';
        }
 
-       public function getValueIndexes() {
-               return array( 1 );
+       public function getValueIndex() {
+               return 1;
        }
 
-       public function getLabelIndexes() {
-               return array( 0 );
+       public function getLabelIndex() {
+               return 0;
        }
 
        public function getWikiValue() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_TypeList.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_TypeList.php     
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_TypeList.php     
2010-05-12 22:38:29 UTC (rev 66313)
@@ -58,12 +58,12 @@
                return 't';
        }
 
-       public function getValueIndexes() {
-               return array( 0 );
+       public function getValueIndex() {
+               return 0;
        }
 
-       public function getLabelIndexes() {
-               return array( 0 );
+       public function getLabelIndex() {
+               return 0;
        }
 
        public function getShortWikiText( $linked = null ) {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php        
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php        
2010-05-12 22:38:29 UTC (rev 66313)
@@ -78,12 +78,12 @@
                return 't';
        }
 
-       public function getValueIndexes() {
-               return array( 0 );
+       public function getValueIndex() {
+               return 0;
        }
 
-       public function getLabelIndexes() {
-               return array( 0 );
+       public function getLabelIndex() {
+               return 0;
        }
 
        public function getWikiValue() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php  2010-05-12 
22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php  2010-05-12 
22:38:29 UTC (rev 66313)
@@ -249,12 +249,12 @@
                return 't';
        }
 
-       public function getValueIndexes() {
-               return array( 0 );
+       public function getValueIndex() {
+               return 0;
        }
 
-       public function getLabelIndexes() {
-               return array( 0 );
+       public function getLabelIndex() {
+               return 0;
        }
 
        public function getWikiValue() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php     
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php     
2010-05-12 22:38:29 UTC (rev 66313)
@@ -192,12 +192,12 @@
                return 'tnwt';
        }
 
-       public function getValueIndexes() {
-               return array( 3 );
+       public function getValueIndex() {
+               return 3;
        }
 
-       public function getLabelIndexes() {
-               return array( 3 );
+       public function getLabelIndex() {
+               return 3;
        }
 
        public function getWikiValue() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php       
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php       
2010-05-12 22:38:29 UTC (rev 66313)
@@ -365,26 +365,26 @@
         * the type of the resepctive field. If no ordering is supported for 
this
         * data value, then -1 can be returned here.
         * 
-        * @return array
+        * @return integer
         */
-       public function getValueIndexes() {
-               return array( 0 );
+       public function getValueIndex() {
+               return 0;
        }
 
        /**
         * This function specifies the index of the DB key that should be used 
for
         * string-matching values of this type. SMW supports some query 
conditions
         * that involve string patterns. Since numerical sort fields cannot be 
used
-        * for this, this index might differ from getValueIndexes(). Otherwise, 
all
-        * documentation of getValueIndexes() applies.
+        * for this, this index might differ from getValueIndex(). Otherwise, 
all
+        * documentation of getValueIndex() applies.
         * @note Any given storage implementation might decide to not support
         * string matching conditions for the specified value if not available 
for
         * its type.
         * 
-        * @return array
+        * @return integer
         */
-       public function getLabelIndexes() {
-               return array( 0 );
+       public function getLabelIndex() {
+               return 0;
        }
 
        /**
@@ -562,24 +562,22 @@
         */
        public function isNumeric() {
                $sig = $this->getSignature();
-               $valueIndexes = $this->getValueIndexes();
+               $valueIndex = $this->getValueIndex();
                
-               return count( $valueIndexes ) == 1 && ( ( $sig { 
$valueIndexes[0] } == 'n' ) || ( $sig { $valueIndexes[0] } == 'f' ) );
+               return $sig { $valueIndex } == 'n' || $sig { $valueIndex } == 
'f';
        }
 
        /**
         * Convenience method that returns the DB key that holds the value that 
is
         * to be used for sorting data of this kind. If this datatype does not
         * support sorting, then null is returned here.
-        * 
-        * TODO //.//
         */
        public function getValueKey() {
                $dbkeys = $this->getDBkeys();
-               $validx = $this->getValueIndexes();
+               $validx = $this->getValueIndex();
                
-               if ( array_key_exists( $validx[0], $dbkeys ) ) {
-                       return $dbkeys[$validx[0]];
+               if ( array_key_exists( $validx, $dbkeys ) ) {
+                       return $dbkeys[$validx];
                } else {
                        return null;
                }

Modified: 
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php     
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php     
2010-05-12 22:38:29 UTC (rev 66313)
@@ -143,15 +143,15 @@
        }
 
        /**
-        * TODO
+        * TODO: replace $fieldName by signature
         * 
         * @param string $tableName
-        * @param array $fieldNames
+        * @param integer $fieldName
         * @param DatabaseBase $dbs
         * 
         * @return false
         */     
-       public function getSQLCondition( $tableName, array $fieldNames, 
DatabaseBase $dbs ) {
+       public function getSQLCondition( $tableName, $fieldName, DatabaseBase 
$dbs ) {
                return false;
        }
 }

Modified: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php       
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php       
2010-05-12 22:38:29 UTC (rev 66313)
@@ -155,35 +155,35 @@
        /// Array to cache signatures of known built-in types. Having this data
        /// here safes us from creating datavalue instances in 
getTypeSignature().
        private static $type_signatures = array(
-               '_txt'  => array( 'l', array(), array() ),  // Text type
-               '_cod'  => array( 'l', array(), array() ),  // Code type
-               '_str'  => array( 't', array( 0 ), array( 0 ) ),    // String 
type
-               '_ema'  => array( 't', array( 0 ), array( 0 ) ),    // Email 
type
-               '_uri'  => array( 't', array( 0 ), array( 0 ) ),    // URL/URI 
type
-               '_anu'  => array( 't', array( 0 ), array( 0 ) ),    // 
Annotation URI type
-               '_tel'  => array( 't', array( 0 ), array( 0 ) ),    // 
Telephone number
-               '_wpg'  => array( 'tnwt', array( 3 ), array( 3 ) ), // Page type
-               '_wpp'  => array( 'tnwt', array( 3 ), array( 3 ) ), // Property 
page type
-               '_wpc'  => array( 'tnwt', array( 3 ), array( 3 ) ), // Category 
page type
-               '_wpf'  => array( 'tnwt', array( 3 ), array( 3 ) ), // Form 
page type (for Semantic Forms)
-               '_num'  => array( 'tfu', array( 1 ), array( 0 ) ),  // Number 
type
-               '_tem'  => array( 'tfu', array( 1 ), array( 0 ) ),  // 
Temperature type
-               '_dat'  => array( 'tf', array( 1 ), array( 0 ) ),   // Time type
-               '_boo'  => array( 't', array( 0 ), array( 0 ) ),    // Boolean 
type
-               '_rec'  => array( 'tnwt', array( 0 ), array() ),// Value list 
type (internal object)
+               '_txt'  => array( 'l', -1, -1 ),  // Text type
+               '_cod'  => array( 'l', -1, -1 ),  // Code type
+               '_str'  => array( 't', 0, 0 ),    // String type
+               '_ema'  => array( 't', 0, 0 ),    // Email type
+               '_uri'  => array( 't', 0, 0 ),    // URL/URI type
+               '_anu'  => array( 't', 0, 0 ),    // Annotation URI type
+               '_tel'  => array( 't', 0, 0 ),    // Telephone number
+               '_wpg'  => array( 'tnwt', 3, 3 ), // Page type
+               '_wpp'  => array( 'tnwt', 3, 3 ), // Property page type
+               '_wpc'  => array( 'tnwt', 3, 3 ), // Category page type
+               '_wpf'  => array( 'tnwt', 3, 3 ), // Form page type (for 
Semantic Forms)
+               '_num'  => array( 'tfu', 1, 0 ),  // Number type
+               '_tem'  => array( 'tfu', 1, 0 ),  // Temperature type
+               '_dat'  => array( 'tf', 1, 0 ),   // Time type
+               '_boo'  => array( 't', 0, 0 ),    // Boolean type
+               '_rec'  => array( 'tnwt', 0, -1 ),// Value list type (internal 
object)
                // Special types are not avaialble directly for users (and have 
no local language name):
-               '__typ' => array( 't', array( 0 ), array( 0 ) ),    // Special 
type page type
-               '__tls' => array( 't', array( 0 ), array( 0 ) ),    // Special 
type page type
-               '__sps' => array( 't', array( 0 ), array( 0 ) ),    // Special 
string type
-               '__spu' => array( 't', array( 0 ), array( 0 ) ),    // Special 
uri type
-               '__sup' => array( 'tnwt', array( 3 ), array( 3 ) ), // Special 
subproperty type
-               '__suc' => array( 'tnwt', array( 3 ), array( 3 ) ), // Special 
subcategory type
-               '__spf' => array( 't', array( 0 ), array( 0 ) ),    // Special 
form type (for Semantic Forms)
-               '__sin' => array( 'tnwt', array( 3 ), array( 3 ) ), // Special 
instance of type
-               '__red' => array( 'tnwt', array( 3 ), array( 3 ) ), // Special 
redirect type
-               '__lin' => array( 'tfu', array( 1 ), array( 0 ) ),  // Special 
linear unit conversion type
-               '__imp' => array( 't', array( 0 ), array( 0 ) ), // Special 
import vocabulary type
-               '__pro' => array( 't', array( 0 ), array( 0 ) ),  // Property 
page type; never be stored as a value (_wpp is used there) but needed for 
sorting
+               '__typ' => array( 't', 0, 0 ),    // Special type page type
+               '__tls' => array( 't', 0, 0 ),    // Special type page type
+               '__sps' => array( 't', 0, 0 ),    // Special string type
+               '__spu' => array( 't', 0, 0 ),    // Special uri type
+               '__sup' => array( 'tnwt', 3, 3 ), // Special subproperty type
+               '__suc' => array( 'tnwt', 3, 3 ), // Special subcategory type
+               '__spf' => array( 't', 0, 0 ),    // Special form type (for 
Semantic Forms)
+               '__sin' => array( 'tnwt', 3, 3 ), // Special instance of type
+               '__red' => array( 'tnwt', 3, 3 ), // Special redirect type
+               '__lin' => array( 'tfu', 1, 0 ),  // Special linear unit 
conversion type
+               '__imp' => array( 't', 0, 0 ), // Special import vocabulary type
+               '__pro' => array( 't', 0, 0 ),  // Property page type; never be 
stored as a value (_wpp is used there) but needed for sorting
        );
 
 ///// Reading methods /////
@@ -385,9 +385,9 @@
                
                if ( !$issubject ) { // Needed to apply sorting/string matching 
in query; only with fixed property.
                        //.// TODO: support multiple value and label indexes.
-                       list( $sig, $valueIndexes, $labelIndexes ) = 
self::getTypeSignature( $object->getPropertyTypeID() );
-                       $valuecolumn = ( array_key_exists( $valueIndexes[0], 
$selectvalues ) ) ? $selectvalues[$valueIndexes[0]] : '';
-                       $labelcolumn = ( array_key_exists( $labelIndexes[0], 
$selectvalues ) ) ? $selectvalues[$labelIndexes[0]] : '';
+                       list( $sig, $valueIndex, $labelIndex ) = 
self::getTypeSignature( $object->getPropertyTypeID() );
+                       $valuecolumn = ( array_key_exists( $valueIndex, 
$selectvalues ) ) ? $selectvalues[$valueIndex] : '';
+                       $labelcolumn = ( array_key_exists( $labelIndex, 
$selectvalues ) ) ? $selectvalues[$labelIndex] : '';
                        $where .= $this->getSQLConditions( $requestoptions, 
$valuecolumn, $labelcolumn, $where != '' );
                } else {
                        $valuecolumn = $labelcolumn = '';
@@ -1590,18 +1590,17 @@
                $result = array();
                $sortres = array();
                
-               //.// TODO: support multiple value and label indexes.
-               list( $sig, $valueIndexes, $labelIndexes ) = 
self::getTypeSignature( reset( $data )->getTypeID() );
+               list( $sig, $valueIndex, $labelIndex ) = 
self::getTypeSignature( reset( $data )->getTypeID() );
                
-               $numeric = ( ( $valueIndexes[0] >= 0 ) && ( strlen( $sig ) > 
$valueIndexes[0] ) &&
-                            ( ( $sig { $valueIndexes[0] } != 'f' ) || ( $sig { 
$valueIndexes[0] } != 'n' ) ) );
+               $numeric = ( ( $valueIndex >= 0 ) && ( strlen( $sig ) > 
$valueIndex ) &&
+                            ( ( $sig { $valueIndex } != 'f' ) || ( $sig { 
$valueIndex } != 'n' ) ) );
                $i = 0;
                
                foreach ( $data as $item ) {
                        $ok = true; // keep datavalue only if this remains true
                        $keys = $item->getDBkeys();
-                       $value = array_key_exists( $valueIndexes[0], $keys ) ? 
$keys[$valueIndexes[0]] : '';
-                       $label = array_key_exists( $labelIndexes[0], $keys ) ? 
$keys[$labelIndexes[0]] : '';
+                       $value = array_key_exists( $valueIndex, $keys ) ? 
$keys[$valueIndex] : '';
+                       $label = array_key_exists( $labelIndex, $keys ) ? 
$keys[$labelIndex] : '';
                        
                        if ( $requestoptions->boundary !== null ) { // apply 
value boundary
                                $strc = $numeric ? 0 : strcmp( $value, 
$requestoptions->boundary );
@@ -1693,7 +1692,7 @@
         * entries: a signature string, the index of the value field, and
         * the index of the label label field. These entries correspond to
         * the results of SMWDataValue::getSignature(),
-        * SMWDatavalue::getValueIndexes(), and SMWDatavalue::getLabelIndexes().
+        * SMWDatavalue::getValueIndex(), and SMWDatavalue::getLabelIndex().
         * @todo Custom unit types (SMWLinearValue) have page names as their
         * type id and are not in the array cache. Can we still determine their
         * signature without creating them?
@@ -1701,7 +1700,7 @@
        public static function getTypeSignature( $typeid ) {
                if ( !array_key_exists( $typeid, self::$type_signatures ) ) {
                        $dv = SMWDataValueFactory::newTypeIDValue( $typeid );
-                       self::$type_signatures[$typeid] = array( 
$dv->getSignature(), $dv->getValueIndexes(), $dv->getLabelIndexes() );
+                       self::$type_signatures[$typeid] = array( 
$dv->getSignature(), $dv->getValueIndex(), $dv->getLabelIndex() );
                }
                
                return self::$type_signatures[$typeid];

Modified: 
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
===================================================================
--- 
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php   
    2010-05-12 22:13:43 UTC (rev 66312)
+++ 
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php   
    2010-05-12 22:38:29 UTC (rev 66313)
@@ -564,7 +564,7 @@
                        return;
                }
                
-               list( $sig, $valueindexes, $labelindexes ) = 
SMWSQLStore2::getTypeSignature( $typeid );
+               list( $sig, $valueindex, $labelindex ) = 
SMWSQLStore2::getTypeSignature( $typeid );
                $sortkey = $property->getDBkey(); // TODO: strictly speaking, 
the DB key is not what we want here, since sortkey is based on a "wiki value"
 
                // *** Basic settings: table, joinfield, and objectfields ***//
@@ -574,7 +574,7 @@
                        if ( ( count( $proptable->objectfields ) == 1 ) && ( 
reset( $proptable->objectfields ) == 'p' ) ) {
                                $query->joinfield = $query->alias . '.' . 
reset( array_keys( $proptable->objectfields ) );
                                $objectfields = array( 's_id' => 'p' );
-                               $valueindexes = $labelindexes = array( 3 ); // 
should normally not change, but let's be strict
+                               $valueindex = $labelindex = 3; // should 
normally not change, but let's be strict
                        } else { // no inverses supported for this property, 
stop here
                                $query->type = SMW_SQL2_NOQUERY;
                                return;
@@ -612,12 +612,12 @@
                                $query->components[$sub] = 
"{$query->alias}.{$objectfield}";
                        }
                } else { // non-page value description; expressive features 
mainly based on value
-                       $this->compileAttributeWhere( $query, $valuedesc, 
$proptable, $valueindexes );
+                       $this->compileAttributeWhere( $query, $valuedesc, 
$proptable, $valueindex );
                        // (no need to pass on $objectfields since they are 
just as in $proptable in this case)
                }
 
                // *** Incorporate ordering if desired ***//
-               if ( ( count( $valueindexes ) > 0 ) && array_key_exists( 
$sortkey, $this->m_sortkeys ) ) {
+               if ( ( $valueindex >= 0 ) && array_key_exists( $sortkey, 
$this->m_sortkeys ) ) {
                        // This code might be overly general: it supports 
datatypes of arbitrary signatures
                        // and valueindex (sortkeys). It can even order pages 
by something other than their
                        // sortkey (e.g. by their namespace?!), and it can 
handle values consisting of a page
@@ -625,16 +625,16 @@
                        // to iterate over the table fields since one page 
corresponds to four values in a
                        // type's signature. Thankfully, signatures are short 
so this iteration is not notable.
                        $smwidjoinfield = false;
-                       $fieldNames = $this->getDBFieldsForDVIndexes( 
$objectfields, $valueindexes, $smwidjoinfield );
+                       $fieldName = $this->getDBFieldsForDVIndex( 
$objectfields, $valueindex, $smwidjoinfield );
                        
-                       if ( $fieldNames ) { // TODO //.//
+                       if ( $fieldName ) {
                                if ( $smwidjoinfield ) {
                                        // TODO: is this smw_ids possibly 
duplicated in the query? Can we prevent that? (PERFORMANCE)
                                        $query->from = ' INNER JOIN ' . 
$this->m_dbs->tableName( 'smw_ids' ) .
                                                                        " AS 
ids{$query->alias} ON 
ids{$query->alias}.smw_id={$query->alias}.{$smwidjoinfield}";
-                                       $query->sortfields[$sortkey] = 
"ids{$query->alias}.{$fieldNames[0]}";
+                                       $query->sortfields[$sortkey] = 
"ids{$query->alias}.{$fieldName}";
                                } else {
-                                       $query->sortfields[$sortkey] = 
"{$query->alias}.{$fieldNames[0]}";
+                                       $query->sortfields[$sortkey] = 
"{$query->alias}.{$fieldName}";
                                }
                        }
                }
@@ -652,37 +652,33 @@
         * given index could not be matched, $fieldname is false.
         * 
         * @param array $objectFields
-        * @param array $indexes
+        * @param integer $index
         * @param $smwidjoinfield
         * 
         * @return array with at least one element or false
-        * 
-        * TODO: $smwidjoinfield should probably also be turned into an array
         */
-       protected function getDBFieldsForDVIndexes( array $objectFields, array 
$indexes, &$smwidjoinfield ) {
-               $fieldNames = array();
+       protected function getDBFieldsForDVIndex( array $objectFields, $index, 
&$smwidjoinfield ) {
+               $fieldName = false;
                
-               foreach( $indexes as $index ) {
-                       $curindex = 0;
-                       foreach( $objectFields as $fname => $ftype ) {
-                               if ( $ftype == 'p' ) { // special treatment 
since "p" consists of 4 fields that are kept in smw_ids
-                                       if ( $curindex + 4 >= $index ) {
-                                               $idfieldnames = array( 
'smw_title', 'smw_namespace', 'smw_iw', 'smw_sortkey' );
-                                               $smwidjoinfield = $fname;
-                                               $fieldNames[] = 
$idfieldnames[$index - $curindex];
-                                               break;
-                                       }
-                                       $curindex += 3;
-                               } elseif ( $curindex == $index ) {
-                                       $smwidjoinfield = false;
-                                       $fieldNames[] = $fname;
+               $curindex = 0;
+               foreach( $objectFields as $fname => $ftype ) {
+                       if ( $ftype == 'p' ) { // special treatment since "p" 
consists of 4 fields that are kept in smw_ids
+                               if ( $curindex + 4 >= $index ) {
+                                       $idfieldnames = array( 'smw_title', 
'smw_namespace', 'smw_iw', 'smw_sortkey' );
+                                       $smwidjoinfield = $fname;
+                                       $fieldName = $idfieldnames[$index - 
$curindex];
                                        break;
                                }
-                               $curindex++;
-                       }                       
-               }
+                               $curindex += 3;
+                       } elseif ( $curindex == $index ) {
+                               $smwidjoinfield = false;
+                               $fieldName = $fname;
+                               break;
+                       }
+                       $curindex++;
+               }                       
                
-               return count( $fieldNames ) > 0 ? $fieldNames : false;
+               return $fieldName;
        }
 
        /**
@@ -693,11 +689,11 @@
         * @param $query
         * @param SMWDescription $description
         * @param SMWSQLStore2Table $proptable
-        * @param array $valueIndexes
+        * @param integer $valueIndex
         * @param string $operator
         */
        protected function compileAttributeWhere(
-                       $query, SMWDescription $description, SMWSQLStore2Table 
$proptable, array $valueIndexes, $operator = 'AND' ) {
+                       $query, SMWDescription $description, SMWSQLStore2Table 
$proptable, $valueIndex, $operator = 'AND' ) {
                                
                $where = '';
                
@@ -706,13 +702,13 @@
                        $keys = $dv->getDBkeys();
                        
                        // Try comparison based on value field and comparator.
-                       if ( ( count( $valueIndexes ) > 0 ) ) {
+                       if ( $valueIndex >= 0 ) {
                                // Find field name for comparison.
                                $smwidjoinfield = false;
-                               $fieldNames = $this->getDBFieldsForDVIndexes( 
$proptable->objectfields, $valueIndexes, $smwidjoinfield );
-                               
+                               $fieldName = $this->getDBFieldsForDVIndex( 
$proptable->objectfields, $valueIndex, $smwidjoinfield );
+
                                // Do not support smw_id joined data for now.
-                               if ( $fieldNames && !$smwidjoinfield ) { 
+                               if ( $fieldName && !$smwidjoinfield ) { 
                                        $comparator = false;
                                        $customSQL = false;
                                        
@@ -724,20 +720,14 @@
                                        }
                                        
                                        if ( !$comparator ) {
-                                               $customSQL = 
$description->getSQLCondition( $query->alias, $fieldNames, $this->m_dbs ); 
+                                               $customSQL = 
$description->getSQLCondition( $query->alias, $fieldName, $this->m_dbs );  
                                        }
                                        
                                        if ( $customSQL ) {
                                                $where = $customSQL;
                                        }
                                        else {
-                                               $contitions = array();  
-                                               
-                                               for( $i = 0, $n = count( 
$fieldNames ); $i < $n; $i++ ) {
-                                                       $contitions[] = 
"$query->alias.{$fieldNames[$i]}{$comparator}" . $this->m_dbs->addQuotes( 
$keys[$valueIndexes[$i]] );
-                                               }
-                                               
-                                               $where = implode( ' && ', 
$contitions );
+                                               $where = 
"$query->alias.{$fieldName}{$comparator}" . $this->m_dbs->addQuotes( 
$keys[$valueIndex] );
                                        }
                                }
                        }
@@ -759,12 +749,13 @@
                        
                } elseif ( ( $description instanceof SMWConjunction ) || ( 
$description instanceof SMWDisjunction ) ) {
                        $op = ( $description instanceof SMWConjunction ) ? 
'AND' : 'OR';
+                       
                        foreach ( $description->getDescriptions() as $subdesc ) 
{
-                               // $where .= ($where!=''?$op:'') .
-                               $this->compileAttributeWhere( $query, $subdesc, 
$proptable, $valueIndexes, $op );
+                               $this->compileAttributeWhere( $query, $subdesc, 
$proptable, $valueIndex, $op );
                        }
                }
-               if ( $where != '' ) $query->where .= ( $query->where ? " 
$operator ":'' ) . "($where)";
+               
+               if ( $where != '' ) $query->where .= ( $query->where ? " 
$operator " : '' ) . "($where)";
        }
 
        /**

Modified: 
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStoreLight.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStoreLight.php   
2010-05-12 22:13:43 UTC (rev 66312)
+++ trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStoreLight.php   
2010-05-12 22:38:29 UTC (rev 66313)
@@ -174,35 +174,35 @@
        /// Array to cache signatures of known built-in types. Having this data
        /// here safes us from creating datavalue instances in 
getTypeSignature().
        private static $type_signatures = array(
-               '_txt'  => array( 'l', array(), array() ),  // Text type
-               '_cod'  => array( 'l', array(), array() ),  // Code type
-               '_str'  => array( 't', array( 0 ), array( 0 ) ),    // String 
type
-               '_ema'  => array( 't', array( 0 ), array( 0 ) ),    // Email 
type
-               '_uri'  => array( 't', array( 0 ), array( 0 ) ),    // URL/URI 
type
-               '_anu'  => array( 't', array( 0 ), array( 0 ) ),    // 
Annotation URI type
-               '_tel'  => array( 't', array( 0 ), array( 0 ) ),    // 
Telephone number
-               '_wpg'  => array( 'tnwt', array( 3 ), array( 3 ) ), // Page type
-               '_wpp'  => array( 'tnwt', array( 3 ), array( 3 ) ), // Property 
page type
-               '_wpc'  => array( 'tnwt', array( 3 ), array( 3 ) ), // Category 
page type
-               '_wpf'  => array( 'tnwt', array( 3 ), array( 3 ) ), // Form 
page type (for Semantic Forms)
-               '_num'  => array( 'tfu', array( 1 ), array( 0 ) ),  // Number 
type
-               '_tem'  => array( 'tfu', array( 1 ), array( 0 ) ),  // 
Temperature type
-               '_dat'  => array( 'tf', array( 1 ), array( 0 ) ),   // Time type
-               '_boo'  => array( 't', array( 0 ), array( 0 ) ),    // Boolean 
type
-               '_rec'  => array( 'tnwt', array( 0 ), array() ),// Value list 
type (internal object)
+               '_txt'  => array( 'l', -1, -1 ),  // Text type
+               '_cod'  => array( 'l', -1, -1 ),  // Code type
+               '_str'  => array( 't', 0, 0 ),    // String type
+               '_ema'  => array( 't', 0, 0 ),    // Email type
+               '_uri'  => array( 't', 0, 0 ),    // URL/URI type
+               '_anu'  => array( 't', 0, 0 ),    // Annotation URI type
+               '_tel'  => array( 't', 0, 0 ),    // Telephone number
+               '_wpg'  => array( 'tnwt', 3, 3 ), // Page type
+               '_wpp'  => array( 'tnwt', 3, 3 ), // Property page type
+               '_wpc'  => array( 'tnwt', 3, 3 ), // Category page type
+               '_wpf'  => array( 'tnwt', 3, 3 ), // Form page type (for 
Semantic Forms)
+               '_num'  => array( 'tfu', 1, 0 ),  // Number type
+               '_tem'  => array( 'tfu', 1, 0 ),  // Temperature type
+               '_dat'  => array( 'tf', 1, 0 ),   // Time type
+               '_boo'  => array( 't', 0, 0 ),    // Boolean type
+               '_rec'  => array( 'tnwt', 0, -1 ),// Value list type (internal 
object)
                // Special types are not avaialble directly for users (and have 
no local language name):
-               '__typ' => array( 't', array( 0 ), array( 0 ) ),    // Special 
type page type
-               '__tls' => array( 't', array( 0 ), array( 0 ) ),    // Special 
type page type
-               '__sps' => array( 't', array( 0 ), array( 0 ) ),    // Special 
string type
-               '__spu' => array( 't', array( 0 ), array( 0 ) ),    // Special 
uri type
-               '__sup' => array( 'tnwt', array( 3 ), array( 3 ) ), // Special 
subproperty type
-               '__suc' => array( 'tnwt', array( 3 ), array( 3 ) ), // Special 
subcategory type
-               '__spf' => array( 't', array( 0 ), array( 0 ) ),    // Special 
form type (for Semantic Forms)
-               '__sin' => array( 'tnwt', array( 3 ), array( 3 ) ), // Special 
instance of type
-               '__red' => array( 'tnwt', array( 3 ), array( 3 ) ), // Special 
redirect type
-               '__lin' => array( 'tfu', array( 1 ), array( 0 ) ),  // Special 
linear unit conversion type
-               '__imp' => array( 't', array( 0 ), array( 0 ) ), // Special 
import vocabulary type
-               '__pro' => array( 't', array( 0 ), array( 0 ) ),  // Property 
page type; never be stored as a value (_wpp is used there) but needed for 
sorting
+               '__typ' => array( 't', 0, 0 ),    // Special type page type
+               '__tls' => array( 't', 0, 0 ),    // Special type page type
+               '__sps' => array( 't', 0, 0 ),    // Special string type
+               '__spu' => array( 't', 0, 0 ),    // Special uri type
+               '__sup' => array( 'tnwt', 3, 3 ), // Special subproperty type
+               '__suc' => array( 'tnwt', 3, 3 ), // Special subcategory type
+               '__spf' => array( 't', 0, 0 ),    // Special form type (for 
Semantic Forms)
+               '__sin' => array( 'tnwt', 3, 3 ), // Special instance of type
+               '__red' => array( 'tnwt', 3, 3 ), // Special redirect type
+               '__lin' => array( 'tfu', 1, 0 ),  // Special linear unit 
conversion type
+               '__imp' => array( 't', 0, 0 ), // Special import vocabulary type
+               '__pro' => array( 't', 0, 0 ),  // Property page type; never be 
stored as a value (_wpp is used there) but needed for sorting
        );
 
 ///// Reading methods /////
@@ -1363,7 +1363,7 @@
         * entries: a signature string, the index of the value field, and
         * the index of the label label field. These entries correspond to
         * the results of SMWDataValue::getSignature(),
-        * SMWDatavalue::getValueIndexes(), and SMWDatavalue::getLabelIndexes().
+        * SMWDatavalue::getValueIndex(), and SMWDatavalue::getLabelIndexes().
         * @todo Custom unit types (SMWLinearValue) have page names as their
         * type id and are not in the array cache. Can we still determine their
         * signature without creating them?
@@ -1371,7 +1371,7 @@
        public static function getTypeSignature( $typeid ) {
                if ( !array_key_exists( $typeid, self::$type_signatures ) ) {
                        $dv = SMWDataValueFactory::newTypeIDValue( $typeid );
-                       self::$type_signatures[$typeid] = array( 
$dv->getSignature(), $dv->getValueIndexes(), $dv->getLabelIndexes() );
+                       self::$type_signatures[$typeid] = array( 
$dv->getSignature(), $dv->getValueIndex(), $dv->getLabelIndex() );
                }
                return self::$type_signatures[$typeid];
        }



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to