private static function getAllValuesForProperty($property_name, $substring, $basePropertyName = null, $baseValue = null)
 {
     global $sfgMaxAutocompleteValues, $sfgCacheAutocompleteValues, $sfgAutocompleteCacheTimeout;
     global $smwgDefaultStore;
     $values = array();
     $db = wfGetDB(DB_SLAVE);
     $sqlOptions = array();
     $sqlOptions['LIMIT'] = $sfgMaxAutocompleteValues;
     $property = SMWPropertyValue::makeUserProperty($property_name);
     $propertyHasTypePage = $property->getPropertyTypeID() == '_wpg';
     $property_name = str_replace(' ', '_', $property_name);
     $conditions = array('p_ids.smw_title' => $property_name);
     // Use cache if allowed
     if ($sfgCacheAutocompleteValues) {
         $cache = SFFormUtils::getFormCache();
         // Remove trailing whitespace to avoid unnecessary database selects
         $cacheKeyString = $property_name . '::' . rtrim($substring);
         if (!is_null($basePropertyName)) {
             $cacheKeyString .= ',' . $basePropertyName . ',' . $baseValue;
         }
         $cacheKey = wfMemcKey('sf-autocomplete', md5($cacheKeyString));
         $values = $cache->get($cacheKey);
         if (!empty($values)) {
             // Return with results immediately
             return $values;
         }
     }
     if ($propertyHasTypePage) {
         $valueField = 'o_ids.smw_title';
         if ($smwgDefaultStore === 'SMWSQLStore3') {
             $idsTable = $db->tableName('smw_object_ids');
             $propsTable = $db->tableName('smw_di_wikipage');
         } else {
             $idsTable = $db->tableName('smw_ids');
             $propsTable = $db->tableName('smw_rels2');
         }
         $fromClause = "{$propsTable} p JOIN {$idsTable} p_ids ON p.p_id = p_ids.smw_id JOIN {$idsTable} o_ids ON p.o_id = o_ids.smw_id";
     } else {
         if ($smwgDefaultStore === 'SMWSQLStore3') {
             $valueField = 'p.o_hash';
             $idsTable = $db->tableName('smw_object_ids');
             $propsTable = $db->tableName('smw_di_blob');
         } else {
             $valueField = 'p.value_xsd';
             $idsTable = $db->tableName('smw_ids');
             $propsTable = $db->tableName('smw_atts2');
         }
         $fromClause = "{$propsTable} p JOIN {$idsTable} p_ids ON p.p_id = p_ids.smw_id";
     }
     if (!is_null($basePropertyName)) {
         $baseProperty = SMWPropertyValue::makeUserProperty($basePropertyName);
         $basePropertyHasTypePage = $baseProperty->getPropertyTypeID() == '_wpg';
         $basePropertyName = str_replace(' ', '_', $basePropertyName);
         $conditions['base_p_ids.smw_title'] = $basePropertyName;
         if ($basePropertyHasTypePage) {
             if ($smwgDefaultStore === 'SMWSQLStore3') {
                 $idsTable = $db->tableName('smw_object_ids');
                 $propsTable = $db->tableName('smw_di_wikipage');
             } else {
                 $idsTable = $db->tableName('smw_ids');
                 $propsTable = $db->tableName('smw_rels2');
             }
             $fromClause .= " JOIN {$propsTable} p_base ON p.s_id = p_base.s_id";
             $fromClause .= " JOIN {$idsTable} base_p_ids ON p_base.p_id = base_p_ids.smw_id JOIN {$idsTable} base_o_ids ON p_base.o_id = base_o_ids.smw_id";
             $baseValue = str_replace(' ', '_', $baseValue);
             $conditions['base_o_ids.smw_title'] = $baseValue;
         } else {
             if ($smwgDefaultStore === 'SMWSQLStore3') {
                 $baseValueField = 'p_base.o_hash';
                 $idsTable = $db->tableName('smw_object_ids');
                 $propsTable = $db->tableName('smw_di_blob');
             } else {
                 $baseValueField = 'p_base.value_xsd';
                 $idsTable = $db->tableName('smw_ids');
                 $propsTable = $db->tableName('smw_atts2');
             }
             $fromClause .= " JOIN {$propsTable} p_base ON p.s_id = p_base.s_id";
             $fromClause .= " JOIN {$idsTable} base_p_ids ON p_base.p_id = base_p_ids.smw_id";
             $conditions[$baseValueField] = $baseValue;
         }
     }
     if (!is_null($substring)) {
         // "Page" type property valeus are stored differently
         // in the DB, i.e. underlines instead of spaces.
         $conditions[] = SFUtils::getSQLConditionForAutocompleteInColumn($valueField, $substring, $propertyHasTypePage);
     }
     $sqlOptions['ORDER BY'] = $valueField;
     $res = $db->select($fromClause, "DISTINCT {$valueField}", $conditions, __METHOD__, $sqlOptions);
     while ($row = $db->fetchRow($res)) {
         $values[] = str_replace('_', ' ', $row[0]);
     }
     $db->freeResult($res);
     if ($sfgCacheAutocompleteValues) {
         // Save to cache.
         $cache->set($cacheKey, $values, $sfgAutocompleteCacheTimeout);
     }
     return $values;
 }
Ejemplo n.º 2
0
 private static function getAllValuesForProperty($property_name, $substring, $base_property_name = null, $base_value = null)
 {
     $values = array();
     $db = wfGetDB(DB_SLAVE);
     $sql_options = array();
     $sql_options['LIMIT'] = 500;
     //$limit;
     $property = SMWPropertyValue::makeUserProperty($property_name);
     $is_relation = $property->getPropertyTypeID() == '_wpg';
     $property_name = str_replace(' ', '_', $property_name);
     $conditions = array('p_ids.smw_title' => $property_name);
     if ($is_relation) {
         $value_field = 'o_ids.smw_title';
         $from_clause = $db->tableName('smw_rels2') . " r JOIN " . $db->tableName('smw_ids') . " p_ids ON r.p_id = p_ids.smw_id JOIN " . $db->tableName('smw_ids') . " o_ids ON r.o_id = o_ids.smw_id";
     } else {
         $value_field = 'a.value_xsd';
         $from_clause = $db->tableName('smw_atts2') . " a JOIN " . $db->tableName('smw_ids') . " p_ids ON a.p_id = p_ids.smw_id";
     }
     if (!is_null($base_property_name)) {
         $base_property = SMWPropertyValue::makeUserProperty($base_property_name);
         $base_is_relation = $base_property->getPropertyTypeID() == '_wpg';
         $base_property_name = str_replace(' ', '_', $base_property_name);
         $conditions['base_p_ids.smw_title'] = $base_property_name;
         $main_prop_alias = $is_relation ? 'r' : 'a';
         if ($base_is_relation) {
             $from_clause .= " JOIN " . $db->tableName('smw_rels2') . " r_base ON {$main_prop_alias}.s_id = r_base.s_id";
             $from_clause .= " JOIN " . $db->tableName('smw_ids') . " base_p_ids ON r_base.p_id = base_p_ids.smw_id JOIN " . $db->tableName('smw_ids') . " base_o_ids ON r_base.o_id = base_o_ids.smw_id";
             $base_value = str_replace(' ', '_', $base_value);
             $conditions['base_o_ids.smw_title'] = $base_value;
         } else {
             $from_clause .= " JOIN " . $db->tableName('smw_atts2') . " a_base ON {$main_prop_alias}.s_id = a_base.s_id";
             $from_clause .= " JOIN " . $db->tableName('smw_ids') . " base_p_ids ON a_base.p_id = base_p_ids.smw_id";
             $conditions['a_base.value_xsd'] = $base_value;
         }
     }
     if (!is_null($substring)) {
         $conditions[] = SFUtils::getSQLConditionForAutocompleteInColumn($value_field, $substring);
     }
     $sql_options['ORDER BY'] = $value_field;
     $res = $db->select($from_clause, "DISTINCT {$value_field}", $conditions, __METHOD__, $sql_options);
     while ($row = $db->fetchRow($res)) {
         $values[] = str_replace('_', ' ', $row[0]);
     }
     $db->freeResult($res);
     return $values;
 }
Ejemplo n.º 3
0
 public static function getAllPagesForNamespace($namespace_name, $substring = null)
 {
     global $wgContLang, $wgLanguageCode;
     // Cycle through all the namespace names for this language, and
     // if one matches the namespace specified in the form, get the
     // names of all the pages in that namespace.
     // Switch to blank for the string 'Main'.
     if ($namespace_name == 'Main' || $namespace_name == 'main') {
         $namespace_name = '';
     }
     $matchingNamespaceCode = null;
     $namespaces = $wgContLang->getNamespaces();
     foreach ($namespaces as $curNSCode => $curNSName) {
         if ($curNSName == $namespace_name) {
             $matchingNamespaceCode = $curNSCode;
         }
     }
     // If that didn't find anything, and we're in a language
     // other than English, check English as well.
     if (is_null($matchingNamespaceCode) && $wgLanguageCode != 'en') {
         $englishLang = Language::factory('en');
         $namespaces = $englishLang->getNamespaces();
         foreach ($namespaces as $curNSCode => $curNSName) {
             if ($curNSName == $namespace_name) {
                 $matchingNamespaceCode = $curNSCode;
             }
         }
     }
     if (is_null($matchingNamespaceCode)) {
         return "Could not find namespace: {$namespace_name}";
     }
     $db = wfGetDB(DB_SLAVE);
     $conditions = array();
     $conditions['page_namespace'] = $matchingNamespaceCode;
     if ($substring != null) {
         $conditions[] = SFUtils::getSQLConditionForAutocompleteInColumn('page_title', $substring);
     }
     $res = $db->select('page', 'page_title', $conditions, __METHOD__, array('ORDER BY' => 'page_title'));
     $pages = array();
     while ($row = $db->fetchRow($res)) {
         $pages[] = str_replace('_', ' ', $row[0]);
     }
     $db->freeResult($res);
     return $pages;
 }
Ejemplo n.º 4
0
 private static function getAllValuesForProperty($property_name, $substring, $base_property_name = null, $base_value = null)
 {
     global $sfgMaxAutocompleteValues, $sfgCacheAutocompleteValues, $sfgAutocompleteCacheTimeout;
     $values = array();
     $db = wfGetDB(DB_SLAVE);
     $sql_options = array();
     $sql_options['LIMIT'] = $sfgMaxAutocompleteValues;
     $property = SMWPropertyValue::makeUserProperty($property_name);
     $is_relation = $property->getPropertyTypeID() == '_wpg';
     $property_name = str_replace(' ', '_', $property_name);
     $conditions = array('p_ids.smw_title' => $property_name);
     // Use cache if allowed
     if ($sfgCacheAutocompleteValues) {
         $cache = SFFormUtils::getFormCache();
         // Remove trailing whitespace to avoid unnecessary database selects
         $cacheKeyString = $property_name . '::' . rtrim($substring);
         if (!is_null($base_property_name)) {
             $cacheKeyString .= ',' . $base_property_name . ',' . $base_value;
         }
         $cacheKey = wfMemcKey('sf-autocomplete', md5($cacheKeyString));
         $values = $cache->get($cacheKey);
         if (!empty($values)) {
             // Return with results immediately
             return $values;
         }
     }
     if ($is_relation) {
         $value_field = 'o_ids.smw_title';
         $from_clause = $db->tableName('smw_rels2') . " r JOIN " . $db->tableName('smw_ids') . " p_ids ON r.p_id = p_ids.smw_id JOIN " . $db->tableName('smw_ids') . " o_ids ON r.o_id = o_ids.smw_id";
     } else {
         $value_field = 'a.value_xsd';
         $from_clause = $db->tableName('smw_atts2') . " a JOIN " . $db->tableName('smw_ids') . " p_ids ON a.p_id = p_ids.smw_id";
     }
     if (!is_null($base_property_name)) {
         $base_property = SMWPropertyValue::makeUserProperty($base_property_name);
         $base_is_relation = $base_property->getPropertyTypeID() == '_wpg';
         $base_property_name = str_replace(' ', '_', $base_property_name);
         $conditions['base_p_ids.smw_title'] = $base_property_name;
         $main_prop_alias = $is_relation ? 'r' : 'a';
         if ($base_is_relation) {
             $from_clause .= " JOIN " . $db->tableName('smw_rels2') . " r_base ON {$main_prop_alias}.s_id = r_base.s_id";
             $from_clause .= " JOIN " . $db->tableName('smw_ids') . " base_p_ids ON r_base.p_id = base_p_ids.smw_id JOIN " . $db->tableName('smw_ids') . " base_o_ids ON r_base.o_id = base_o_ids.smw_id";
             $base_value = str_replace(' ', '_', $base_value);
             $conditions['base_o_ids.smw_title'] = $base_value;
         } else {
             $from_clause .= " JOIN " . $db->tableName('smw_atts2') . " a_base ON {$main_prop_alias}.s_id = a_base.s_id";
             $from_clause .= " JOIN " . $db->tableName('smw_ids') . " base_p_ids ON a_base.p_id = base_p_ids.smw_id";
             $conditions['a_base.value_xsd'] = $base_value;
         }
     }
     if (!is_null($substring)) {
         $conditions[] = SFUtils::getSQLConditionForAutocompleteInColumn($value_field, $substring);
     }
     $sql_options['ORDER BY'] = $value_field;
     $res = $db->select($from_clause, "DISTINCT {$value_field}", $conditions, __METHOD__, $sql_options);
     while ($row = $db->fetchRow($res)) {
         $values[] = str_replace('_', ' ', $row[0]);
     }
     $db->freeResult($res);
     if ($sfgCacheAutocompleteValues) {
         // Save to cache.
         $cache->set($cacheKey, $values, $sfgAutocompleteCacheTimeout);
     }
     return $values;
 }