モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

このモジュールは、バージョン確認のために他モジュールを点検します。この関数は、一般的にはモジュールのインポートに使用されますが、ウィキボヤージュのモジュールにも提供されます。

ウィキデータでのバージョン: 2022-04-25 問題なし

関数

[編集]
function fs._failsafe( version, moduleInterface ) 

パラメータ:

  • versionbool or string or table
    nil or falseの時、バージョン確認はされず、モジュールに書かれているバージョンを参照します。
    stringが渡されている時、もしも'wikidata'が渡されているならばウィキデータに保存されたバージョンを参照します。バージョン番号そのものが含まれている場合にはそのバージョンを使用します。取得したあるいは渡されたバージョン番号とモジュール内に書かれたバージョン番号を比較し、異なる場合は現在のバージョン番号が返り、そうでないならばfalseが返ります。
    tableを渡された場合、frameテーブルとして処理します。
  • moduleInterfacetable
    モジュールの情報が入ったテーブル

戻り値:

  • 現在のバージョンか、falseが戻り値になります。
function fs.getModuleVersion( frame ) 

ウィキデータやモジュールに保存されたバージョンを提供し、可能ならばそれらが一致するか評価します。

moduleInterfaceの構造

[編集]
local Modulname = { 	suite    = 'Modulname', 	sub      = 'Untermodul',   	serial   = '2019-07-09', 	item     = 12345678,   -- ウィキデータID  	-- 以下も使われますが、何を想定したものかは不明です。  	frame    = false, 	ns       = -9999,      -- number; 現在の名前空間番号 	nsDocs   = -99999,     -- number; 中央ドキュメントの名前空間番号 	title    = false,      -- 現在のページのタイトルオブジェクト 	transl   = false, 	subpages = ?, 	suffix   = ?, 	swift    = ?, 	start    = ?,          -- string; 定義されたpageDocRoot引数 	script   = ?,          -- string; モジュール名(メイン) 	say      = ?,          -- string; メッセージキー 	specific = ?,          -- string, optional; 追加の情報 	collect  = ?, 	lazy     = ?, 	lead     = ?, } 

おそらくドイツ語版ウィキペディアのModul:Vorlage:LuaModuleDocにあるでしょう。

[編集]
  • function fs._failsafe( nil, moduleInterface ) 
  • {{#invoke: {{BASEPAGENAME}} | failsafe }} 
    モジュールからバージョンを提供します。
  • function fs._failsafe( 'wikidata', moduleInterface ) 
  • {{#invoke: {{BASEPAGENAME}} | failsafe | wikidata }} 
    ウィキデータからバージョンを提供します。
  • function fs._failsafe( '2019-07-09', moduleInterface ) 
  • {{#invoke: {{BASEPAGENAME}} | failsafe | 2019-07-09 }} 
    渡されたバージョンとモジュールのバージョンを比較します。
  • {{#ifeq: {{#invoke:{{BASEPAGENAME}} | failsafe }} | {{#invoke:{{BASEPAGENAME}} | failsafe | wikidata }} | {{ombox | type = notice | image = [[Image:Blue check.svg|30px]] | text = モジュールは最新です }} }} 
    ウィキデータに保存されているバージョンとモジュールに書かれているバージョンが一致するか評価します。

使用状況

[編集]

このモジュールを使用しているテンプレートは以下の通りです:

-- module interface local Failsafe = { 	suite  = 'Failsafe', 	serial = '2022-04-25', 	item   = 65306115 }  local strings = { 	docPage           = 'doc', 	ok                = '[[File:Artículo bueno.svg|16px|text-bottom|問題なし]]', 	notOk             = '[[File:Symbol oppose vote.svg|15px|text-bottom|問題あり]][[Category:ウィキデータと実際のバージョンが異なるモジュール]]', 	versionText       = 'ウィキデータでのバージョン:', 	noVersion         = '有効なバージョンが見つかりませんでした' }  -- modul variable and administration local fs = { 	moduleInterface = Failsafe }  -- possible vaules of version --  nil, false: no version required --  string:     string of version required --  table:      frame table (template, #invoke) -- aModuleInterface --  table  function fs._failsafe( version, aModuleInterface ) 	if type( aModuleInterface ) ~= 'table' then 		return false 	end  	local i, s, v  	-- check if version is a frame table 	if type( version ) == 'table' and type( version.args ) == 'table' then 		s = version.args[ 1 ] 		if not s and type( version.getParent ) == 'function' then 			i = version:getParent() 			if i then 				s = i.args[ 1 ] 			end 		end 		version = s 	end 	-- version should be a string 	if type( version ) == 'string' then 		-- check if empty string 		version = mw.text.trim( version ) 		if version == '' then 			version = nil 		end 	else 		version = nil 	end  	-- getting version from Wikidata 	if version == 'wikidata' then 		version = nil 		i = aModuleInterface.item 		if type( i ) == 'number' and i > 0 then 			s = mw.wikibase.getBestStatements( 'Q' .. i, 'P348' ) 			for i = 1, #s, 1 do 				if s[ i ].mainsnak.snaktype == 'value' then 					v = s[ i ].mainsnak.datavalue.value 					if v ~= '' then 						return v:gsub( '%.', '-' ) 					end 				end 			end 		end 	end  	if not aModuleInterface.serial then 		return false 	elseif not version or version <= aModuleInterface.serial then 		return aModuleInterface.serial 	else 		return false 	end end  local function getModule( title ) 	return require( 'Module:' .. title ) end  function fs.getModuleVersion( frame ) 	local result = strings.versionText .. ' ' .. strings.noVersion 	local fromModule, fromWikidata, m, success  	local title = mw.ustring.gsub( mw.title.getCurrentTitle().text, '/' .. strings.docPage, '' ) 	if title == 'Failsafe' then -- the module itself 		success = true 		m = fs 	else 		success, m = pcall( getModule, title ) 	end 	if success then 		if m.moduleInterface then 			fromModule = m.moduleInterface.serial 			fromWikidata = fs._failsafe( 'wikidata', m.moduleInterface ) 		end 		if fromWikidata or fromModule then 			result = strings.versionText .. ' <code>' 				.. ( fromWikidata or fromModule ) .. '</code>' 			if fromWikidata and fromModule then 				result = result .. ' ' .. 					( fromWikidata == fromModule and strings.ok or strings.notOk ) 			end 		end 	end  	return result end  return fs