Cicalese has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/355444 )
Change subject: Added label disambigation for remote autocompletion.
......................................................................
Added label disambigation for remote autocompletion.
Change-Id: Ifaf2879ce7f2af566d6f258ce6d0f0faf5507083
---
M includes/PF_AutocompleteAPI.php
M includes/PF_FormField.php
M includes/PF_ValuesUtils.php
3 files changed, 37 insertions(+), 32 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms
refs/changes/44/355444/1
diff --git a/includes/PF_AutocompleteAPI.php b/includes/PF_AutocompleteAPI.php
index f504351..b57bd77 100644
--- a/includes/PF_AutocompleteAPI.php
+++ b/includes/PF_AutocompleteAPI.php
@@ -54,9 +54,15 @@
} elseif ( !is_null( $category ) ) {
$data = PFValuesUtils::getAllPagesForCategory(
$category, 3, $substr );
$map = $wgPageFormsUseDisplayTitle;
+ if ( $map ) {
+ $data = PFValuesUtils::disambiguateLabels(
$data );
+ }
} elseif ( !is_null( $concept ) ) {
$data = PFValuesUtils::getAllPagesForConcept( $concept,
$substr );
$map = $wgPageFormsUseDisplayTitle;
+ if ( $map ) {
+ $data = PFValuesUtils::disambiguateLabels(
$data );
+ }
} elseif ( !is_null( $cargo_table ) && !is_null( $cargo_field )
) {
$data = self::getAllValuesForCargoField( $cargo_table,
$cargo_field, $field_is_array, $substr, $base_cargo_table, $base_cargo_field,
$basevalue );
} elseif ( !is_null( $namespace ) ) {
diff --git a/includes/PF_FormField.php b/includes/PF_FormField.php
index c2887d4..0dcff50 100644
--- a/includes/PF_FormField.php
+++ b/includes/PF_FormField.php
@@ -361,7 +361,7 @@
array_key_exists( 'mapping cargo field',
$f->mFieldArgs ) ) {
$f->setValuesWithMappingCargoField();
} elseif ( $f->mUseDisplayTitle ) {
- $f->mPossibleValues = $f->disambiguateLabels(
$f->mPossibleValues );
+ $f->mPossibleValues =
PFValuesUtils::disambiguateLabels( $f->mPossibleValues );
}
}
if ( $template_in_form->allowsMultiple() ) {
@@ -544,7 +544,7 @@
$labels[$value] = $value;
}
}
- $this->mPossibleValues = $this->disambiguateLabels( $labels );
+ $this->mPossibleValues = PFValuesUtils::disambiguateLabels(
$labels );
}
/**
@@ -578,7 +578,7 @@
}
}
}
- $this->mPossibleValues = $this->disambiguateLabels( $labels );
+ $this->mPossibleValues = PFValuesUtils::disambiguateLabels(
$labels );
}
/**
@@ -601,35 +601,7 @@
$labels[$value] = trim( $vals[0] );
}
}
- $this->mPossibleValues = $this->disambiguateLabels( $labels );
- }
-
-
- function disambiguateLabels( $labels ) {
- asort( $labels );
- if ( count( $labels ) == count( array_unique( $labels ) ) ) {
- return $labels;
- }
- $fixed_labels = array();
- foreach ( $labels as $value => $label ) {
- $fixed_labels[$value] = $labels[$value];
- }
- $counts = array_count_values( $fixed_labels );
- foreach ( $counts as $current_label => $count ) {
- if ( $count > 1 ) {
- $matching_keys = array_keys( $labels,
$current_label );
- foreach ( $matching_keys as $key ) {
- $fixed_labels[$key] .= ' (' . $key .
')';
- }
- }
- }
- if ( count( $fixed_labels ) == count( array_unique(
$fixed_labels ) ) ) {
- return $fixed_labels;
- }
- foreach ( $labels as $value => $label ) {
- $labels[$value] .= ' (' . $value . ')';
- }
- return $labels;
+ $this->mPossibleValues = PFValuesUtils::disambiguateLabels(
$labels );
}
/**
diff --git a/includes/PF_ValuesUtils.php b/includes/PF_ValuesUtils.php
index 423eb5c..e806a4b 100644
--- a/includes/PF_ValuesUtils.php
+++ b/includes/PF_ValuesUtils.php
@@ -584,4 +584,31 @@
return $pages;
}
+ public static function disambiguateLabels( $labels ) {
+ asort( $labels );
+ if ( count( $labels ) == count( array_unique( $labels ) ) ) {
+ return $labels;
+ }
+ $fixed_labels = array();
+ foreach ( $labels as $value => $label ) {
+ $fixed_labels[$value] = $labels[$value];
+ }
+ $counts = array_count_values( $fixed_labels );
+ foreach ( $counts as $current_label => $count ) {
+ if ( $count > 1 ) {
+ $matching_keys = array_keys( $labels,
$current_label );
+ foreach ( $matching_keys as $key ) {
+ $fixed_labels[$key] .= ' (' . $key .
')';
+ }
+ }
+ }
+ if ( count( $fixed_labels ) == count( array_unique(
$fixed_labels ) ) ) {
+ return $fixed_labels;
+ }
+ foreach ( $labels as $value => $label ) {
+ $labels[$value] .= ' (' . $value . ')';
+ }
+ return $labels;
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/355444
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifaf2879ce7f2af566d6f258ce6d0f0faf5507083
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Cicalese <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits