(Translated by https://www.hiragana.jp/)
⚓ T176272 Decide on what to recommend for table style usecase
Page MenuHomePhabricator

Decide on what to recommend for table style usecase
Open, LowPublic

Description

The guidance we give for TemplateStyles is to assume that the CSS won't apply outside of the template which contains the <templatestyle> tag (although this cannot be technically enforced yet). See e.g. caveats, item 3.

This is at odds with an important use case: styling article content, especially templates, which tend to involve repetitive inline styles and can look quite monstrous (see this table as a random example). Since the content comes from the article itself and not a template, there isn't really any way to apply CSS to the table while keeping it inside the DOM node(s) of the template. One could use a wrapper template:

{{wrapper|content=

...lots of wikitext here...

}}

but that will break VisualEditor which cannot visually edit template parameters; and turns | into {{!}} in the wrapped wikitext, which is a nightmare for large tables.

In the long term, heredoc template syntax (T114432) might be the solution; for now, we need to decide what guidance to give on current usage patterns of TemplateStyles. Tables in articles are an important use case and we shouldn't discourage people from fixing it, but we also do not want for everyone to fix it differently, and probably want to track such out-of-template-scope usages in some way.

Event Timeline

Deskana subscribed.

This is not an immediate priority for the initial deployment of TemplateStyles.

Putting the template with the styles after the table might result in a FOUC (although not a huge deal as long as it's just colors and no layout-related rules).

Moving my comment from the dupliacte here :

Currently on English Wikipedia, there are a number of tables which use inline CSS formatting to achieve certain effects such as alignment of text, or specfic bordering styles.. Mediawiki as configured on English Wikipedia provides a 'wikitable' class which provides a nice looking set of styling for some tables.

However, by comparison English Wikisource currently provides a table style template: https://en.wikisource.org/wiki/Template:Table_style which provides a number of short code sequences (currently upto 9) to apply various forms of table formatting. The current implementation of this template is a directly coded MASSIVE parser function, which to add new codes requires that the /parse portion of the template be updated directly, and has performance implications..

A better way of doing this to me would be to have an equivalent of TemplateStyles for Tables, allowing relevant styles to be applied on a per table basis, albiet the stylesheet(s) for a given sequence of tables may be the same stylesheet page located elsewhere on a given wiki.

The TableStyle template itself could then be altered so that the short codes are converted into name munged class names in a common CSS defined style sheet, such that new codes could be easily added to the style sheet, without needing to alter the core logic of the TableStyle template itself...

Also Could TemplateStyles could be used on certain non-template WikiPages, where a commonality of styling without using inline CSS would be desirable?

Please note that all efforts with TemplateStyles always need a collision-free class naming policy.

  • No class name of one local TemplateStyles page must conflict with any other in the same project.
  • No class name of a TemplateStyles page must collide with a global MW class name.
    • Please note that not all MW classes are preceded by mw- prefix.
    • There is no dictionary of all basic MW classes available, nor an explanation of promised effect.
    • Nobody can check whether the same class name is reserved for MW purposes already.
  • For exchange between projects, gadget usage and so-called “global templates” and “global modules” a global registry of class names is required first, to ensure that a local class name will not collide with another one, and the same class name will have a similar and expected effect when copied into a different project.

How is any of that relevant to the table use case?

It refers to the suggestion to use TemplateStyles for equipping of a particular table. However, nobody can introduce a class table-something without the risk of collision with other specification of the same class name but other effect in global things.

The minimum to use classes rather than inline styles would be to provide a global class name dictionary by MediaWiki without any implementation, which has to define class names and expected effect, preceded with mw-.

It refers to the suggestion to use TemplateStyles for equipping of a particular table. However, nobody can introduce a class table-something without the risk of collision with other specification of the same class name but other effect in global things.

The minimum to use classes rather than inline styles would be to provide a global class name dictionary by MediaWiki without any implementation, which has to define class names and expected effect, preceded with mw-.

None of that is specific to this task. Please take your suggestions elsewhere where they might be heard in the right context.

Seeing as there hasn't been significant discussion here... I intend to remove the plainrowheaders class from Common.css on en.wp (pending a bot and community consensus), which will necessitate wikitext which is directly the topic of this task as well as

Styles included by a template can currently affect content on the page outside of the content generated by that template, but this ability may be removed in the future and should not be relied upon. (See discussion from phab:T155813#2996589 and in phab:T176272.)

from https://www.mediawiki.org/wiki/Extension:TemplateStyles. The reason I'm letting the task know is that this change would affect approximately 90k pages that will likely spread to other wikis (never mind largely letting the cat out of the bag on en.wp), so this is kind of a "speak now or forever hold your peace" notice here. Appropriate discussion would be appreciated if/when some reality were to occur where that warning were to be relevant. (I am not personally a fan of it, since I see little to no reason to restrict the output of styles to some content that it is transcluded with, from the user point of view. And including the TemplateStyles tag everywhere would be categorically worse from a learning perspective. What little comment there was in the discussions that lead to that note seemed more interested in 'what the users would do' before settling on that answer that remains irrelevant today and may never be relevant.)

The usage instructions of the template of interest will indicate to use wikitext like the below:

{{plain row headers}} <!-- containing the TemplateStyles definition for .plainrowheaders -->
{| class="wikitable plainrowheaders"
|+ Wikitable with plain row headers
|-
! scope="col" | Col header
! scope="col" | Col header
! scope="col" | Col header
|-
! scope="row" | Row header
| A
| B
|-
! scope="row" | Row header long
| C
| D
|}

The template is already created, I just haven't started doing anything with it as I needed to get this note posted and time for discussion to occur.

In respect of English Wikisource, I only found 1 usage of the class directly. However, there are a moderate number of Pages that have scope=row and a manual override on each cell. A number of these would benefit from a table style approach.

(Subsequent to my now merged ticket, IndexStyles was implemented on English Wikisource and hence a form of TableStyles can be implemented using classes
defined on a per Index basis, which partially resolved the now merged ticket.)

https://ru.wikipedia.org/wiki/Шаблон:Стиль_столбцов which basically styles any table with specific classes has around 800 uses already. So I’m guessing that any recommendations that can be made should be made sooner than later, since more and more wikis are going to do this because of its convenience.