-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(infobox): cleanup header image display #4197
Open
iMarbot
wants to merge
5
commits into
main
Choose a base branch
from
infobox-image-cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+24
−29
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
15146fd
feat(infobox): cleanup header image display
iMarbot a06f4af
use stringutils instead
iMarbot 282d449
Rework to use Image module
iMarbot aa7dadc
Limit image thumbnail vertical height too
iMarbot 729c22f
Update components/infobox/commons/infobox_widget_header.lua
iMarbot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,10 @@ | |
-- | ||
|
||
local Class = require('Module:Class') | ||
local Image = require('Module:Image') | ||
local Logic = require('Module:Logic') | ||
local Lua = require('Module:Lua') | ||
local String = require('Module:StringUtils') | ||
|
||
local Widget = Lua.import('Module:Infobox/Widget') | ||
|
||
|
@@ -92,49 +95,40 @@ end | |
---@param size number|string|nil | ||
---@return Html? | ||
function Header:_image(fileName, fileNameDark, default, defaultDark, size) | ||
if (fileName == nil or fileName == '') and (default == nil or default == '') then | ||
local imageName = fileName or default | ||
local imageDarkname = fileNameDark or fileName or defaultDark or default | ||
|
||
if String.isEmpty(imageName) and String.isEmpty(imageDarkname) then | ||
return nil | ||
end | ||
|
||
local imageName = fileName or default | ||
---@cast imageName -nil | ||
local infoboxImage = Header:_makeSizedImage(imageName, fileName, size, 'lightmode') | ||
if imageName == imageDarkname then | ||
imageDarkname = nil | ||
end | ||
|
||
imageName = fileNameDark or fileName or defaultDark or default | ||
---@cast imageName -nil | ||
local infoboxImageDark = Header:_makeSizedImage(imageName, fileNameDark or fileName, size, 'darkmode') | ||
local infoboxImage = Header:_makeSizedImage(imageName, size, 'lightmode') | ||
local infoboxImageDark = Header:_makeSizedImage(imageDarkname, size, 'darkmode') | ||
|
||
return mw.html.create('div'):node(infoboxImage):node(infoboxImageDark) | ||
end | ||
|
||
---@param imageName string | ||
---@param fileName string? | ||
---@param imageName string? | ||
---@param size number|string|nil | ||
---@param mode string | ||
---@return Html | ||
function Header:_makeSizedImage(imageName, fileName, size, mode) | ||
local infoboxImage = mw.html.create('div'):addClass('infobox-image ' .. mode) | ||
---@param mode string? | ||
---@return Html? | ||
function Header:_makeSizedImage(imageName, size, mode) | ||
if String.isEmpty(imageName) then | ||
return | ||
end | ||
|
||
-- Number (interpret as pixels) | ||
size = size or '' | ||
if tonumber(size) then | ||
size = tonumber(size) .. 'px' | ||
local infoboxImage = mw.html.create('div'):addClass('infobox-image'):addClass(mode) | ||
if Logic.isNumeric(size) then | ||
infoboxImage:addClass('infobox-fixed-size-image') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for this |
||
-- Percentage (interpret as scaling) | ||
elseif size:find('%%') then | ||
local scale = size:gsub('%%', '') | ||
local scaleNumber = tonumber(scale) | ||
if scaleNumber then | ||
size = 'frameless|upright=' .. (scaleNumber / 100) | ||
infoboxImage:addClass('infobox-fixed-size-image') | ||
end | ||
-- Default | ||
else | ||
size = '600px' | ||
size = '600x1000px' | ||
end | ||
|
||
local fullFileName = '[[File:' .. imageName .. '|center|' .. size .. ']]' | ||
infoboxImage:wikitext(fullFileName) | ||
infoboxImage:wikitext(Image.display(imageName, nil, {size = size})) | ||
|
||
return infoboxImage | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the css be tweaked so
infobox-image
is only needed to be set on the wrapper?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way the infobox itself is all written, it's got classless div rows, and then each of those rows is filled with different things (headers/images/rows/etc.). It wouldn't make much sense to only change one of these and have the rest be as before, imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would still require tweaking some CSS, but wouldn't be too hard.
Idk if there's any conventions on "adjective" class names needing to be applied to an element with an existing "noun" class name (if that makes sense?) Obviously, on a technical level it makes absolutely no difference, just wondering how people feel about it in general (i.e. "lightmode" what? vs "lightmode" "infobox image").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we even need the inner div (which sets the lightmode)?
if using module:Image it would get set in the image itself
would be in line with how other infobox rows are displayed too
(obviously in this case it would merke the 2 images into 1 since they are the same, just for showcasing with 2 different light/dark mode)
https://liquipedia.net/commons/index.php?title=Module%3AInfobox%2FWidget%2FHeader%2Fdev&type=revision&diff=703437&oldid=703225
tested on sc2 with
no extra css changes needed (only the one already suggested in the PR)
can probably even kick some css