Page MenuHomePhabricator

Add a 'mw-collapsible-header' class to 'mw-collapsible' scheme
Closed, ResolvedPublic

Description

This idea has been implemented using a different class name: mw-collapsible-toggle-placeholder – documentation: https://www.mediawiki.org/wiki/Manual:Collapsible_elements#Custom_toggle_link_placement


Now it is impossible to create a semantic block, such as https://en.wikipedia.org/wiki/Template:Collapse, , but using div. Tables are not the correct usage for such blocks and are difficult to manage. The main problem is that in the current implementation of mw-collapsible it is not possible to add hide/show button in header for div scheme.

image.png (49×561 px, 1 KB)

I ran into this when I tried to update the template in Russian Wikipedia (https://ru.wikipedia.org/wiki/Шаблон:Начало_скрытого_блока), but I had to rewrite the default NavFrame classes. NavFrame used now in many wikis (https://ru.wikipedia.org/w/index.php?title=MediaWiki:Common.css&oldid=111660712#L-1152) allows you to create a heading with a button, but does not allow you to manage this button, place it on the right or left, I had to expand this functionality with extra classes: collapsibleBox-title-titleAlgin and collapsibleBox-title-hideLinkAlign (https://ru.wikipedia.org/w/index.php?title=MediaWiki:Common.css&oldid=111660712#L-1213).

image.png (133×684 px, 13 KB)

I think we need to add 'mw-collapsible-header' class to 'mw-collapsible' scheme for easy creation a non-tabled collapsible boxes. It will help us to move standard toggle button into a title div.

Current DOM

<div class="mw-collapsible">
<span class="mw-collapsible-toggle">Button</span>
<div>Title</div>
<div class="mw-collapsible-content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>

Expected DOM

Perhaps I was wrong somewhere in the semantics and it needs to be improved further.

<div class="mw-collapsible">
<div class="mw-collapsible-header"><span class="mw-collapsible-toggle">Button</span>Title</div>
<div class="mw-collapsible-content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>

Links

Event Timeline

This seems like a solution to a problem that is not well defined. Please provide real world examples.

Do you mean that you want the ability to indicate inside wikicode where you want the toggle to be positioned ?

Do you mean that you want the ability to indicate inside wikicode where you want the toggle to be positioned ?

This is one of two options. But I was referring to the behavior of a button for a table's title.

@Iniquity my question is WHY do you need a mw-collapsible-header class?

You seem to say that your problem is with positioning the toggle ? Yet your ticket asks for adding a class, which will not manage the positioning of the toggle.. This confuses me.

@TheDJ It's just one of the solutions, which I think most rapidly achievable. This is a copy of the solution for navframe, which I want to replace in ruWiki.

asks for adding a class, which will not manage the positioning of the toggle

If you add the mw-collapsible-header class for div then toggle block must be putted in it.

@TheDJ Did I give the right description? Or still have questions? Sorry for it :(

So I just rebuild NavFrame, using mw-collapsible

https://test.wikipedia.org/w/index.php?title=MediaWiki%3ACommon.js&type=revision&diff=352561&oldid=339661
Demo: https://test.wikipedia.org/wiki/Wikipedia:NavFrame?debug=true

I found some trickery around this problem, by postprocessing the collapsible and moving the toggle, but I'm not particularly happy with it. Maybe we need a new option for makeCollapsible, to indicate a selector for the parent of the togglelink.

The problem with just randomly introducing a mw-collapsible-header, is that it is either too inflexible (only suited for one specific case) or too loose (esp. problems with nesting).

Thanks for you example! Anyway I hope you add a new option for makeCollapsible ;)

Jdlrobson changed the task status from Open to Stalled.Jan 20 2021, 2:38 AM
Jdlrobson subscribed.

What is the problem statement here? What are we trying to achieve? I don't really understand what this bug report is about. Has anything changed since 2018 that might lead us to want to decline this?

What is the problem statement here? What are we trying to achieve? I don't really understand what this bug report is about. Has anything changed since 2018 that might lead us to want to decline this?

Hi, Jdlrobson. I don't really remember why I created this task anymore. Perhaps I wanted to implement the NavBar mechanics for 'hidden' templates: https://ru.wikipedia.org/wiki/Шаблон:Начало_скрытого_блока.
https://ru.wikipedia.org/w/index.php?title=MediaWiki:Common.css&oldid=111660712#L-1152

If you remember please feel free to reopen. Am trying to get the backlog into a more manageable state, so we can service these kind of requests better in future!

I just remembered, I was unable to make the https://ru.wikipedia.org/wiki/Шаблон:Начало_скрытого_блока template purely on mw-collapsible. Unable to create hide/show link in header.

Alas, English version of Template:Collapse is made on tables, which is not semantic. And it requires additional code, which is no different from the NavFrame.

Iniquity updated the task description. (Show Details)

Alas, English version of Template:Collapse is made on tables, which is not semantic. And it requires additional code, which is no different from the NavFrame.

What is the semantic value of divs? Which additional code?

What is the semantic value of divs?

Tables represent tabulated data, not all content that needs to be hidden: https://www.w3.org/TR/WCAG20-TECHS/H51.html

Which additional code?

To control the position of the hide button. But this is most likely required in my version, so we can omit it :)

The only issue I ran into in the several hundred moves from NavFrame to mw-collapsible I did to support removal from Common.css is that NavFrame has position absolute/relative etc. for its buttonology and mw-collapsible does not. This causes some grief with jumpy centered text, but even that only requires going from <div class="NavHead">Title</div> to <div style="some styles"><div style="margin: 0 4em">Title</div></div> to hack around plus some moderate CSS from Common.css.

I don't fundamentally see a need for core to support a header concept at this time, and especially now that TemplateStyles exists I'm pretty sure someone could do the work with that to make everything work the way it should. Regarding the template in T185674#6789763, it looks like someone did just that (see page history).

Speaking specifically to collapse top, I'm pretty sure that's simply a matter of removing the tables and could be remedied as soon as anyone who was interested did so.

I coded around this issue in https://ru.wikipedia.org/wiki/MediaWiki:Common.js#L-163 because some ruWP templates did not work correctly because of this:

I think the header concept is viable, but also pretty easy to hack around.

I found this task by accident when looking for something else, and I realized that a very similar feature has been implemented last year in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/897905 by Lucas. Rather than marking some element as a "header", you can mark exactly where you want the toggle to be placed using <div class="mw-collapsible-toggle-placeholder"></div>. I think that would work for all of the listed use cases.

Would anyone like to try to update some of the templates to use that? If everything works as expected, I'd like to close this task.

Interesting. Updated https://ru.wikipedia.org/wiki/Шаблон:Оригинальный_текст to use it, seems to function as intended. I guess this covers all the cases then.

@matmarex thanks for the info :) I think yes, this solves the problem with headers!

matmarex assigned this task to Lucas_Werkmeister_WMDE.
matmarex updated the task description. (Show Details)

Thanks for checking.

By the way, when I looked at that template, I noticed that the page content shifts a little bit when the toggle is added by the script:

Screen Shot 2024-04-16 at 18.57.06.png (800×1 px, 123 KB)
Screen Shot 2024-04-16 at 18.57.40.png (800×1 px, 123 KB)

We usually manage to avoid that for collapsible elements, and I think we can extend that solution to handle the new placeholder toggles as well. Patch pending review: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1020287

(Russian Wikipedia has some overrides for the styling of toggles in MediaWiki:Common.css and in TemplateStyles, you'll need to update them to also apply to .mw-collapsible-toggle-placeholder for this to look good.)

@matmarex replying here instead of onwiki: this is this code in jquery.makeCollapsible styles
https://gerrit.wikimedia.org/g/mediawiki/core/+/67f80e68bf5534d5de317c4ee892707d18760ade/resources/src/jquery/jquery.makeCollapsible.styles.less#46

I did want to make a note about updating the styles to account for it, but I don't see a proper way to detect if .mw-collapsible-toggle-placeholder is inside, so I don’t think one is viable. And I tried making it styled differently before so it doesn’t look like a jump but it doesn’t work with the layout we have.

Ah. Disregard. Misunderstood what you were trying to convey to me onwiki.