Page MenuHomePhabricator

Replace the last comma in a list from an #arraymap with a coordinating conjunctions (i.e. "and", "or")
Closed, ResolvedPublic

Description

When using an arraymap function to present a list of items to visitors, say from a property value, I receive each item in the array as a list.

orange, banana, apple, grape

I want that list to include the word "and" for the final item in the list as the coordinating conjunctions(as what happens in the SMW Factbox for properties with multiple values).

orange, banana, apple, and grape

That fruity example is not incredibly applicable. I use #arraymap to display a list of authors for a particular news article on my wiki.

By: Chris, Sam, and Yolanda.

I'm a fan of the Oxford Comma, but that would require additional settings to use/not use.

A simple conjunction=and or conjunction=or syntax would suffice for many uses.

Briefly discussed at the SF Extension talk page.

Event Timeline

Ckoerner raised the priority of this task from to Needs Triage.
Ckoerner updated the task description. (Show Details)
Ckoerner subscribed.

Is this issue about adding the conjunction to the last list item in the list of items in a page which is created from a form?

@Yaron_Koren Do you think that should I take this task?!
I think it needs adding a new parameter (in the same way we solved the parsing micro task), conjunction, and find the loop that prints the values, and check the last element to put the conjunction before.
Am I in the right direction of thinking?!

Change 583949 had a related patch set uploaded (by Amr El-Absy; owner: Amr El-Absy):
[mediawiki/extensions/PageForms@master] Replace the last comma in list from #arraymap with a conjunction

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

@AmrEl-Absy - sorry for not responding before. This is a clever solution, and I'm impressed that you thought of it, and implemented it. I have a few comments, which I'll make in the patch.

Change 583949 merged by jenkins-bot:
[mediawiki/extensions/PageForms@master] Replace the last comma in list from #arraymap with a conjunction

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

@AmrEl-Absy - I'm re-opening this because it led to a bug with the handling of "\n" - see the comment at the end of the Gerrit patch. Can you please look into this when you get the chance?

Change 591924 had a related patch set uploaded (by Amr El-Absy; owner: Amr El-Absy):
[mediawiki/extensions/PageForms@master] Handle the "\n" in the conjunction

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

Change 591924 merged by jenkins-bot:
[mediawiki/extensions/PageForms@master] Handle the "\n" in the conjunction

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

Okay, I'm closing this again - I believe the bug has been fixed.