Help talk:TemplateStyles

Jump to navigation Jump to search

About this board

Phillipm0703 (talkcontribs)

I tryed to change my page "Template:Ahnentafel/styles.css" from "wikitext" to "sanitized_css" via "Spezial:ChangeContentModel". But now there is an text: [f45af79187c45d67cf8831aa] 2019-09-20 08:37:36: Fatal exception of type "Error"

What do I wrong? I installed and activated the Extensions CSS, TemplateStyles and Scribunto.

Anomie (talkcontribs)

You should start by finding the error in your logs (look for that "f45af79187c45d67cf8831aa" identifier). If nothing else, you could then post it here (including the backtrace) so we can see what exactly the error was.

Reply to "Sanitized Css"
CaiusSPQR (talkcontribs)

Wikipedia uses the 1000 px as a breakpoint for desktops. Does that apply for laptops as well?

Foolproof way to add the templatestyles tag?

Nirmos (talkcontribs)

Extension:TemplateStyles as well as Help:TemplateStyles is a bit vague as to how exactly the templatestyles tag should be added. So far, I have just prepended it to the template's wikitext, but as can be seen in sv:Special:Diff/42452572, this does not always work. Is there any foolproof way to add the templatestyles tag to a template?

Tgr (WMF) (talkcontribs)

That should work just fine (did you mean to write Mall:Audio/styles.css instead of Audio/styles.css?) but ideally you should scope the styles to the template, ie. write something like

<div class="my-template">
<templatestyles src="Template:MyTemplate/style.css" />
.my-template {
Tgr (WMF) (talkcontribs)

(Note, the position of the <templatestyles /> tag doesn't matter, it could be outside of the div. The point is to make sure the styles do not have effect outside of the template.)

Nirmos (talkcontribs)

The namespace prefix is optional, so that's not the problem. If you look at my contributions in the template namespace on svwiki ( you can see that I've successfully added templatestyles tags to several templates. In this case, however, the template starts with wikitext syntax for a table, that needs to start on its own line, and apparently does not tolerate a templatestyles tag before it.

Nirmos (talkcontribs)

And sure, you could say that it needs to be wrapped in a div, but then the user has to know that, and it would need to be documented. Moreover, some templates do not have divs as their outermost structure. For example, infoboxes, navboxes and amboxes (the Big Three in the template world) all have table as their outermost element.

Tgr (WMF) (talkcontribs)

The div is not the point, the class could just as well be on the <table> element. The point is that styles should not leak out of the template, otherwise you'll be facing a maintenance nightmare.

Nirmos (talkcontribs)

FWIW, I tried to do the same but with table tags in HTML instead of wikitext, but still got the same problem.

Tgr (WMF) (talkcontribs)

So the problem is how to use a templatestyles tag without making the parser wrap it into an empty paragraph?

I guess you could go with

|}<templatestyles />

although it's a bit ugly to put the style tag after the content it is styling, but the table would have to be really huge to cause a FOUC...

Using HTML table tags would work fine, but then that makes the code much harder to read.

Anomie (talkcontribs)
So the problem is how to use a templatestyles tag without making the parser wrap it into an empty paragraph?

That's an issue with the Parser, IMO. Or maybe RemexHtml, since currently HTML Tidy is handling it. Filed as phab:T186965.

Nirmos (talkcontribs)

Using HTML table tags instead of wikitext does not solve the problem as I said above, but placing the templatestyles tag after the table actually does! Still, do you not agree that this should be solved properly? Otherwise, when TemplateStyles is deployed widely, people will almost definitely add templatestyles tags to infobox/navbox/ambox and break an enormous amount of pages.

Nirmos (talkcontribs)

Correcting myself: I said above that converting from wikitext table syntax to HTML table tags did not solve the problem. It does. I have created a minimal test case at sv:Användare:Nirmos/sandlåda where I've tested various combinations. So there are two workarounds. Still, I don't like any of them. Converting from wikitext table syntax to HTML table tags can be a lot of work, can break things, and have nothing to do with the migration of styles. Placing the templatestyles tag after the template is unintuitive, can create a FOUC, and is not according to docs. (talkcontribs)

There is an example on the subject that is identical to what you want to do. It seems that you expect it to work like the (no)include tags, and those explicitly behave as if they are not there at all. Visually, there doesn't seem to be any difference anyway.

Reply to "Foolproof way to add the templatestyles tag?"
IKhitron (talkcontribs)

Hi. I don't understand. Is there a chance that TemplateStyles tag has nothing to do with templates? Because I tried to add the tag in mainspace, and it works. Thank you. (talkcontribs)

Yes, currently the only link to templates is the fact that it must be added to the template namespace (although it can be configured differently - Extension:TemplateStyles). It also seems that originally the templatestyles tag could only be added to the template namespace, as it would have no effect anywhere else. That's where it got its name from, aside from its primary usage planned in templates rather than pages.

Perhaps eventually they could all be moved to a dedicated namespace, e.g. Styles:Mainpage.css . In fact it is already possible,because any community can ask for an extra namespace, and those with the rights to change the content model can add as many styles there as they want.

It might be a good idea to read up on the background history of the tool (Requests for comment/Allow styling in templates).

IKhitron (talkcontribs)

Thank you for your answer. You just said "as it would have no effect anywhere else". Why do you think so? It's definetely wrong. Usage in other namespaces makes it more powerful dozens of times. (talkcontribs)

> It's definetely wrong. Usage in other namespaces makes it more powerful dozens of times.

You misunderstood. The <templatestyles> tag could only be added to the template namespace. The template in which it was added could be transcluded everywhere, and its styles would apply to content in the template.

At some point they removed that limitation, and now the <templatestyles> tag can be added everywhere. You can see the huge discussion about it here ( and in

I also tried it at the time, so it was definitely working like that before they changed it.

IKhitron (talkcontribs)

So, what do you think, it helps in other namespaces or not? (talkcontribs)

It is certainly helpful to use in other namespaces. although it needs to be used cautiously. People might start adding it to signatures, and other unnecessary places. It will be really chaotic because sitewide css allows users to add frivolous features like blinking stuff, marquee, spinning things random transitions, and much more. (talkcontribs)

I'm not sure if any of those animations are whitelisted though.

IKhitron (talkcontribs)

Yes, it can be a problem. But the question is: Can I be sure it will work for mainspace forever or long enough? Because is so, it's much easy to use, and I can ask the commubity to deploy it now. (talkcontribs)

The whole purpose of the extension is to reduce the need of inline styling in the main namespace (and templates), so as long as that goal doesn't change it will continue to work there.

Whether it will work forever, or long enough is something only the developers (or their bosses) can answer.

IKhitron (talkcontribs)

It's not just inline. It actually resques RTL wiki from a huge problem we had before. And usage in mainspace will allow all the users make it easily, not just some that work with templates. How can I ask them, please? (talkcontribs)

One of their potential goals is to completely get rid of inline styling (

My guess is that they will keep it. Performance in some pages is pretty horrible because of an exaggerated number of html tags, and the inline styling added for them.

Anyway, phabricator would probably be the right place to ask about whether adding these tags directly to the namespaces is a feature or a bug, and whether it will remain if it is a feature.

IKhitron (talkcontribs)

Don't sure it's a good idea. How can I ask in phabricator? You mean some old task? (talkcontribs)

Just to be clear, my guess is that they'll keep templatestyles, and completely kill off inline styles.

Although the process of disabling inline styling will probably take many years. (talkcontribs)

Either a new task or maybe Since it is an RFC, and it still hasn't been closed, the final configuration for the implementation is probably still being discussed.

IKhitron (talkcontribs)

Thank you very much for your help. (talkcontribs)

You're welcome.

Tgr (WMF) (talkcontribs)

At some point use of the tag outside of templates might become forbidden. Ideally the CSS should be scoped to the template the tag is used in, and not affect other parts of the article, but that was implausible with current technology.

IKhitron (talkcontribs)

Thank you, Tgr (WMF). Could you tell me, please how vandal actions are prevented until then? As black background color, white font color or 15% font size? Maybe only autopatrolled users can edit sanitized css or something?

Tgr (WMF) (talkcontribs)

They aren't; vandalism enabled by TemplateStyles is not particularly worse than plain inline styles vandalism. (Which is to say, you can already do pretty nasty things via inline syles.) That can be changed if it proves to be a problem. See also the FAQ answer.

(For context, the project focused on technical issues so far and had no product owner. Soon it will get one, so it's possible some decisions or priorities will be reevaluated.)

IKhitron (talkcontribs)

Thank you, Tgr. It looks as bad news. ערן, what do you think?

ערן (talkcontribs)

I agree with the last answer of Tgr, that vandalism by TemplateStyles is not worse than plain inline vandalism.

IKhitron (talkcontribs)

Ok, you are the boss.

Anomie (talkcontribs)

I have no plans and know of no plans to remove the ability to use <templatestyles> outside of templates. I can't promise the Editing Contributors team might not try to do that in the future though. They've already reserved the right to make the styles not apply to any content outside of the template that actually contains the tag.

For vandalism of stylesheets themselves, the primary mechanism is to protect the stylesheets as you'd protect any template. It would probably be possible to set a default protection level for everything that uses the content model, but since most problematic things that can be done with TemplateStyles can be done with inline CSS too that doesn't seem like something that needs attention right now.

For vandalism by including a stylesheet onto a page, again, since most problematic things that can be done with TemplateStyles can be done with inline CSS too that doesn't seem like something that needs attention right now.

IKhitron (talkcontribs)

Thank for your answer, Anomie, but there are two huge differences between inline vandalism and stylesheet. One: The last does not appear in watchlist of users that watch the page, not the stylesheet. Two: if user that watches some page see anonime user changed something in line 55 of page, and they does not know css, they can see the line 55 result and check if it looks reasonable. If they even knew about stylesheet edit, they can't know where they should look in the page without some css master help. So I thought that only autopatrolled should edit sanitized css, it will resolve these problems. Am I wrong?

Anomie (talkcontribs)

Your "One" applies equally well to template vandalism, and communities already deal with that. They should deal with TemplateStyles stylesheets in the same manner.

Your "Two" doesn't make sense. They can see the diff of the TemplateStyles stylesheet as easily as they can see the diff of a wikitext page. In neither case does MediaWiki say "line 55" and expect the user to figure out which line that is. Unless you're trying to say that they'd have to understand CSS well enough to figure out what a change to the stylesheet is going to do to the page as a whole? But even then, a change in a complex module or template is unlikely to be clear to someone unfamiliar with Lua or complex wikitext in the same way.

IKhitron (talkcontribs)

Well. Anomie: We deal with template vandalism by protecting templates that used in 10,000 articles for example. Here it will be used in one article.\ About two: neither. The css font-size:35% added to text can be checked immediately. When it added to class name, you should understand how to find where this class is used - how to find affected places in the article.

Reply to "Not a template"
IKhitron (talkcontribs)

Hello. I'd like to create a small demo for TemplateStyles for our wiki users, when I solving some problems that are very painful to us and do not matter to other wikis. When I saw today that the extension is already deployed to mediawiki, I came here to write it, starting from stupid example and extending it, but it does not work. As I can see, because ns-2 does not create sanitized css files. What can I do? Use another namespace to play with? Ask an admin to use special:changecontentmodel (I even don't know if it will work)? What is the content of $wgTemplateStylesNamespaces on MediaWiki at all? Thank you.

Anomie (talkcontribs)

Special:ChangeContentModel is the method to create sanitized CSS pages in cases where that doesn't happen automatically. (talkcontribs)

As the subject page notes this only works on the template namespace. Unless  you can change the content model of a page.

You might want to use the beta wikis to experiment  rather than create unnecessary template css here.

See examples on the page.

IKhitron (talkcontribs)

Thank you for your answer. Beta wiki is not a good choice, because it is not a part of global accounts, and I need that anyone could login from theirs account. Am I allowed to create a template for my purposes in Template namespace? Or: You said "unless". Am I allowed to ask an admin to convert one page in user namespace to be sanitized css, to work with it? Thank you. (talkcontribs)

test.wikipedia is part of the global account system and should have it.

As far as creating test template CSS here. Sure, it should be allowed. Much like how test lua modules are created as a subpage of a sandbox module. If in doubt one can ask in the central discussion area of this wiki.

For Admins, as long as it is within your user subpage it is likely that they won't mind. The problem of course is that both css and sanitized css pages end with CSS but behave differently.

You might want to use the beta wikis to experiment  rather than create unnecessary templates here CSS but behave differently. (talkcontribs)

Oops, last section was pasted incorrectly.

IKhitron (talkcontribs)

Didn't know about testwiki global. Moved there. Thank you.

Reply to "Sanitized css"
He7d3r (talkcontribs)
The <templatestyles> tag should be placed before the content that is styled, e.g. at the top of the template

Does that mean the template should also be added/moved to the top of the articles where it is used in case it contains styles used in more than a single section of the article?

Tgr (WMF) (talkcontribs)

<templatestyles> should only be used to style content that's contained or enclosed in the same template. If that's the case, it doesn't really matter where you place the template, as the <templatestyles> tag will always precede the styled content.

Anomie (talkcontribs)

If a template is supposed to affect content outside of the template itself, it should probably appear before that content. But ideally most templates will style only their own content so such placement doesn't matter.

Note that the Editing Contributors team has reserved the right to force templates to style only their own content in the future. Actually doing that would require some other significant changes to how templates work (e.g. T114445).

TheDJ (talkcontribs)

There's also some interesting points about Template fragments,, this feature and the future desires of VE of course.

If you look at templates that only output: <code>--data-sort-value="sortkey" |</code> to apply sorting to a table cell... That's just.. interesting.

Reply to "top"

Is it reasonable to use the tag directly inside a page?

1 (talkcontribs)

The caveats section clearly notes that users shouldn't expect that a template allows its styles to propagate outside it. But a simple syntax that may be used instead is basically using the tag directly in an article, e.g.:

<templatestyles css = "Template:mypage/styles.css" >

My article text goes here

Considering that most pages can essentially be used as a templates (except those with special content models), the distinction doesn't seem clear cut.

While some editors and wikis would probably be against such "ugly" markup there may be legitimate uses in non-mainspace pages or even in a main page for example.

Reply to "Is it reasonable to use the tag directly inside a page?"
Anomie (talkcontribs)

The zebra-table demos are using an ability (to affect content on the page outside of the template's output) that is specifically warned against in Extension:TemplateStyles#Caveats.

Personally I don't care much for that restriction, but some others really want it. Perhaps the demo should be changed to avoid doing that. (talkcontribs)

Irony fixed. Something like that is needed for crazy pages such as this:

It had around 7000 template calls just to add a different color to some links, it also had more than 10000 unnecessary html span tags just to also change color of certain links.

While that's a horrible case caused by user ignorance, it still highlights the fact that currently adding repetitive styles to pages is a inefficient. Bloating common.css with these would also not solve the problem in a huge wiki such as german wikipedia, nor would changing those 7000 templates to call TemplateStyles internally.

That particular case was changed, but the underlying problem remains. Although it could be argued that it isn't a problem meant to be solved by this extension.

Perhaps that could work in a future "page styles" tool, or something similar. (talkcontribs)

If there is one thing mediawiki developers probably realized by now it is that any mechanism added to a wiki will be abused (templates -> slow pages, gadgets -> broken pages and features) . If this ironic usage is an anti-pattern, it might be a good idea to start thinking about ways to minimise its impact or abuse.

Experience tells us that the best way to avoid such abuse is to break things hard and fast whenever they happen.

Reply to "Demo irony"

Combine with Extension:TemplateStyles/Q%26A ?

2 (talkcontribs)

Looks good overall, but maybe it needs to be combined with Extension:TemplateStyles/Q%26A .

Or perhaps a simple link will suffice.

Anomie (talkcontribs)

Extension:TemplateStyles/Q&A doesn't seem to have anything to do with this page. That was a survey to get feedback about possible implementation methods, which has since been decided. This is end-user documentation.

Reply to "Combine with Extension:TemplateStyles/Q%26A ?"
There are no older topics