Module:Version: Difference between revisions

From Ylvapedia
(Created page with "-- Current stable version. Increment this when a new version is released. local STABLE = 32 local RECENT = 31 local p = {} -- Tries to parse a version number -- returns either a version number, "trunk", or nil (meaning unknown) local function parse_version(version) if type(version) == "number" or version == "trunk" then return version end local num = tonumber(version) if num then -- convert 0.17 to 17 if num < 1 then num = 100*num end...")
 
No edit summary
 
(22 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- Current stable version. Increment this when a new version is released.
-- Current stable version. Increment this when a new version is released.
local STABLE = 32
-- The version of Elin is made of <major version>.<minor version>
local RECENT = 31
local CURRENT = 23.67
 
local _, _, CURRENT_major, CURRENT_minor = string.find( CURRENT, "(%d+)%.(%d+)" )
local p = {}
local p = {}


-- This function assume the input is in the form of <major version>.<minor version>, but it doesn't give an error if minor version doesn't exist.
-- Return:
-- 2, the minor version is 21 or more away, or the major version is at least 1 away.
-- 1, the minor version is 1~20 away from the current version.
-- 0, the versions are the same
-- -1, the input version is greater
local function if_greater_function(test_version)
_, _, major, minor = string.find( test_version, "(%d+)%.(%d+)" )
if CURRENT_major > major then
return 2
elseif CURRENT_major < major then
return -1
elseif CURRENT_minor < minor then
return -1
elseif tonumber(CURRENT_minor) > tonumber(minor) + 20 then
return 2
elseif CURRENT_minor > minor then
return 1
else
return 0
end
end
-- Tries to parse a version number
-- Tries to parse a version number
-- returns either a version number, "trunk", or nil (meaning unknown)
-- returns either a version number, "trunk", or nil (meaning unknown)
Line 13: Line 36:
   local num = tonumber(version)
   local num = tonumber(version)
   if num then
   if num then
    -- convert 0.17 to 17
    if num < 1 then
      num = 100*num
    end
    if num > STABLE then
      return "trunk"
    else
       return num
       return num
    end
   end
   end
   return nil
   return nil
Line 28: Line 43:
function p.version_tag(frame)
function p.version_tag(frame)
   local version = parse_version(frame.args[1])
   local version = parse_version(frame.args[1])
   local current = version == STABLE
  local lang = frame.args[2]
   local previ = version == RECENT
   local current = if_greater_function(version) == 0
   local trunk = version == "trunk"
   local previ = if_greater_function(version) == 1
  local deprec = if_greater_function(version) == 2
   local trunk = if_greater_function(version) == -1
   local unknown = not version
   local unknown = not version
 
  local version_b = ""
  _, _, THIS_major, THIS_minor = string.find( version, "(%d+)%.(%d+)" )
  THIS_major = tonumber(THIS_major)
  THIS_minor = tonumber(THIS_minor)
  if THIS_major >= 23 then
  version_b = "EA"
  elseif THIS_major == 22 and THIS_minor >= 19 then
  version_b = "Beta"
  elseif THIS_major == 22 and THIS_minor < 19 then
  version_b = "Pre-Beta"
  elseif THIS_major < 22 then
  version_b = "Alpha"
  end
   local bgcolor = "fc6"
   local bgcolor = "fc6"
   if current then
   if current then
Line 39: Line 68:
     bgcolor = "BCEBF5"
     bgcolor = "BCEBF5"
   elseif previ then
   elseif previ then
     bgcolor = "e0fae0"
     bgcolor = "ffff66"
  elseif deprec then
  bgcolor = "ff9999"
   end
   end


Line 48: Line 79:
     bordercolor = "04A0BF"
     bordercolor = "04A0BF"
   elseif previ then
   elseif previ then
     bordercolor = "33FF66"
     bordercolor = "ff9933"
  elseif deprec then
  bordercolor = "ff3366"
   end
   end


Line 54: Line 87:
   result = result:format(bordercolor, bgcolor, bordercolor)
   result = result:format(bordercolor, bgcolor, bordercolor)
   if trunk then
   if trunk then
    result = result .. "'''''[[Trunk]]-only''': This article pertains to a feature of Crawl which is being tested. It will likely change before the next release, and may even be removed entirely.''"
  if lang == "EN" then
        result = result .. "'''''This article pertains to a feature of Elin which is unrelease in stable version.''"
    else
    result = result .. "'''''この記事は、Elinの未リリースバージョンの機能に関するものです。''"
    end
   else
   else
     result = result .. "'''''Version "
  if lang == "EN" then
        result = result .. "'''''Version "
     else
    result = result .. "'''''バージョン "
    end
     if unknown then
     if unknown then
       result = result .. "Unknown"
       result = result .. "Unknown"
     else
     else
       result = result .. "[[0." .. version .. "]]"
       result = result .. "".. version_b .."" .. version .. ""
     end
     end
     result = result .. "''': "
     result = result .. "''': "
     if current then
     if current then
      result = result .. "This article is up to date for the [[0." .. STABLE .. "|latest stable release]] of ''Dungeon Crawl Stone Soup''."
        if lang == "EN" then
    else
        result = result .. "This article is up to date for the [[Elin:Changelog|latest stable release]] of ''Elin''."
      result = result .. "This article '''may not be''' up to date for the [[0." .. STABLE .. "|latest stable release]] of Crawl.''"
        else
        result = result .. "この記事は''Elin''の[[Elin:更新履歴|最新の安定版リリース]]に対応しています。"
        end
    elseif previ then
    if lang == "EN" then
            result = result .. "This article is behind the [[Elin:Changelog|latest stable release]] of ''Elin'', but maybe close enough to be reliable."
        else
        result = result .. "この記事は、''Elin'' [[Elin:更新履歴|最新の安定版リリース]]に遅れをとっていますが、信頼できる範囲にあるかもしれません。"
    end
    elseif deprec then
    if lang == "EN" then
            result = result .. "This article is at least 20 minor version or a major version behind the [[Elin:Changelog|latest stable release]] of ''Elin''. Please help update the page."
        else
        result = result .. "この記事は、''Elin'' の[[Elin:更新履歴|最新の安定版リリース]]に、少なくとも20のマイナーバージョンが遅れています。ページの更新をお願いします。"
    end 
     end
     end
   end
   end
   result = result .. "</div>"
   result = result .. "</div>"
 
  -- The next part is used to add a category, we don't do that just yet.
   result = result .. "\n[[Category:"
   --result = result .. "\n[[Category:"
   if trunk then
   --if trunk then
    result = result .. "Trunk"
  --  result = result .. "Trunk"
   elseif unknown then
   --elseif unknown then
    result = result .. "Unknown"
  --  result = result .. "Unknown"
   else
   --else
    result = result .. "0." .. version
  --  result = result .. "0." .. version
   end
   --end
   result = result .. " articles]]"
   --result = result .. " articles]]"


   return result
   return result

Latest revision as of 16:40, 26 December 2024

Documentation for this module may be created at Module:Version/doc

-- Current stable version. Increment this when a new version is released.
-- The version of Elin is made of <major version>.<minor version>
local CURRENT = 23.67
local _, _, CURRENT_major, CURRENT_minor = string.find( CURRENT, "(%d+)%.(%d+)" )
local p = {}

-- This function assume the input is in the form of <major version>.<minor version>, but it doesn't give an error if minor version doesn't exist.
-- Return:
-- 2, the minor version is 21 or more away, or the major version is at least 1 away.
-- 1, the minor version is 1~20 away from the current version.
-- 0, the versions are the same
-- -1, the input version is greater
local function if_greater_function(test_version)
	_, _, major, minor = string.find( test_version, "(%d+)%.(%d+)" )
	
	if CURRENT_major > major then
		return 2
	elseif CURRENT_major < major then
		return -1
	elseif CURRENT_minor < minor then
		return -1
	elseif tonumber(CURRENT_minor) > tonumber(minor) + 20 then
		return 2
	elseif CURRENT_minor > minor then
		return 1
	else
		return 0
	end
end	
-- Tries to parse a version number
-- returns either a version number, "trunk", or nil (meaning unknown)
local function parse_version(version)
  if type(version) == "number" or version == "trunk" then
    return version
  end
  local num = tonumber(version)
  if num then
      return num
  end
  return nil
end

function p.version_tag(frame)
  local version = parse_version(frame.args[1])
  local lang = frame.args[2]
  local current = if_greater_function(version) == 0
  local previ = if_greater_function(version) == 1
  local deprec = if_greater_function(version) == 2
  local trunk = if_greater_function(version) == -1
  local unknown = not version
  local version_b = ""
  _, _, THIS_major, THIS_minor = string.find( version, "(%d+)%.(%d+)" )
  THIS_major = tonumber(THIS_major)
  THIS_minor = tonumber(THIS_minor)
  if THIS_major >= 23 then
  	version_b = "EA"
  elseif THIS_major == 22 and THIS_minor >= 19 then
  	version_b = "Beta"
  elseif THIS_major == 22 and THIS_minor < 19 then 
  	version_b = "Pre-Beta"
  elseif THIS_major < 22 then
  	version_b = "Alpha"
  end
  local bgcolor = "fc6"
  if current then
    bgcolor = "99FF99"
  elseif trunk then
    bgcolor = "BCEBF5"
  elseif previ then
    bgcolor = "ffff66"
  elseif deprec then
  	bgcolor = "ff9999"
  end

  local bordercolor = "f90"
  if current then
    bordercolor = "33FF66"
  elseif trunk then
    bordercolor = "04A0BF"
  elseif previ then
    bordercolor = "ff9933"
  elseif deprec then
  	bordercolor = "ff3366"
  end

  local result = [[<div style="border: 1px solid #%s; background-color: #%s; border-left: 15px solid #%s; margin-bottom: 20px; width: 100%%; padding: 4px 10px; line-height: 1.1em; width: auto;">]]
  result = result:format(bordercolor, bgcolor, bordercolor)
  if trunk then
  	if lang == "EN" then
        result = result .. "'''''This article pertains to a feature of Elin which is unrelease in stable version.''"
    else
    	result = result .. "'''''この記事は、Elinの未リリースバージョンの機能に関するものです。''"
    end
  else
  	if lang == "EN" then
        result = result .. "'''''Version "
    else
    	result = result .. "'''''バージョン "
    end
    if unknown then
      result = result .. "Unknown"
    else
      result = result .. "".. version_b .."" .. version .. ""
    end
    result = result .. "''': "
    if current then
        if lang == "EN" then
        	result = result .. "This article is up to date for the [[Elin:Changelog|latest stable release]] of ''Elin''."
        else
        	result = result .. "この記事は''Elin''の[[Elin:更新履歴|最新の安定版リリース]]に対応しています。"
        end
    elseif previ then
    	if lang == "EN" then
            result = result .. "This article is behind the [[Elin:Changelog|latest stable release]] of ''Elin'', but maybe close enough to be reliable."
        else
        	result = result .. "この記事は、''Elin'' の[[Elin:更新履歴|最新の安定版リリース]]に遅れをとっていますが、信頼できる範囲にあるかもしれません。"
    	end
    elseif deprec then
     	if lang == "EN" then
            result = result .. "This article is at least 20 minor version or a major version behind the [[Elin:Changelog|latest stable release]] of ''Elin''. Please help update the page."
        else
        	result = result .. "この記事は、''Elin'' の[[Elin:更新履歴|最新の安定版リリース]]に、少なくとも20のマイナーバージョンが遅れています。ページの更新をお願いします。"
    	end   	
    end
  end
  result = result .. "</div>"
  -- The next part is used to add a category, we don't do that just yet.
  --result = result .. "\n[[Category:"
  --if trunk then
  --  result = result .. "Trunk"
  --elseif unknown then
  --  result = result .. "Unknown"
  --else
  --  result = result .. "0." .. version
  --end
  --result = result .. " articles]]"

  return result
end

function p.version_list(frame)
  local prev_versions = {}
  for version = STABLE - 1, 1, -1 do
    table.insert(prev_versions, "[[0." .. version .. "]]")
  end

  local result = [=[{| cellspacing="0" cellpadding="0" style="margin:0em 0em 1em 0em; width:100%; background-color:white"
| style="width:50%; vertical-align:top; border:1px solid #CC6600; background-color:#FF9966;" |
<div style="border-bottom:0px solid #CC6600; background-color:#FF6633; padding:0.2em 0.5em 0.2em 0.5em; font-size:110%; font-weight:bold;">[[:Category:Crawl Versions|Versions]]</div>
<div style="border-bottom:0px solid #CC6600; padding:0.4em 1em 1em 1em;">
The Crawl Wiki is kept up to date with the latest stable release: [[0.]=]
  result = result .. STABLE .. "]]\n"
  result = result .. "* Previous releases: " .. table.concat(prev_versions, " | ") .. "\n"
  result = result .. "* In [[trunk]] development: [[0." .. STABLE + 1 .. "]]</div>\n|}"
  return result
end

return p