Page MenuHomePhabricator

parser output not trimmed anymore for show on select mapping templates/$option_div_pair
Closed, ResolvedPublicBUG REPORT

Description

We use mapping templates to allow translated dropdown values to work with show on select, e.g.:

{{{field|type|input type=dropdown|values={{Dropdown definition}}|mapping template=mapping dropdown definition|show on select={{Mapping dropdown definition|myOption}}=>myOption}}}

What happens?:
Since this change in PF_FormField.php::306, the parsed wikitext option does not get trimmed anymore. Only the input (wikitext) gets trimmed.mw.config.get('wgPageFormsShowOnSelect')['input_11'][1][0][0] in the browser's console reads ` "\nMy mapped option" instead of "My mapped option". The selected option in the form's dropdown does not trigger the hidden html to show.

What should have happened instead?:
The newline gets trimmed. Show on select works.

Software version (skip for WMF-hosted wikis like Wikipedia):
PageForms 3fde7fa31f2bf64ac7905e179a57f9848cfdaa2c

I am not sure if that's a use case you intend to support. If not feel free to close the issue :) Since we use this template structure in more than 30 wikis in around 10 of such mapping templates each, I patched the code rather than fixing "hidden" newlines in the templates themselves.

diff --git a/includes/PF_FormField.php b/includes/PF_FormField.php
index 29cd6029..179081ac 100644
--- a/includes/PF_FormField.php
+++ b/includes/PF_FormField.php
@@ -303,7 +303,7 @@ class PFFormField {
                                                }
                                                $option_div_pair = explode( '=>', $val, 2 );
                                                if ( count( $option_div_pair ) > 1 ) {
-                                                       $option = PFFormPrinter::getParsedValue( $parser, trim( $option_div_pair[0] ) );
+                                                       $option = trim( PFFormPrinter::getParsedValue( $parser, trim( $option_div_pair[0] ) ) );
                                                        $div_id = $option_div_pair[1];
                                                        if ( array_key_exists( $div_id, $show_on_select ) ) {
                                                                $show_on_select[$div_id][] = $option;

Event Timeline

Change 1011455 had a related patch set uploaded (by Yaron Koren; author: Yaron Koren):

[mediawiki/extensions/PageForms@master] Add trim() to PFFormPrinter::getParsedValue()

https://gerrit.wikimedia.org/r/1011455

@Schtom - I implemented the fix in a slightly different way; please let me know if this fix works for you.

thank you yaron. your fix works fine.

Change 1011455 merged by jenkins-bot:

[mediawiki/extensions/PageForms@master] Add trim() to PFFormPrinter::getParsedValue()

https://gerrit.wikimedia.org/r/1011455

Yaron_Koren claimed this task.

That's great to hear! Closing this now.