মডিউল:প্রবেশদ্বার: সংশোধিত সংস্করণের মধ্যে পার্থক্য

বিষয়বস্তু বিয়োগ হয়েছে বিষয়বস্তু যোগ হয়েছে
সম্পাদনা সারাংশ নেই
হালনাগাদ করা হল
৩৪ নং লাইন:
 
local p = {}
 
local trackingEnabled = true
 
local templatestyles = 'মডিউল:প্রবেশদ্বার/শৈলী.css'
 
-- Check whether to do tracking in this namespace
-- Returns true unless the page is one of the banned namespaces
local function checkTrackingNamespace()
local thisPage = mw.title.getCurrentTitle()
if (thisPage.namespace == 1) -- Talk
or (thisPage.namespace == 2) -- User
or (thisPage.namespace == 3) -- User talk
or (thisPage.namespace == 5) -- Wikipedia talk
or (thisPage.namespace == 7) -- File talk
or (thisPage.namespace == 11) -- Template talk
or (thisPage.namespace == 15) -- Category talk
or (thisPage.namespace == 101) -- Portal talk
or (thisPage.namespace == 109) -- Book talk
or (thisPage.namespace == 118) -- Draft
or (thisPage.namespace == 119) -- Draft talk
or (thisPage.namespace == 829) -- Module talk
then
return false
end
return true
end
 
-- Check whether to do tracking on this pagename
-- Returns false if the page title matches one of the banned strings
-- Otherwise returns true
local function checkTrackingPagename()
local thisPage = mw.title.getCurrentTitle()
local thisPageLC = mw.ustring.lower(thisPage.text)
if (string.match(thisPageLC, "/সংগ্রহশালা") ~= nil) then
return false
end
if (string.match(thisPageLC, "/নথি") ~= nil) then
return false
end
if (string.match(thisPageLC, "/খেলাঘর") ~= nil) then
return false
end
return true
end
 
 
local function matchImagePage(s)
৬৩ ⟶ ১০৮ নং লাইন:
local function getImageName(s)
-- Gets the image name for a given string.
local default = 'Portal-puzzle.svg|link=|alt='
if type(s) ~= 'string' or #s < 1 then
return 'Portal-puzzle.svg'default
end
s = mw.ustring.lower(s)
return matchImagePage(s) or matchImagePage(getAlias(s)) or 'Portal-puzzle.svg'default
end
 
local function checkPortalExists(portal)
return not (mw.title.makeTitle(100, portal).id == 0)
end
 
৭৩ ⟶ ১২৩ নং লাইন:
-- This function builds the portal box used by the {{portal}} template.
local root = mw.html.create('div')
:addClassattr('noprintrole', portal'navigation')
:attr('aria-label', 'Portals')
:addClass('noprint portal plainlist')
:addClass(args.left and 'tleft' or 'tright')
:css('bordermargin', 'solidargs.margin #aaaor 1px'nil)
:css('margin', args.margin or (args.left == 'yes' and '0.5em 1em 0.5em 0') or '0.5em 0 0.5em 1em')
:newline()
 
-- Tracking is on by default.
-- Start the table. This corresponds to the start of the wikitext table in the old [[Template:Portal]].
-- It is disabled if any of the following is true
local tableroot = root:tag('table')
-- 1/ the parameter "tracking" is set to 'no, 'n', or 'false'
:css('background', '#f9f9f9')
-- 2/ the current page fails the namespace tests in checkTrackingNamespace()
:css('font-size', '85%')
-- 3/ the current page fails the pagename tests in checkTrackingPagename()
:css('line-height', '110%')
if (args.tracking == 'no') or (args.tracking == 'n') or (args.tracking == 'false') then
:css('max-width', '175px')
trackingEnabled = false
:css('width', type(args.boxsize) == 'string' and (args.boxsize .. 'px') or nil)
end
if (checkTrackingNamespace() == false) then
trackingEnabled = false
end
if (checkTrackingPagename() == false) then
trackingEnabled = false
end
 
-- If no portals have been specified, display an error and add the page to a tracking category.
if not portals[1] then
if (args.nominimum == 'yes') or (args.nominimum == 'y') or (args.nominimum == 'true') then
tableroot:wikitext('<strong class="error">কোন প্রবেশদ্বার নির্দিষ্ট করা হয়নি: অনুগ্রহ করে অন্তত একটি প্রবেশদ্বার উল্লেখ করুন</strong>[[Category:প্যারামিটারবিহীন প্রবেশদ্বার টেমপ্লেট]]')
-- if nominimum as been set to yes (or similar), omit the warning
else
root:wikitext('<strong class="error">কোন প্রবেশদ্বার নির্দিষ্ট করা হয়নি: অনুগ্রহ করে অন্তত একটি প্রবেশদ্বার উল্লেখ করুন</strong>')
end
if (trackingEnabled) then
root:wikitext('[[Category:প্যারামিটারবিহীন প্রবেশদ্বার টেমপ্লেট]]')
end
return tostring(root)
end
-- scan for nonexistent portals, if they exist remove them from the portals table. If redlinks=yes, then don't remove
local portallen = #portals
-- traverse the list backwards to ensure that no portals are missed (table.remove also moves down the portals in the list, so that the next portal isn't checked if going fowards.
-- going backwards allows us to circumvent this issue
for i=portallen,1,-1 do
-- the use of pcall here catches any errors that may occour when attempting to locate pages when the page name is invalid
-- if pcall returns true, then rerun the function to find if the page exists
if not pcall(checkPortalExists, portals[i]) or not checkPortalExists(portals[i]) then
-- Getting here means a redlinked portal has been found
if (args.redlinks == 'yes') or (args.redlinks == 'y') or (args.redlinks == 'true') or (args.redlinks == 'include') then
-- if redlinks as been set to yes (or similar), add the cleanup category and then break the loop before the portal is removed from the list
if (trackingEnabled) then
root:wikitext('[[Category:Portal templates with redlinked portals]]')
end
break
end
-- remove the portal (this does not happen if redlinks=yes)
table.remove(portals,i)
end
end
-- if the length of the table is different, then rows were removed from the table, so portals were removed. If this is the case add the cleanup category
if not (portallen == #portals) then
if (trackingEnabled) then
if #portals == 0 then
return '[[Category:Portal templates with all redlinked portals]]'
else
root:wikitext('[[Category:Portal templates with redlinked portals]]')
end
end
end
 
-- Start the list. This corresponds to the start of the wikitext table in the old [[Template:Portal]].
local listroot = root:tag('ul')
:css('width', type(args.boxsize) == 'string' and (args.boxsize .. 'px') or nil)
 
-- Display the portals specified in the positional arguments.
৯৭ ⟶ ২০০ নং লাইন:
 
-- Generate the html for the image and the portal name.
listroot
tableroot
:newline()
:tag('trli')
:csstag('vertical-align', 'middlespan')
:wikitext(string.format('[[File:%s|32x28px|class=noviewer]]', image))
:tag('td')
:css('text-align', 'center')
:wikitext(string.format('[[File:%s|32x28px|alt=প্রবেশদ্বার আইকন|class=noviewer]]', image))
:done()
:tag('tdspan')
:css('padding', '0 0.2em')
:css('vertical-align', 'middle')
:css('font-style', 'italic')
:css('font-weight', 'bold')
:wikitext(string.format('[[প্রবেশদ্বার:%s|%s%sপ্রবেশদ্বার]]', portal, portal, args['break'] and '<br />' or ' '))
end
১১৬ ⟶ ২১৩ নং লাইন:
 
function p._image(portals)
 
-- Wrapper function to allow getImageName() to be accessed through #invoke.
returnlocal name = getImageName(portals[1])
return name:match('^(.-)|') or name -- FIXME: use a more elegant way to separate borders etc. from the image name
end
 
২১৫ ⟶ ৩১২ নং লাইন:
end
end
return p[funcName](processPortalArgs(args)) -- passes two tables to func: an array of portal names, and a table of named arguments.
local results = ''
if funcName == '_portal' or funcName == '_displayAll' then
results = frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles} }
end
return results .. p[funcName](processPortalArgs(args)) -- passes two tables to func: an array of portal names, and a table of named arguments.
end
end