Hi!
We at plwiki are in progress of refactoring the inplementation of standard {{mbox}} template family and unifying them into a single template. One of the tasks is to port these to TemplateStyles, instead of relying on global styles defined in MediaWiki: namespace.
While it's quite easy for majority of the templates, an issue is {{fmbox}}, which is commonly used on special pages, edit intros, and edit notices. In these places, TemplateStyles don't work out of the box. An approach that I've thought of is to automatically wrap the actual message box with div of mw-parser-output class if the template is transcluded in these places, so as to enable TemplateStyles. (And do it conditionally, to have a common mbox for in-content and in-interface messages).
Detecting whether we're at a special page should be pretty easy – checking the {{NAMESPACE}} should suffice. However, I don't think this will work for e.g. edit notice (I'd get the namespace of the edited page).
So here comes the question: is there a reliable way to check when a template is transcluded outside of the standard page content (i.e. outside of .mw-parser-output)? Or, alternatively, to safely enable TemplateStyles in all places a template can be transcluded in, without breaking anything related to actual wiki content?
Regards and thanks in advance, Marcin User:Msz2001
I don't think this is possible, sorry. Why not have a special template for use on special pages? Making code more complicated just to avoid "duplication" sounds like something we discuss in software development all the time – and typically try to avoid.
The two templates can still share most of their code, e.g. the special one can call the normal one and add the mentioned mw-parser-output wrapper.
Kind regards Thiemo
Of course, having two templates like you said is a possibility (and perhaps the optimal way).
It still has a downside, however – people have to remember that in certain scenarios you have to use a special template (even though the common one will – confusingly – appear correct on the page where you configure the editnotice etc.).
Anyway, thanks for the answer. Marcin ________________________________ From: Thiemo Kreuz thiemo.kreuz@wikimedia.de Sent: Friday, November 29, 2024 3:11:21 PM To: Wikitech-l wikitech-l@lists.wikimedia.org Subject: [Wikitech-l] Re: Checking if template is rendered outside page content
I don't think this is possible, sorry. Why not have a special template for use on special pages? Making code more complicated just to avoid "duplication" sounds like something we discuss in software development all the time – and typically try to avoid.
The two templates can still share most of their code, e.g. the special one can call the normal one and add the mentioned mw-parser-output wrapper.
Kind regards Thiemo _______________________________________________ Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
Having two templates is the nicer solution, but you could just wrap them unconditionally - being wrapped twice shouldn't be a problem.
FWIW there is a task for wrapping edit notices: https://phabricator.wikimedia.org/T337640
Thanks for the link.
About wrapping unconditionally - well, I'd like to avoid it. I checked over the codebase and for now it shouldn't be a problem, but who knows what the future will bring :). (and BTW, adjacency rules like `.mbox + .mbox` are more readable this way).
I've however prepared a general template like {{Activate TemplateStyles|...}} so that all templates (not only mboxes) could potentially benefit from that without the need to remember what's so magical in a div. In the end, I've also created a separate {{Editnotice}} template that wraps normal {{mbox}} and additionally attaches some CSS that adapts the template to very narrow containers, for instance in VE, and gets rid of a MobileFrontend magic (bleh...).
During the work with unifying all the mbox flavours (which finished like a few days ago), it turned out that mw-parser-output, apart from {{Editnotice}}, was needed on like 2 or 3 pages on plwiki which made my apply the described approach. Initially I've thought that it'd be worse, but – well – I discovered that legacy code in interface messages preserves very well :)
Msz2001
W dniu 19.12.2024 o 21:30, Gergo Tisza pisze:
Having two templates is the nicer solution, but you could just wrap them unconditionally - being wrapped twice shouldn't be a problem.
FWIW there is a task for wrapping edit notices: https://phabricator.wikimedia.org/T337640
Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
wikitech-l@lists.wikimedia.org