Template talk:Gallery
| Template:Gallery is permanently protected from editing as 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 Gallery template. |
|
| Archives: 1, 2Auto-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: | ||||||||
| ||||||||
Changes of the arguments parsing algorithm
[edit]Hey,
I'm pinging the major contributors to this Module.
I noticed the algorithm for this module was quite rigid, and it making many assumptions of image and caption order. It was counting the number of arguments and making assumptions of how many images the gallery had.
I changed it a bit, so it counts the images by a custom isImage(filename) and get the next non-empty argument to be the caption.
The tricky thing is to identify the images. If File:, Image: and Media: was previously enforced, it would be a bit easier. So what I did was verifying those prefix and if in case it was not present I verify if it ends in an extension of 3 or 4 characters. As there can also be audio and video in the gallery, we would have to keep up with Commons to know and update the existing file extensions. Checking for ".****" seems okay, but there is the risk a caption would be identified as an image if it had a similar ending, but those endings are unlikely in most languages. An option would be to check the cases without the File:, Image: and Media: prefixes and automatically put them in some category, something like: "Category:Pages using gallery without a media prefix"
I appreciate thoughts on this changes.
Template:Gallery/testcases#Hunting_for_bugs
-- Arthurfragoso (talk) 04:22, 1 February 2025 (UTC)
- A recent change to this module appears to have broken the use of {{FIAV}}. Expand the gallery at Flag of Spain#Spanish transition to see the problem: a File call inside the
|alt=text. This problem is affecting about 300 articles, listed here. – Jonesey95 (talk) 14:43, 7 February 2025 (UTC)- Thanks for the report! I already understood the problem and I'm working on a fix! -- Arthurfragoso (talk) 16:17, 7 February 2025 (UTC)
- @Jonesey95:
fixed :) Arthurfragoso (talk) 20:33, 7 February 2025 (UTC)
- Thanks for the quick fix. – Jonesey95 (talk) 23:22, 7 February 2025 (UTC)
- Sorry to have to revert all the way back. Please continue to experiment in the sandbox based on feedback below and the added testcases. – Jonesey95 (talk) 03:19, 10 February 2025 (UTC)
- Thanks for the quick fix. – Jonesey95 (talk) 23:22, 7 February 2025 (UTC)
Caption not accepting external links
[edit]@Jonesey95 Hmmm, sorry about that erroneous edit to the doc saying captions don't accept external links when it appears they do in my sandbox, but possibley not on talk pages... like on this talk page in the past the source code for the gallery at the section header titled "Proposal: clarify "user-generated" in MOS:CALLIGRAPHY" is:
{{Gallery
| title = Examples of a "digital recreation" and of "stylistic elements which are not present in the original":
| align = center
| footer =
| style =
| state =
| height =
| width =
| perrow =
| mode =
| whitebg = no
| noborder = yes
| captionstyle =
| File:Istanbul - Santa Sofia - Medalló (cropped).JPG
| real-world calligraphy of [[Ali]]
| alt1=
| File:Rashidun Caliph Ali ibn Abi Talib - علي بن أبي طالب.svg
| digital recreation of real-world calligraphy of Ali
| alt2=
| File:UsulALFiqh.svg
| calligraphy containing stylistic elements (decorative circle, color, shadow) not present in original calligraphy as used outside WP (external links [https://m.media-amazon.com/images/I/71iObLPx1mL._SL1500_.jpg][https://www.mehbooba.com/the-principles-of-hanafi-usul-al-fiqh][https://madinahcollege.uk/product/usul-al-fiqh-an-introduction-to-islamic-legal-theory])
| alt3=
}}
See the highlighted caption doesn't appear on the page. Is it a talk page only thing? Or is it specifically the code of this caption that is causing it not to output? waddie96 ★ (talk) 20:23, 9 February 2025 (UTC)
- A bit of a mystery. See this test case, where the first external link appears to suppress the entire caption. The same link with link text works fine. – Jonesey95 (talk) 21:13, 9 February 2025 (UTC)
- Arthurfragoso, I think this may be related to your alt text changes. The alt text for the above contains unprocessed URLs that appear to be interfering with rendering of the caption; when I remove the alt text from the rendered gallery, the links above display just fine. – Jonesey95 (talk) 21:18, 9 February 2025 (UTC)
- @Arthurfragoso yes appears so. waddie96 ★ (talk) 23:30, 9 February 2025 (UTC)
- Alt text must not contain external links. This is because the alt text is carried in the
alt=attribute of the<img />tag; and attribute values cannot contain markup of any kind. See HTML5 spec, section 4.7.1.1 (it's quite lengthy). --Redrose64 🌹 (talk) 23:52, 9 February 2025 (UTC)- I have reverted
the last twoall of the February changes, which appears to resolve the problem until Arthurfragoso can come up with a better fix in the sandbox. – Jonesey95 (talk) 02:33, 10 February 2025 (UTC) - But the above example contains no external links in the alt text... or if I'm missing the bigger picture here then excuse me because I know nothing of Module coding. waddie96 ★ (talk) 09:35, 10 February 2025 (UTC)
- @Jonesey95, @Waddie96:
- The problem was because the url was concatenating with the pipe, and the parser was interpreting the pipe as part of the url, example:
alt1=caption with link at the end http://website.com/about|caption with link at the...- So now I added a code to strip the links added to the alt text, and I also added a space before the caption to prevent other unexpected behavior. -- Arthurfragoso (talk) 10:21, 10 February 2025 (UTC)
- @Waddie96: Thanks for reporting! I have just put the updated code live. -- Arthurfragoso (talk) 10:34, 10 February 2025 (UTC)
- @Arthurfragoso Awesome, thanks for the quick fix and your help! waddie96 ★ (talk) 21:06, 10 February 2025 (UTC)
- @Waddie96: Thanks for reporting! I have just put the updated code live. -- Arthurfragoso (talk) 10:34, 10 February 2025 (UTC)
- I have reverted
- Alt text must not contain external links. This is because the alt text is carried in the
- @Arthurfragoso yes appears so. waddie96 ★ (talk) 23:30, 9 February 2025 (UTC)
- Arthurfragoso, I think this may be related to your alt text changes. The alt text for the above contains unprocessed URLs that appear to be interfering with rendering of the caption; when I remove the alt text from the rendered gallery, the links above display just fine. – Jonesey95 (talk) 21:18, 9 February 2025 (UTC)
Vertical alignment
[edit]Is is possible to vertically align images? PhotographyEdits (talk) 11:00, 9 March 2025 (UTC)
Align footer left
[edit]I feel like it's weird and arbitrary that the footer is aligned right by default. It just makes the footer unsuitable for long text that wraps to the next line. Should there be an option that lets you change the alignment setting of the footer (right, center, left)? Nrco0e (talk • contribs) 06:39, 11 September 2025 (UTC)