モジュール:Twitter

提供:エケペディア
2021年3月21日 (日) 13:06時点におけるMotodai (トーク | 投稿記録)による版 (http: --> https:)
ナビゲーションに移動 検索に移動

このモジュールについての説明文ページを モジュール:Twitter/doc に作成できます

local p = {};

local function setProperty(t_name)
	
	-- メイン空間のみ
	if not mw.title.getCurrentTitle().namespace == 0 then
		return true;
	end
	
	if not mw.smw then
        return true;
    end
    
    local dataStore = {}
    dataStore['twitterアカウント'] = t_name

    local result = mw.smw.set( dataStore )

    if result == true then
        -- everything ok
    else
        -- error message to be found in result.error
    end
end	

function p.main( frame )
	local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:Twitter', removeBlanks = false, parentFirst = true });

	-- Twitter ID
	local t_name = args[1] or args.id or '';
	
	-- Twitter URL
	local formatterURL = "https://twitter.com/$1";
	local url = mw.ustring.gsub(formatterURL, "\$1", t_name);
	
	-- Twitter 表示名
	local name = args[2] or args.name or '';
	
	-- SemanticMediaWiki
	if not args.nosmw then
		setProperty(t_name);
	end


	-- Twitter 表示名デフォルト
	if name == '' then
		name = "Twitterアカウント";
	end

	local t_name2 = '(@' .. t_name  ..')';
	if mw.ustring.match(name, '%(' .. t_name .. '%)$') then
		t_name2 = '';
	end

	return '[' ..url ..' ' ..name ..'] ' ..t_name2 ..' - [[Twitter]]';
end

return p;