Template talk:Infobox drug
Template:Infobox drug is permanently protected from editing because it is a heavily used or highly visible template. Substantial changes should first be proposed and discussed here on this page. If the proposal is uncontroversial or has been discussed and is supported by consensus, editors may use {{edit template-protected}} to notify an administrator or template editor to make the requested edit. Usually, any contributor may edit the template's documentation to add usage notes or categories.
Any contributor may edit the template's sandbox. Functionality of the template can be checked using test cases. |
This is the talk page for discussing improvements to the Infobox drug template. |
|
Archives: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19Auto-archiving period: 3 months |
This template does not require a rating on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | |||||||||
|
Infobox drug: Changes log
|
---|
Add a Tmax field
[edit]This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
Diff:
− | + | Tmax |
Hplotter (talk) 13:52, 24 July 2024 (UTC)
- Not done: it's not clear what changes you want to be made. Please mention the specific changes in a "change X to Y" format and provide a reliable source if appropriate. – Jonesey95 (talk) 23:25, 24 July 2024 (UTC)
- It is very clear if you know what Tmax stands for Hplotter (talk) 13:14, 25 July 2024 (UTC)
- @Hplotter: I agree with Jonesey95—you need to be more explicit (please). —DocWatson42 (talk) 13:03, 27 July 2024 (UTC)
- I want to add a field for Tmax values. Hplotter (talk) 13:24, 27 July 2024 (UTC)
- @Hplotter: I agree with Jonesey95—you need to be more explicit (please). —DocWatson42 (talk) 13:03, 27 July 2024 (UTC)
- In support of adding a field for Tmax values.
- @Jonesey95: I believe @Hplotter wants to add a new field under "Pharmacokinetic data," which currently has eight fields/parameters in use.
- Under pharmacology (specifically pharmacokinetics), Tmax i.e., peak plasma concentration would be useful as that would provide greater insights into drug efficacy and toxicity. ElectronCompound (talk) 13:16, 24 September 2024 (UTC)
- It is very clear if you know what Tmax stands for Hplotter (talk) 13:14, 25 July 2024 (UTC)
- Can something be done about it, please? Hplotter (talk) 13:40, 13 August 2024 (UTC)
- Yes: edit {{Infobox drug/sandbox}} to show the changes that you wish to see. – Jonesey95 (talk) 13:32, 24 September 2024 (UTC)
- I've made the change but the field does not render, can you fix it please? Hplotter (talk) 16:42, 26 September 2024 (UTC)
- Yes: edit {{Infobox drug/sandbox}} to show the changes that you wish to see. – Jonesey95 (talk) 13:32, 24 September 2024 (UTC)
Chemical structure images are poorly visible in dark mode
[edit]Hello,
As Aminabzz pointed out at the Teahouse and 0dorkmann mentioned above, pages that use this infobox to show a chemical structure do not work well in dark mode. The SVG files used to represent the structures use dark lines, which become almost invisible on the black background of dark mode. Using ranitidine as an example, this is what its infobox looks like in dark mode.
As it turns out, there are MediaWiki recommendations for handling this issue: specifically, to apply the skin-invert
or skin-invert-image
classes to elements wrapping the image. This applies a CSS invert filter to the image, making it readable in dark mode.
Using my browser's dev tools, I tested applying the skin-invert-image
class to a span
element wrapping the image for ranitidine. The result looks like this, which I think is pretty good - the lines turn white and the structure is readable.
However, I don't think the solution is as easy as indiscriminately adding a skin-invert-image
wrapper to all the image fields in this infobox. For example, this is what happens if I do the same thing for the image of the 3D structure of ranitidine; much of the color contrast in the picture is lost.
So, I figured I'd post this here to see what thoughts people have. I suppose indiscriminately forcing a white background for any images within this infobox would technically solve the problem, but may not be the most aesthetically pleasing approach. Another option might be to add a parameter to the template specifying that the image should be wrapped in an element with the skin-invert-image
class, but that would require modifying all the pages displaying chemical structures with this infobox to use that parameter. nmaeltalk 18:49, 13 August 2024 (UTC)
- Is there a
<span>...</span>
or<div>...</div>
trick for forcing a white background? DMacks (talk) 04:25, 14 August 2024 (UTC)- There is. If I modify the
span
wrapping ranitidine's chemical structure to<span style="display:block; background-color:#FFFFFF;" ...>
in dev tools it creates this result, which looks legible. - However, we'd probably have to force the white background on all images in this template if we want to avoid adding a new template parameter specifying when to add the white background (and therefore having to change all the pages using this infobox with a chemical structure) - same problem as if we were to use the
skin-invert-image
tag. When I apply thespan
above forcing a white background on both images in the ranitidine infobox, this is the result. It's more tolerable than what happens when indiscriminately applying theskin-invert-image
tag, but it does add a lot of white to a page that's supposed to be in dark mode. - Also worth noting: applying the above change with the
span
tag would also make the infobox look like this in light mode; it's subtle, but since the infobox background isn't#FFFFFF
you can see white boxes surrounding the images which looks off. This could theoretically be avoided by using Mediawiki's night mode selectors/media queries so that the white background is only added in night mode. I believe this would require us to use the TemplateStyles feature to create a stylesheet for this infobox. nmaeltalk 15:07, 14 August 2024 (UTC)- Forcing "night" readers to see the infobox in "day" appearance, which makes the images legible, seems like a good quick solution. The images were clearly designed for viewing against a white or light background, so the only a down-side to making the box display them that way is that it isn't the "night mode" way. But that's better than "not really visible at all". Insead of
#FFFFFF
, we could use whatever slight-gray background is used in day-mode. DMacks (talk) 21:27, 14 August 2024 (UTC)
- Forcing "night" readers to see the infobox in "day" appearance, which makes the images legible, seems like a good quick solution. The images were clearly designed for viewing against a white or light background, so the only a down-side to making the box display them that way is that it isn't the "night mode" way. But that's better than "not really visible at all". Insead of
- There is. If I modify the
- Forcing a white background technically works, but it defeats the purpose of dark mode. The goal would be to apply the
skin-invert-image
class if the image is a line drawing. I, at least, can't think of any methods that would do this gracefully. It may be sufficient to sort by file type (invert SVG files), but that might be limiting and wouldn't catch somewhat common exceptions like when PNGs are used for line drawings. Maybe it is okay to apply the tag to the image parameter and not the image2 parameter, as it seems that the preferred style for these infoboxes is to put the line drawing in the image parameter and a ball-and-stick model in the image2 parameter. ― Synpath 21:25, 19 August 2024 (UTC)- Although usually the
image
parameter is used for chemical structures, there are several pages where a photo of something is used instead; e.g.: Polio vaccine, Laudanum, & BCG vaccine. These look very odd whenskin-invert-image
is applied to them. I suppose we could add a new parameter (likedark_mode_invert_image=yes
) that allows editors to applyskin-invert-image
on a case-by-case basis; this would then require painfully updating all the pages showing chemical structures with the template (maybe could be automated to some extent), but at least would keep things the way they are on pages that haven't been fixed yet. nmaeltalk 21:23, 20 August 2024 (UTC) - Edit: I'm a JWB novice, but it looks like if I set it up to do a regex replacement with
(\|\s*image\s*=.*\.svg)
as the regex and$1 | dark_mode_invert_image = yes
as the replacement string it will add the new parameter to the template only on pages where theimage
parameter references an SVG file. nmaeltalk 22:13, 20 August 2024 (UTC)- I like the idea and tried figuring out a regex expression that could do this without hitting off-target templates (like the image parameter of {{Annotated image 4}} at MDMA), but couldn't come up with anything. I'm not too familiar with regex techniques mind you. I was hoping to find a way to be able to match something like
\{\{[^\n]*drugbox(.*?)\}\}
(or any variant that finds the template) and then search within that match for something like:\|\s*image\s*=.*\.svg
. The issue is the nested curly braces within the infobox (citations for example) interfere with non-greedy matching (greedy matching hits outside the intended template). I wonder if there is a solution. - I'm also souring on applying the dark-mode compatibility onto the
image
parameter as switching examples like those you brought up toimage2
(the simplest edit) might end up being a ton of work anyways (I couldn't figure out a search to quantify this properly). It also introduces non-intuitive behaviour to a non-descriptive parameter making the template harder to use. ― Synpath 05:22, 22 August 2024 (UTC)
- I like the idea and tried figuring out a regex expression that could do this without hitting off-target templates (like the image parameter of {{Annotated image 4}} at MDMA), but couldn't come up with anything. I'm not too familiar with regex techniques mind you. I was hoping to find a way to be able to match something like
- Although usually the
- Note:phab:T370074 notes say this needs to be fixed locally, some notes are included on that ticket. — xaosflux Talk 15:34, 5 September 2024 (UTC)
Automatic short description
[edit]Hi there! Would it be possible to implement automatically generated short descriptions for this template, similarly to Template:Chembox? I would suggest something along the lines of {{main other|{{short description|Pharmaceutical compound|noreplace}}}}
. Cheers! YuniToumei (talk) 21:42, 23 November 2024 (UTC)
Edit request 25 November 2024
[edit]This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
It has been discussed above that molecular line drawings are poorly visible in dark mode. Based on these conversations I believe it would be uncontroversial and desirable to expand the template parameters and expose the file/image class
parameter. This allows the easy addition of the skin-invert-image
filter per MediaWiki recommendations. I've done this at {{Infobox drug class}} with Special:Diff/1247489275 and Snowmanonahoe made similar edits several months ago to {{chembox}} and related templates, see Special:Diff/1066834948/1224321587 for the top-level example.
See my edits to the sandbox for the change: Special:Diff/1247845656/1259538500 ― Synpath 19:02, 25 November 2024 (UTC)
- Done * Pppery * it has begun... 21:05, 26 November 2024 (UTC)
- I see that a default grey background was added. It is great that it automatically fixes thousands of pages.
- But the disadvantage is that we can't use `skin-invert` or `skin-invert-image`. If we do, we get a white image on a white/grey background.
imagestyle = background-color: #f8f9fa;
- A nicer way to fix this would be by the creation of more classes, like: gray-background or gray-only-when-on-blackmode
- This could be set by default, and when we use the image_class = skin-invert, I think it would then replace the default class.
- Ideally those classes would be created for the whole wikipedia, or in some standard, so we don't get each infobox using a different class name. (in this infobox it is "image_class", and on Chembox it is ImageClass"
- -- Arthurfragoso (talk) 22:51, 16 December 2024 (UTC)
...the disadvantage is that we can't use `skin-invert` or `skin-invert-image`. If we do, we get a white image on a white/grey background.
-- I do not get this result when usingskin-invert-image
on molecular diagrams with transparent backgrounds in {{drugbox}}. I get a white structure on a background that is effectively black. It's been brought up on my talk page before that this CSS filter is producing inconsistent results between others and (at least) myself. I'm curious if you or anyone else has some insight.- Additional classes specific for this kind of styling is recommended by MediaWiki if I'm reading that page right. Thanks ― Synpath 00:31, 17 December 2024 (UTC)
- I get this result both on Chrome and Firefox. [1] -- Arthurfragoso (talk) 00:44, 17 December 2024 (UTC)
- Firefox on macOS (what I usually use) over here gives this: [2], but I get similar results to yours on Safari. I'd hate to have to use Safari to check all my edits for dark mode. ― Synpath 01:11, 17 December 2024 (UTC)
- After a little experimenting I see that removing
| imageclass = notheme
from the Infobox template fixes this particular issue in Safari for me. The thing is, this line was specifically added as a dark mode quick-fix in the first place. Not sure what the plan there was as there's no comments around the edit, just that a MediaWiki staff member made the edit on their personal account. I can only assume that taking away that line will create other places where dark mode will screw up images without some other, more proper, implementation. ― Synpath 01:45, 17 December 2024 (UTC)- In your screenshot, as the background is not the same color as the drugbox, maybe for some reason you are getting an image with a white background instead of transparent? Wikipedia actually converts the SVG to PNG before providing it to us.
- If you look at the code, mine looks like:
<a href="/wiki/File:Amphetamine.svg" class="mw-file-description"><img alt="An image of the amphetamine compound" decoding="async" width="210" height="109" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/9/98/Amphetamine.svg/315px-Amphetamine.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/9/98/Amphetamine.svg/420px-Amphetamine.svg.png 2x" data-file-width="512" data-file-height="266" src="//upload.wikimedia.org/wikipedia/commons/thumb/9/98/Amphetamine.svg/420px-Amphetamine.svg.png"></a>
- Could you try to do a hard refresh on Firefox (so it bypasses caches and re-download the image):
- - Command+Shift+‘R’. [3] Arthurfragoso (talk) 01:55, 17 December 2024 (UTC)
- Hard refresh gives the same visual result as before, the only difference that I see is between the <a> and nested <img> tag where the src keyword points to the 210px width png:― Synpath 02:31, 17 December 2024 (UTC)
<a href="/wiki/File:Amphetamine.svg" class="mw-file-description"><img alt="An image of the amphetamine compound" src="//upload.wikimedia.org/wikipedia/commons/thumb/9/98/Amphetamine.svg/210px-Amphetamine.svg.png" decoding="async" width="210" height="109" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/9/98/Amphetamine.svg/315px-Amphetamine.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/9/98/Amphetamine.svg/420px-Amphetamine.svg.png 2x" data-file-width="512" data-file-height="266"></a>
- I just found out that if I have the browser extension Dark Reader activated while in WP dark mode, that the Amphetamine page works nicely. I wonder if you are using a similar browser extension. -- Arthurfragoso (talk) 18:57, 24 December 2024 (UTC)
- Hard refresh gives the same visual result as before, the only difference that I see is between the <a> and nested <img> tag where the src keyword points to the 210px width png:
- I get this result both on Chrome and Firefox. [1] -- Arthurfragoso (talk) 00:44, 17 December 2024 (UTC)
Edit request 2 December 2024
[edit]This edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
I've proposed an automatic short description for this template above. Based on no opposition and its relative similarity to Template:Chembox, this change seems uncontroversial to me. I've included the code in the sandbox, see Special:Diff/1260739628. YuniToumei (talk) 10:37, 2 December 2024 (UTC)
- Done I expect that there will be cases where the automatic short description is not accurate, which happens with many infobox templates; those short descriptions can easily be overridden with a local short description in the article. – Jonesey95 (talk) 02:37, 3 December 2024 (UTC)
More flexible dark mode implementation
[edit]Summary: Rather than using a static image background colour and notheme
class (diff), this dark mode fallback should be implemented as a default class through CSS. I have created Template:Infobox_drug/styles.css as a suggestion on how to go about this, and implemented the styles in the sandbox. See Template:Infobox_drug/testcases7images for visual comparisons (especially the Template:Infobox_drug/testcases7images#Dark mode test I've added). I hope this will work for almost all people, but this kind of change needs discussion.
More context/comments: Implementing dark mode on this template has been a bit of a hassle, and I think I've slowly come to understand what is going on here and how to go about it more properly. Over the past few months I've been adding the skin-invert-image
class to molecular line drawings in order for them to be drawn without eye-searing results in dark mode (it essentially just inverts image colours). This does not work with this particular template as the images are set to have a static light grey background colour in the base Infobox template (added in this edit) leaving the line drawings as essentially white-on-white. Per the MediaWiki recommendations this type of dark mode fix is discouraged and should be made more flexible through CSS. Nmael brought this up several months ago and suggested the fix I am presenting here (though I didn't fully understand what was suggested at the time). Essentially, I've just moved the static background colouring to an HTML class called dark_mode_safe
at Template:Infobox_drug/styles.css and used that as the default class. This means that if someone (me) comes along and adds a skin-invert-image
class the dark_mode_safe
class (i.e light background) gets overridden and you end up with a nice looking line drawing. See Template:Infobox_drug/testcases7images#Dark mode test for the results and, of course, this fix is meant primarily for black-and-white images.
The great thing about this is that you can start adding more advanced logic to what the default class should be and that can be added either directly to the template or through the CSS. For example SVG images could default to using an invert filter that we define at Template:Infobox_drug/styles.css. Perhaps we could crib some of the CSS magic from MediaWiki:Gadget-dark-mode.css in how they handle SVG images as well.
Be warned I've never dabbled in CSS up until now, and I definitely do not completely understand the nuances of dark mode. ― Synpath 16:05, 31 December 2024 (UTC)
- Pinging previous participants in Infobox drug dark mode related discussions: @Nmael, DMacks, Arthurfragoso, and Susko3: thanks. ― Synpath 16:11, 31 December 2024 (UTC)
- I like it! I even added some extra examples showing the transparent-bg option there Template:Infobox_drug/testcases7images. :) Arthurfragoso (talk) 22:31, 31 December 2024 (UTC)
- I know wikipedia is trying to use css variables for color coding so it is easier to make the whole website with consistent styling. So the one I found to be the most similar and appropriate there is var(--background-color-inverted), that has the value #f8f9fa in dark mode. Arthurfragoso (talk) 02:30, 1 January 2025 (UTC)
- I made the edit there already. Arthurfragoso (talk) 02:34, 1 January 2025 (UTC)
- Thanks, I appreciate the extra test cases and applying the css variable. Is there an index for those? Where did you find this one? ― Synpath 04:43, 1 January 2025 (UTC)
- Right click at the background, inspect element: screenshot
- If the wikipedia light/dark theme is set to automatic, you can use the option shown in the image in Firefox to switch the theme.
- The same variables is set to different color codes depending if in light/dark mode. The code you wrote sets the background only in dark mode, so it doesn't show a dark background in light mode.
- Actually I thought a bit of a default grayer color would be better instead of that white, but maybe it would not fit well to all images. So ideally there could be a range of options for styling, but that would be a discussion for the admins, and I'm quite happy already with the results we already got with your excellent work! :)
- ― Arthurfragoso (talk) 07:23, 1 January 2025 (UTC)
- Ah, clever - don't think I would have found that myself. As for the specific colours that can be something we figure out here, but for now I'm more concerned that this is a functional solution that doesn't affect light mode and is at minimum status quo for dark mode. Though I do think a bit of a darker grey would be better. ― Synpath 16:30, 1 January 2025 (UTC)
- I don't know much about the implementation details (though I could try to deciper the template spaghetti if needed), and I know zilcho about dark-mode except that it's a perpetual pain for everyone that deals with it. I wish you all the best of luck, with moral support for anyone that makes things better in a centralized way without making things worse. DMacks (talk) 07:40, 1 January 2025 (UTC)