[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Added optional built-in support for displaytitle
Yaron Koren has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/329015 ) Change subject: Added optional built-in support for displaytitle .. Added optional built-in support for displaytitle Change-Id: I51417e091c67d220ce464a7627a3525f42732e92 --- M PageForms.php M extension.json M includes/PF_AutocompleteAPI.php M includes/PF_FormField.php M includes/PF_FormPrinter.php M includes/PF_ValuesUtils.php M libs/ext.pf.select2.combobox.js M libs/ext.pf.select2.tokens.js 8 files changed, 239 insertions(+), 50 deletions(-) Approvals: Yaron Koren: Looks good to me, approved jenkins-bot: Verified diff --git a/PageForms.php b/PageForms.php index fa02a12..e612e3a 100644 --- a/PageForms.php +++ b/PageForms.php @@ -572,6 +572,11 @@ require_once 'includes/PF_DatePickerSettings.php'; # ## +# Display displaytitle page property instead of page title for Page type fields +# ## +$GLOBALS['wgPageFormsUseDisplayTitle'] = false; + +# ## # Global variables for Javascript # ## $GLOBALS['wgPageFormsShowOnSelect'] = array(); diff --git a/extension.json b/extension.json index 30b2532..493f408 100644 --- a/extension.json +++ b/extension.json @@ -420,6 +420,7 @@ ] }, "config": { + "PageFormsUseDisplayTitle": false, "PageFormsMaxAutocompleteValues": 1000, "PageFormsMaxLocalAutocompleteValues": 100, "PageFormsAutocompleteOnAllChars": false, @@ -458,4 +459,4 @@ } }, "manifest_version": 1 -} \ No newline at end of file +} diff --git a/includes/PF_AutocompleteAPI.php b/includes/PF_AutocompleteAPI.php index bd0765e..cb16a3d 100644 --- a/includes/PF_AutocompleteAPI.php +++ b/includes/PF_AutocompleteAPI.php @@ -43,6 +43,8 @@ } } + global $wgPageFormsUseDisplayTitle; + $map = false; if ( !is_null( $baseprop ) ) { if ( !is_null( $property ) ) { $data = self::getAllValuesForProperty( $property, null, $baseprop, $basevalue ); @@ -51,12 +53,15 @@ $data = self::getAllValuesForProperty( $property, $substr ); } elseif ( !is_null( $category ) ) { $data = PFValuesUtils::getAllPagesForCategory( $category, 3, $substr ); + $map = $wgPageFormsUseDisplayTitle; } elseif ( !is_null( $concept ) ) { $data = PFValuesUtils::getAllPagesForConcept( $concept, $substr ); + $map = $wgPageFormsUseDisplayTitle; } 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 ) ) { $data = PFValuesUtils::getAllPagesForNamespace( $namespace, $substr ); + $map = $wgPageFormsUseDisplayTitle; } elseif ( !is_null( $external_url ) ) { $data = PFValuesUtils::getValuesFromExternalURL( $external_url, $substr ); } else { @@ -93,8 +98,12 @@ // correctly. if ( is_null( $external_url ) ) { $formattedData = array(); - foreach ( $data as $value ) { - $formattedData[] = array( 'title' => $value ); + foreach ( $data as $index => $value ) { + if ( $map ) { + $formattedData[] = array( 'title' => $index, 'displaytitle' => $value ); + } else { + $formattedData[] = array( 'title' => $value ); + } } } else { $formattedData = $data; diff --git a/includes/PF_FormField.php b/includes/PF_FormField.php index c41406e..c006ff8 100644 --- a/includes/PF_FormField.php +++ b/includes/PF_FormField.php @@ -341,6 +341,7 @@ } if ( !is_null( $f->mPossibleValues ) ) { + global $wgPageFormsUseDisplayTitle; if ( array_key_exists( 'mapping template', $f->mFieldArgs ) ) { $f->setValuesWithMappingTemplate(); } elseif ( array_key_exists( 'mapping property', $f->mFieldArgs ) ) { @@ -348,6 +349,8 @@ } elseif ( array_key_exists( 'mapping cargo table', $f->mFieldArgs ) && array_key_exists( 'mapping cargo field', $f->mFieldArgs ) ) { $f->setValuesWithMappingCargoField(); +
[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Added optional built-in support for displaytitle
Cicalese has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/329015 ) Change subject: Added optional built-in support for displaytitle .. Added optional built-in support for displaytitle Change-Id: I51417e091c67d220ce464a7627a3525f42732e92 --- M extension.json M includes/PF_AutocompleteAPI.php M includes/PF_FormField.php M includes/PF_FormPrinter.php M includes/PF_ValuesUtils.php M libs/ext.pf.select2.combobox.js M libs/ext.pf.select2.tokens.js 7 files changed, 162 insertions(+), 41 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms refs/changes/15/329015/1 diff --git a/extension.json b/extension.json index 30b2532..493f408 100644 --- a/extension.json +++ b/extension.json @@ -420,6 +420,7 @@ ] }, "config": { + "PageFormsUseDisplayTitle": false, "PageFormsMaxAutocompleteValues": 1000, "PageFormsMaxLocalAutocompleteValues": 100, "PageFormsAutocompleteOnAllChars": false, @@ -458,4 +459,4 @@ } }, "manifest_version": 1 -} \ No newline at end of file +} diff --git a/includes/PF_AutocompleteAPI.php b/includes/PF_AutocompleteAPI.php index bd0765e..f16b9f0 100644 --- a/includes/PF_AutocompleteAPI.php +++ b/includes/PF_AutocompleteAPI.php @@ -43,6 +43,8 @@ } } + global $wgPageFormsUseDisplayTitle; + $map = false; if ( !is_null( $baseprop ) ) { if ( !is_null( $property ) ) { $data = self::getAllValuesForProperty( $property, null, $baseprop, $basevalue ); @@ -51,12 +53,14 @@ $data = self::getAllValuesForProperty( $property, $substr ); } elseif ( !is_null( $category ) ) { $data = PFValuesUtils::getAllPagesForCategory( $category, 3, $substr ); + $map = $wgPageFormsUseDisplayTitle; } elseif ( !is_null( $concept ) ) { $data = PFValuesUtils::getAllPagesForConcept( $concept, $substr ); } 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 ) ) { $data = PFValuesUtils::getAllPagesForNamespace( $namespace, $substr ); + $map = $wgPageFormsUseDisplayTitle; } elseif ( !is_null( $external_url ) ) { $data = PFValuesUtils::getValuesFromExternalURL( $external_url, $substr ); } else { @@ -93,8 +97,12 @@ // correctly. if ( is_null( $external_url ) ) { $formattedData = array(); - foreach ( $data as $value ) { - $formattedData[] = array( 'title' => $value ); + foreach ( $data as $index => $value ) { + if ( $map ) { + $formattedData[] = array( 'title' => $index, 'displaytitle' => $value ); + } else { + $formattedData[] = array( 'title' => $value ); + } } } else { $formattedData = $data; diff --git a/includes/PF_FormField.php b/includes/PF_FormField.php index c41406e..c006ff8 100644 --- a/includes/PF_FormField.php +++ b/includes/PF_FormField.php @@ -341,6 +341,7 @@ } if ( !is_null( $f->mPossibleValues ) ) { + global $wgPageFormsUseDisplayTitle; if ( array_key_exists( 'mapping template', $f->mFieldArgs ) ) { $f->setValuesWithMappingTemplate(); } elseif ( array_key_exists( 'mapping property', $f->mFieldArgs ) ) { @@ -348,6 +349,8 @@ } elseif ( array_key_exists( 'mapping cargo table', $f->mFieldArgs ) && array_key_exists( 'mapping cargo field', $f->mFieldArgs ) ) { $f->setValuesWithMappingCargoField(); + } elseif ( $wgPageFormsUseDisplayTitle ) { + $f->mPossibleValues = $f->disambiguateLabels( $f->mPossibleValues ); } } if ( $template_in_form->allowsMultiple() ) { @@ -625,6 +628,10 @@ * Map a template field value into labels. */ public function valueStringToLabels( $valueString, $delimiter ) { + if ( strlen( trim( $valueString ) ) === 0 || +