Page MenuHomePhabricator

Autocompletion matching on every character does not work when remote autocompletion is done
Closed, ResolvedPublicBUG REPORT

Description

To reproduce the bug a field with autocompletion is needed (I tried on token and combobox inputs).

Set the following settings on LocalSettings.php

$wgPageFormsAutocompleteOnAllChars = true;
$wgPageFormsMaxLocalAutocompleteValues = 20;

Replace 20 by a number less than the number of values available so remote autocompletion is used.

As an example assume that one possible value of the field is "New York".

If I start typing "Ne", autocompletion works and "New York" is suggested.
If I start typing "Yo", autocompletion does not work, "New York" is not suggested.

In general, autocompletion only matches on the beginning of the string (not even on the beginning of a word).

My setup is the following:

  • Mediawiki 1.32
  • PHP 7.2.19
  • MariaDB 10.1.38
  • Page Forms 4.5
  • Cargo 2.1.2

I will try to investigate the problem and make a patch if I have some free time.

Event Timeline

I have found the problematic line of code. The bug is in the function getSQLConditionForAutocompleteInColumn (In PF_ValuesUtils.php), which is called when autocompleting by category or namespace.

The bug was introduced 2 years ago in commit bb42c6f401b95d3e1cd1bd107b64da0c827f9533, when the line

return "$column_value LIKE '%$substring%'";

was changed by the line

return $column_value . $db->buildLike( $substring, $db->anyString() );

In the call to $db->buildLike, the any string character is introduced at the end, but is missing at the start. Hence, the following patch fixes the problem

diff --git a/includes/PF_ValuesUtils.php b/includes/PF_ValuesUtils.php
index 35166eda..d92c7fca 100644
--- a/includes/PF_ValuesUtils.php
+++ b/includes/PF_ValuesUtils.php
@@ -650,7 +650,7 @@ class PFValuesUtils {
                }
 
                if ( $wgPageFormsAutocompleteOnAllChars ) {
-                       return $column_value . $db->buildLike( $substring, $db->anyString() );
+                       return $column_value . $db->buildLike( $db->anyString(), $substring, $db->anyString() );
                } else {
                        $spaceRepresentation = $replaceSpaces ? '_' : ' ';
                        return $column_value . $db->buildLike( $substring, $db->anyString() ) .
Yaron_Koren claimed this task.
Yaron_Koren added a subscriber: Yaron_Koren.

Thank you for debugging the problem and finding the fix! I just checked in your suggested change.