Page MenuHomePhabricator

Use Universal Language Selector (ULS) for selecting languages in the UploadWizard
Closed, ResolvedPublic

Description

The UploadWizard has a form for writing file descriptions. It has long lists of languages. Instead it should use a ULS component.

(Tagging good first bug. While not a trivial one-line change, something like this was done in many other places across a bunch of extensions like Translate, Wikibase, and others, so the code for this can come here as well.)

Event Timeline

Amire80 created this task.Oct 15 2016, 8:50 AM
Restricted Application added a project: Multimedia. · View Herald TranscriptOct 15 2016, 8:50 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Restricted Application added a subscriber: Matanya. · View Herald TranscriptOct 15 2016, 8:50 AM
Restricted Application added a subscriber: TerraCodes. · View Herald TranscriptOct 15 2016, 8:59 AM
Amire80 updated the task description. (Show Details)Oct 15 2016, 9:01 AM

A couple notes:

  • I couldn't find documentation quickly, so on an Easy bug I would appreciate linking to where one might find information on the ULS component that is floated as a solution here.
  • ULS may support languages that we don't - i.e., languages for which there is no template. See e.g. https://commons.wikimedia.org/wiki/Template:fr for i18n templates that we support in UW.
  • Making UW depend on ULS may not be a good solution. Some non-WMF wikis use this extension (against our recommendation), and we're trying to make that easier for them, but adding a dependency is something we need to seriously think about.

(Removing good first bug until sufficient info has been provided for a new contributor)

A couple notes:

  • I couldn't find documentation quickly, so on an Easy bug I would appreciate linking to where one might find information on the ULS component that is floated as a solution here.

TLDR, you call the .uls() method as a jQuery plugin on the element, clicking which will show the selector. So instead of the current dropdown there should be a different element, e.g.:

$trigger = $( '<a>' ).attr( 'id', 'mw-uploadwizard-language-selector' );
$trigger.uls( {
    onSelect: function ( language ) {
        // Yadda yadda,
        // whatever happens when the language is selected in the dropdown.
        // Possibly very short.
    },
    languages: LIST // The languages that the dropdown shows
} );

Real documentation:
https://github.com/wikimedia/jquery.uls/blob/master/README.md

A simple example from the Translate extension:
https://phabricator.wikimedia.org/diffusion/ETRA/browse/master/resources/js/ext.translate.special.translate.js
(Search for the setupLanguageSelector function.)

The OPTIONS must define a callback function for onSelect.

The list of languages can (and should) be given in the languages parameter in the options. See above.

  • Making UW depend on ULS may not be a good solution. Some non-WMF wikis use this extension (against our recommendation), and we're trying to make that easier for them, but adding a dependency is something we need to seriously think about.

It can be optional.

MarkTraceur triaged this task as Normal priority.Nov 16 2016, 7:16 PM
MarkTraceur added a project: good first bug.

OK, thanks @Amire80 for the helpful response, I think we can leave this open for new people now :)

MarkTraceur moved this task from Untriaged to Triaged on the Multimedia board.Nov 28 2016, 5:35 PM
Cparle added a subscriber: Cparle.Aug 28 2017, 2:22 PM
Cparle added a comment.EditedSep 5 2017, 11:15 AM

@Amire80

Hi, I'm very new to WMF code, so please forgive my ignorance ...

By "it can be optional" did you mean that the UploadWizard should detect that ULS is installed, and if it is then it should use that instead of the dropdown?

@Amire80
Hi, I'm very new to WMF code, so please forgive my ignorance ...
By "it can be optional" did you mean that the UploadWizard should detect that ULS is installed, and if it is then it should use that instead of the dropdown?

Yes. One easy way to do it in JavaScript is to check whether mw.uls is a defined object, although @santhosh may suggest something better.

Ok cool thanks

Another quick question - should the selected language be connected/related to the IME in the description field? As far as I can make out the IME is intended to be independent of the actual language (so you can enter, for example, a Chinese quote within English text), but I'm not sure my understanding is correct

Ok cool thanks
Another quick question - should the selected language be connected/related to the IME in the description field? As far as I can make out the IME is intended to be independent of the actual language (so you can enter, for example, a Chinese quote within English text), but I'm not sure my understanding is correct

No, it's not really related.

Cparle added a comment.Sep 7 2017, 1:10 PM

@Amire80 would you have any insight into the following?

On this page http://thottingal.in/projects/js/jquery.uls/examples/ if I type the following into the js console in the browser

$('h1').uls();

... then when I click on the h1 a universal language selector pops up

But on this page https://commons.wikimedia.org/wiki/Special:UploadWizard if I enter the same into the console I get this

TypeError: $(...).uls is not a function

Any ideas?

Ugh. That's because the ULS extension's JS code is not fully loaded when you initially open the page.

At the top of the page near your username there's a link with a name of a language (if you haven't changed it, it will be "English"). Click it, and a language selection will appear. On most pages, for optimizing performance, this code that shows it is loaded only after you click it.

After the panel appears, try running $(...).uls again, and it should work.

The JS module that has the .uls() function is called "ext.uls.mediawiki". To make sure that it's pre-loaded so you'll be able to use it, try doing something along these lines:

mw.loader.using( "ext.uls.mediawiki", function () {
    $(...).uls( ... )
} );

Change 377425 had a related patch set uploaded (by Cparle; owner: Cparle):
[mediawiki/extensions/UploadWizard@master] Add ULS for language dropdown in file description

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

@Amire80 do you have any examples of where the uls is used inside a form?

Change 377425 merged by jenkins-bot:
[mediawiki/extensions/UploadWizard@master] Add ULS for language dropdown in file description

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

I see it working on Commons! This is great! Thank you very much!

Cparle closed this task as Resolved.Oct 24 2017, 8:20 AM