Index: trunk/extensions/SemanticForms/includes/SF_AutocompleteAPI.php |
— | — | @@ -163,10 +163,7 @@ |
164 | 164 | } |
165 | 165 | |
166 | 166 | if ( !is_null( $substring ) ) { |
167 | | - $substring = str_replace( "'", "\'", strtolower( $substring ) ); |
168 | | - // UTF-8 conversion is needed in case MediaWiki is using |
169 | | - // binary data storage. |
170 | | - $conditions[] = "REPLACE(LOWER(CONVERT($value_field USING utf8)),'_',' ') LIKE '" . $substring . "%' OR REPLACE(LOWER(CONVERT($value_field USING utf8)),'_',' ') LIKE '% " . $substring . "%'"; |
| 167 | + $conditions[] = SFUtils::getSQLConditionForAutocompleteInColumn( $value_field, $substring ); |
171 | 168 | } |
172 | 169 | |
173 | 170 | $sql_options['ORDER BY'] = $value_field; |
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -462,18 +462,16 @@ |
463 | 463 | for ( $level = $num_levels; $level > 0; $level-- ) { |
464 | 464 | $newcategories = array(); |
465 | 465 | foreach ( $checkcategories as $category ) { |
| 466 | + $conditions = array(); |
| 467 | + $conditions[] = 'cl_from = page_id'; |
| 468 | + $conditions['cl_to'] = $category; |
466 | 469 | if ( $substring != null ) { |
467 | | - $substring = str_replace( ' ', '_', strtolower( $substring ) ); |
468 | | - $substring = str_replace( '_', '\_', $substring ); |
469 | | - $substring = str_replace( "'", "\'", $substring ); |
470 | | - $conditions = 'cl_to = ' . $db->addQuotes( $category ) . " AND (LOWER(CONVERT(`page_title` USING utf8)) LIKE '" . $substring . "%' OR LOWER(CONVERT(`page_title` USING utf8)) LIKE '%\_" . $substring . "%' OR page_namespace = " . NS_CATEGORY . ")"; |
471 | | - } else { |
472 | | - $conditions = 'cl_to = ' . $db->addQuotes( $category ); |
| 470 | + $conditions[] = self::getSQLConditionForAutocompleteInColumn( 'page_title', $substring ) . ' OR page_namespace = ' . NS_CATEGORY; |
473 | 471 | } |
474 | 472 | $res = $db->select( // make the query |
475 | 473 | array( 'categorylinks', 'page' ), |
476 | 474 | array( 'page_title', 'page_namespace' ), |
477 | | - array( 'cl_from = page_id', $conditions ), |
| 475 | + $conditions, |
478 | 476 | __METHOD__, |
479 | 477 | 'SORT BY cl_sortkey' ); |
480 | 478 | if ( $res ) { |
— | — | @@ -521,7 +519,7 @@ |
522 | 520 | } |
523 | 521 | |
524 | 522 | public static function getAllPagesForConcept( $concept_name, $substring = null ) { |
525 | | - global $sfgMaxAutocompleteValues; |
| 523 | + global $sfgMaxAutocompleteValues, $sfgAutocompleteOnAllChars; |
526 | 524 | |
527 | 525 | $store = smwfGetStore(); |
528 | 526 | |
— | — | @@ -557,10 +555,16 @@ |
558 | 556 | // original SMW query, but that doesn't seem |
559 | 557 | // possible yet. |
560 | 558 | $lowercasePageName = strtolower( $pageName ); |
561 | | - if ( strpos( $lowercasePageName, $substring ) === 0 || |
562 | | - strpos( $lowercasePageName, ' ' . $substring ) > 0 ) { |
| 559 | + if ( $sfgAutocompleteOnAllChars ) { |
| 560 | + if ( strpos( $lowercasePageName, $substring ) >= 0 ) { |
563 | 561 | $pages[] = $pageName; |
564 | 562 | } |
| 563 | + } else { |
| 564 | + if ( strpos( $lowercasePageName, $substring ) === 0 || |
| 565 | + strpos( $lowercasePageName, ' ' . $substring ) > 0 ) { |
| 566 | + $pages[] = $pageName; |
| 567 | + } |
| 568 | + } |
565 | 569 | } |
566 | 570 | } |
567 | 571 | sort( $pages ); |
— | — | @@ -820,15 +824,39 @@ |
821 | 825 | } |
822 | 826 | |
823 | 827 | /** |
| 828 | + * Returns a SQL condition for autocompletion substring value in a column. |
| 829 | + * @param string $value_column Value column name |
| 830 | + * @param string $substring Substring to look for |
| 831 | + * @return SQL condition for use in WHERE clause |
| 832 | + * |
| 833 | + * @author Ilmars Poikans |
| 834 | + */ |
| 835 | + public static function getSQLConditionForAutocompleteInColumn( $column, $substring ) { |
| 836 | + global $sfgAutocompleteOnAllChars; |
| 837 | + |
| 838 | + $column_value = "LOWER(CONVERT($column USING utf8))"; |
| 839 | + $substring = str_replace( ' ', '_', strtolower( $substring ) ); |
| 840 | + $substring = str_replace( "'", "\'", $substring ); |
| 841 | + $substring = str_replace( '_', '\_', $substring ); |
| 842 | + $substring = str_replace( '%', '\%', $substring ); |
| 843 | + |
| 844 | + if ( $sfgAutocompleteOnAllChars ) { |
| 845 | + return "$column_value LIKE '%$substring%'"; |
| 846 | + } else { |
| 847 | + return "$column_value LIKE '$substring%' OR $column_value LIKE '%\_$substring%'"; |
| 848 | + } |
| 849 | + } |
| 850 | + |
| 851 | + /** |
824 | 852 | * Appends a preview of the actual form, when a page in the "Form" |
825 | 853 | * namespace is previewed. |
826 | 854 | * |
827 | 855 | * @author Solitarius |
828 | 856 | * @since 2.4 |
829 | | - * |
| 857 | + * |
830 | 858 | * @param EditPage $editpage |
831 | 859 | * @param WebRequest $request |
832 | | - * |
| 860 | + * |
833 | 861 | * @return true |
834 | 862 | */ |
835 | 863 | public static function showFormPreview( EditPage $editpage, WebRequest $request ) { |