Module:Favilink Utility: Difference between revisions

mNo edit summary
Add Endgame namespace to search
 
(10 intermediate revisions by 2 users not shown)
Line 5: Line 5:
local name
local name
local fields = fieldsin or 'JoinKey=Page, DisplayName, PlainName, COALESCE(Image, DisplayChar)=Display'
local fields = fieldsin or 'JoinKey=Page, DisplayName, PlainName, COALESCE(Image, DisplayChar)=Display'
local namespaces = '(_pageNamespace="0" OR _pageNamespace="10002")'
local namespaces = '(_pageNamespace="0" OR _pageNamespace="10002" OR _pageNamespace="10006")'
searchtype = searchtype or 'PlainName'
searchtype = searchtype or 'PlainName'
name = mw.text.trim(frame)
name = mw.text.trim(frame)
Line 21: Line 21:
  {where=namespaces .. wherestr,
  {where=namespaces .. wherestr,
default=name,
default=name,
limit='1',
orderBy='_pageNamespace ASC'} )
orderBy='_pageNamespace ASC'} )
local resulttrue = 0
local resulttrue = 0
Line 35: Line 34:
{where=namespaces .. wherestr,
{where=namespaces .. wherestr,
  default=name,
  default=name,
  limit='1',
  orderBy='_pageNamespace ASC'} )
  orderBy='_pageNamespace ASC'} )
if next(result) then  
if next(result) then  
Line 43: Line 41:
resulttrue = 1
resulttrue = 1
end
end
 
-- If there was a result, check if there were more than two found objects.
if resulttrue == 1 then
if resulttrue == 1 then
return result
if #result > 1 and searchtype == 'ObjectID' then
error("There was more than one result with the name " .. name .. "![[Category:pages with favilink errors]]")
end
return result[1]
else
else
return nil
return nil
Line 66: Line 67:
     return name .. '(no results)]][[Category:Pages with ID to Name errors'
     return name .. '(no results)]][[Category:Pages with ID to Name errors'
else  
else  
     return result[1]['PlainName']
     return result['PlainName']
end
end
end
end
Line 74: Line 75:
if frame.args ~= nil then
if frame.args ~= nil then
     name = frame.args[1]
     name = frame.args[1]
    overridelink = frame.args[2] and frame.args[2] == "overridelink" or False
end
end
local result = p.main(name, 'ObjectID', '_pageName=Page')
local result = p.main(name, 'ObjectID', '_pageName=Page,PlainName')
if result == nil then
if result == nil then
     return name .. '(no results)]][[Category:Pages with ID to Page errors'
     return name .. '(no results)]][[Category:Pages with ID to Page errors'
Line 81: Line 83:
     return name .. '(no results)]][[Category:Pages with ID to Page errors'
     return name .. '(no results)]][[Category:Pages with ID to Page errors'
else  
else  
    return result[1]['Page']
pagename = result['Page']
plainname = result['PlainName']
if string.lower(plainname) == string.lower(pagename) or not overridelink then
return pagename
end
-- otherwise, use plainname for stuff like cybernetics credit wedge 2¢
return result['Page'] .. '|' .. result['PlainName']
end
end
end
end


return p
return p