imported>Mr. Ibrahem No edit summary |
(No difference)
|
Latest revision as of 15:02, 16 December 2021
Documentation for this module may be created at Module:Sandbox/Mr. Ibrahem/doc
local p = {}
function p.EntityIdForTitle(frame)
-- {{#invoke:Sandbox/Mr. Ibrahem|EntityIdForTitle|Yemen}}
if frame.args then Frame_args = frame.args end
local title = frame.args[1]
local str = mw.wikibase.getEntityIdForTitle( title )
--mw.log(str)
return str
end
function p.count_temp(frame)
-- {{#invoke:Sandbox/Mr. Ibrahem|count_temp|Yemen}}
local title = frame.args[1]
local _;
local page_title_object = mw.title.new(title);
local text = page_title_object:getContent();
local count;
_, count = mw.ustring.gsub (text or '', '({{%s*[Hh]arv[nbcolptx]*%s*|)', '%1');
local count2;
__, count2 = mw.ustring.gsub (text or '', '({{%s*[Ss]fn[mp]?%s*|)', '%1');
local allcount = count + count2
return allcount;
end
function p.tab(frame)
local title = frame.args[1]
local _,ref;
local page_title_object = mw.title.new(title);
local text = page_title_object:getContent();
text = mw.ustring.gsub(text , "%{%|", "<table>")
text = mw.ustring.gsub(text , "%|%}", "</table>")
--text = string.gsub(text , "%{%|", "<table>")
--text = string.gsub(text , "%|%}", "</table>")
mw.log(text)
-- \{\|.*?\|\}
local pattern = '(<table[^>]*>.-</table>)'
local tstart, tend = text:find (pattern , 1 , false );
--mw.ustring.find( source_str, pattern, start_pos, plain )
local total = 0;
while tstart do
--mw.log(mw.ustring.sub(text, tstart, tend))
ref = text:sub(tstart, tend)
--mw.log( ref )
total = total + #ref;
tstart = tend;
tstart, tend = text:find (pattern, tstart , false );
end
return total;
end
function p.count_ref(frame)
-- {{#invoke:Sandbox/Mr. Ibrahem|count_ref|Yemen}}
local title = frame.args[1]
local _;
local page_title_object = mw.title.new(title);
local text = page_title_object:getContent();
local count;
_, count = mw.ustring.gsub (text or '', '<ref[^>/]*>', '%1');
--mw.log(_)
return count;
end
function p.ref_len(frame)
-- {{#invoke:Sandbox/Mr. Ibrahem|ref_len|Yemen}}
local title = frame.args[1]
local _,ref;
local page_title_object = mw.title.new(title);
local text = page_title_object:getContent() or '';
local pattern = '(<ref[^>]*>[^<>]+</ref>)'
local tstart, tend = text:find (pattern , 1 , false );
--mw.ustring.find( source_str, pattern, start_pos, plain )
local total = 0;
while tstart do
--mw.log(mw.ustring.sub(text, tstart, tend))
ref = text:sub(tstart, tend)
mw.log( ref )
total = total + #ref;
tstart = tend;
tstart, tend = text:find (pattern, tstart , false );
end
return total;
end
function p.EntityIdForTitle(frame)
local title = frame.args[1]
local str = mw.wikibase.getEntityIdForTitle( title )
return str
end
return p