Last modified: 2012-04-16 09:16:04 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T30313, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 28313 - HTMLForm cannot handle identical translations
HTMLForm cannot handle identical translations
Status: NEW
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
unspecified
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-03-29 23:24 UTC by Mark A. Hershberger
Modified: 2012-04-16 09:16 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Mark A. Hershberger 2011-03-29 23:24:22 UTC
Re bug #28152 and bug #28250: When HTMLForm is given two different fields with identical translations, the following error occurs:

  Global default '1' is invalid for field math

Although Andrew says:

> This is a deliberate design decision in HTMLForm, used to support grouped
> options in select boxes. In theory it could have been done differently, I
> suppose, but why would you want two options to be the same anyway? That's just
> deliberately confusing.

Either the translations should be fixed so that identical translations could be given, or HTMLForm should be fixed so it doesn't cause this problem.
Comment 1 Happy-melon 2011-03-30 11:39:50 UTC
To be clear, HTMLSelectField (and HTMLMultiSelectField etc) take options arrays of the form:

array(
	'message text' => 'value',
	'other text'   => other value,
);

The reason the message texts are in the keys is so that grouped options using <optgroup> can be specified:

array(
	'message text'   => 'value',
	'other text'     => other value,
	'optgroup label' => array(
		'label text'    => 'a value',
		'another label' => false,
	),
);

etc.  There are two problems with attempting to flip keys and values:

1) It confuses the syntax for optgroups, as you cannot specify an array as a key, and there is also nowhere to put the message text

2) It means that the uniqueness must be in the array *value* rather than the key.  While having identical keys is probably easier to get in practice, being able to specify multiple options as mapping to the same value is probably more *useful*.
Comment 2 Max Semenik 2011-04-01 16:09:05 UTC
Added some checks to Extension:Translate in r85131.
Comment 3 Krinkle 2011-04-11 23:04:49 UTC
(In reply to comment #1)
> <optgroup> can be specified:
> 
> array(
>     'message text'   => 'value',
>     'other text'     => other value,
>     'optgroup label' => array(
>         'label text'    => 'a value',
>         'another label' => false,
>     ),
> );

> there is also nowhere to put the message text

There can also be arrays of arrays. Numerical keys.
No problem afaic:

$formFields = array(
  array(
    'label' => 'message text',
    'val' => 'valuehere',
  ),
  array(
    'label' => 'other text',
    'val' => 'other value',
  ),
  array(
    'label' => 'other text', // same label
    'val' => 'yet another value',
  ),
  array(
    'label' => 'my optgroup',
    'val' => array(
      'One' => 'choise1',
      'Two' => 'choise2',
    ),
);
Comment 4 Happy-melon 2011-04-11 23:51:08 UTC
True, however now the syntax is getting rather dense and ugly, because the options array is already several layers deep in the descriptor array.  What you actually have is something like:

$formFields = array(
    'MyButton' => array(
        'type' => 'multiselect',
        'label' => 'Foo option:',
        'options' => array(
            array(
                'label' => 'message text',
                'val' => 'valuehere',
            ),
            array(
                'label' => 'other text',
                'val' => 'other value',
            ),
            array(
                'label' => 'other text', // same label
                'val' => 'yet another value',
            ),
            array(
                'label' => 'my optgroup',
                'val' => array(
                    'One' => 'choise1',
                    'Two' => 'choise2',
                ),
        ),
    ),
);

As opposed to:

$formFields = array(
    'MyButton' => array(
        'type' => 'multiselect',
        'label' => 'Foo option:',
        'options' => array(
            'message text' => 'valuehere',
            'other text' => 'other value',
            'my optgroup' => array(
                'One' => 'choise1',
                'Two' => 'choise2',
            ),
        ),
    ),
);

Which is significantly more compact, and arguably more readable too.  And building those associative arrays from generators like Language::getLanguageNames is not going to be particularly pretty, probably with lots of foreach loops.

In a strongly typed language we'd have no difficulty making some sort of structure for this.  With what we have, I'm not convinced that an associative array is a good way to solve this.
Comment 5 Krinkle 2011-04-12 10:17:58 UTC
I think it's a matter of taste. I see no problem with the longer syntax, but anyway, I can see both working.

However in general using freeform text as array keys doesn't sound like a good idea, and there's ofcourse this bug 28313 for which I haven't seen another solution.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links