Module:Disambiguation page
More actions
This documentation is transcluded from Module:Disambiguation page/doc. Changes can be proposed in the talk page.
require("strict");
local listModule = require('Module:List')
local cargo = mw.ext.cargo
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function insertListItem(listName, queryOutput, i)
local atOrOwnedBy = {}
if queryOutput[i].Location ~= nil then
if queryOutput[i].Location == 'Travelling' then
atOrOwnedBy = ', owned by '
else
atOrOwnedBy = ' at '
end
else
atOrOwnedBy = ' at '
end
if queryOutput[i].Name ~= nil then
if queryOutput[i].Park ~= nil then
table.insert(listName, "''[[" .. queryOutput[i]._pageTitle .. "|" .. queryOutput[i].Name .. "]]''" .. atOrOwnedBy .. queryOutput[i].Park)
elseif queryOutput[i].Operator ~= nil then
table.insert(listName, "''[[" .. queryOutput[i]._pageTitle .. "|" .. queryOutput[i].Name .. "]]''" .. atOrOwnedBy .. queryOutput[i].Operator)
else
table.insert(listName, "''[[" .. queryOutput[i]._pageTitle .. "|" .. queryOutput[i].Name .. "]]''")
end
end
end
local function getSortKey(result)
if result.Park ~= nil then
if (result.Park:sub(1,2) == '[[') then
return result.Park:sub(3, -1)
else
return result.Park
end
elseif result.Operator ~= nil then
if (result.Operator:sub(1,2) == '[[') then
return result.Operator:sub(3, -1)
else
return result.Operator
end
else
return 'zzzzzz'
end
end
function p.disamb(frame)
local args = getArgs(frame)
local name = mw.title.getCurrentTitle().text
if args.Name ~= nil then
name = args.Name
end
-- Products
local productResults=cargo.query('Products','Name, _pageTitle, Manufacturer',{where = 'Name="' .. name .. '"', groupBy = '_pageTitle'})
local productLinesResults=cargo.query('Product_Lines','Name, _pageTitle, Manufacturer',{where = 'Name="' .. name .. '"', groupBy = '_pageTitle'})
for i=1,#productLinesResults do
if productLinesResults[i]._pageTitle ~= nil then
table.insert(productResults,productLinesResults[i])
end
end
local listItemsProducts = {}
for i=1,#productResults do
table.insert(listItemsProducts, "''[[" .. productResults[i]._pageTitle .. "|" .. productResults[i].Name .. "]]'' from " .. productResults[i].Manufacturer)
end
local listProducts = listModule.bulleted(listItemsProducts)
-- Amusement parks
local parkResults=cargo.query('Amusement_Parks','Name, _pageTitle, Country, Status',{where = 'Name="' .. name .. '" AND (Status="operating" OR Status="standing but not operating" OR Status="under construction")', groupBy = '_pageTitle'})
local parkResultsPast=cargo.query('Amusement_Parks','Name, _pageTitle, Country, Status',{where = 'Name="' .. name .. '" AND Status="defunct"', groupBy = '_pageTitle'})
table.sort(parkResults, function(a,b) return getSortKey(a) < getSortKey(b) end)
table.sort(parkResultsPast, function(a,b) return getSortKey(a) < getSortKey(b) end)
local listItemsParks = {}
local listItemsParksPast = {}
for i=1,#parkResults do
table.insert(listItemsParks, "''[[" .. parkResults[i]._pageTitle .. "|" .. parkResults[i].Name .. "]]'' in " .. parkResults[i].Country)
end
for i=1,#parkResultsPast do
table.insert(listItemsParksPast, "''[[" .. parkResults[i]._pageTitle .. "|" .. parkResults[i].Name .. "]]''" .. parkResults[i].Country)
end
local listParks = listModule.bulleted(listItemsParks)
local listParksPast = listModule.bulleted(listItemsParksPast)
-- Coasters
local coasterResults=cargo.query('Roller_Coasters','Name, CONCAT(Park)=Park,Operator, _pageTitle, Location',{where = "(Name='" .. name .. "' OR Name='The " .. name .. "') AND (Status='operating' OR Status='standing but not operating' OR Status='under construction')", groupBy = '_pageTitle'})
local coasterResultsPast=cargo.query('Roller_Coasters','Name, CONCAT(Park)=Park,Operator, _pageTitle, Location',{where = "(Name='" .. name .. "' OR Name='The " .. name .. "') AND (Status='defunct' OR Status='unknown')", groupBy = '_pageTitle'})
local coasterResultsPastLocations=cargo.query('Roller_Coaster_Past_Locations, Roller_Coasters','Roller_Coaster_Past_Locations.Name=Name, CONCAT(Roller_Coaster_Past_Locations.Park)=Park,CONCAT(Roller_Coaster_Past_Locations.Operator)=Operator,Roller_Coaster_Past_Locations._pageTitle=_pageTitle, Roller_Coasters._pageTitle=CoasterPageTitle, Roller_Coaster_Past_Locations.Location=Location',{where = "(Roller_Coaster_Past_Locations.Name='" .. name .. "' OR Roller_Coaster_Past_Locations.Name='The " .. name .. "')",groupBy = 'Roller_Coaster_Past_Locations.Park', join = 'Roller_Coaster_Past_Locations._pageID = Roller_Coasters._pageID'})
local coasterResultsPastNames=cargo.query('Roller_Coasters, PastNames','PastNames.Name=Name, Roller_Coasters._pageTitle=_pageTitle, CONCAT(Park)=Park,Roller_Coasters.Operator, Roller_Coasters._pageTitle, Roller_Coasters.Location',{where = "(PastNames.Name='" .. name .. "' OR PastNames.Name='The " .. name .. "')",join = 'Roller_Coasters._pageID = PastNames._pageID'})
for i=1,#coasterResultsPastLocations do
if coasterResultsPastLocations[i].CoasterPageTitle ~= nil then
table.insert(coasterResultsPast,coasterResultsPastLocations[i])
end
end
for i=1,#coasterResultsPastNames do
mw.logObject(coasterResultsPastNames)
table.insert(coasterResultsPast,coasterResultsPastNames[i])
end
table.sort(coasterResults, function(a,b) return getSortKey(a) < getSortKey(b) end) -- required in case there are any coasters beginning with "The"
table.sort(coasterResultsPast, function(a,b) return getSortKey(a) < getSortKey(b) end)
local listItemsCoasters = {}
local listItemsCoastersPast = {}
for i=1,#coasterResults do
insertListItem(listItemsCoasters, coasterResults, i)
end
for i=1,#coasterResultsPast do
insertListItem(listItemsCoastersPast, coasterResultsPast, i)
end
local listCoasters = listModule.bulleted(listItemsCoasters)
local listCoastersPast = listModule.bulleted(listItemsCoastersPast)
-- Rides
local rideResults=cargo.query('Rides','Name, CONCAT(Park)=Park,Operator, _pageTitle, Location',{where = "(Name='" .. name .. "' OR Name='The " .. name .. "')AND (Status='operating' OR Status='standing but not operating' OR Status='under construction')", groupBy = '_pageTitle'})
local rideResultsPast=cargo.query('Rides','Name, CONCAT(Park)=Park,Operator, _pageTitle, Location',{where = "(Name='" .. name .. "' OR Name='The " .. name .. "')AND (Status='defunct' OR Status='unknown')", groupBy = '_pageTitle'})
local rideResultsPastLocations=cargo.query('Roller_Coaster_Past_Locations, Rides','Roller_Coaster_Past_Locations.Name=Name, CONCAT(Roller_Coaster_Past_Locations.Park)=Park,CONCAT(Roller_Coaster_Past_Locations.Operator)=Operator,Roller_Coaster_Past_Locations._pageTitle=_pageTitle, Rides._pageTitle=RidesPageTitle, Rides.Location=Location',{where = "(Roller_Coaster_Past_Locations.Name='" .. name .. "' OR Roller_Coaster_Past_Locations.Name='The " .. name .. "')",groupBy = 'Roller_Coaster_Past_Locations.Park', join = 'Roller_Coaster_Past_Locations._pageID = Rides._pageID'})
mw.logObject(rideResultsPastLocations)
for i=1,#rideResultsPastLocations do
if rideResultsPastLocations[i].RidesPageTitle ~= nil then
table.insert(rideResultsPast,rideResultsPastLocations[i])
end
end
table.sort(rideResults, function(a,b) return getSortKey(a) < getSortKey(b) end) -- required in case there are any rides beginning with "The"
table.sort(rideResultsPast, function(a,b) return getSortKey(a) < getSortKey(b) end)
local listItemsRides = {}
local listItemsRidesPast = {}
for i=1,#rideResults do
insertListItem(listItemsRides, rideResults, i)
end
for i=1,#rideResultsPast do
insertListItem(listItemsRidesPast, rideResultsPast, i)
end
local listRides = listModule.bulleted(listItemsRides)
local listRidesPast = listModule.bulleted(listItemsRidesPast)
-- Water slides
local slideResults=cargo.query('Water_Slides','Name, CONCAT(Park)=Park, _pageTitle, Location',{where = "(Name='" .. name .. "' OR Name='The " .. name .. "')AND (Status='operating' OR Status='standing but not operating' OR Status='under construction')", groupBy = '_pageTitle'})
local slideResultsPast=cargo.query('Water_Slides','Name, CONCAT(Park)=Park, _pageTitle, Location',{where = "(Name='" .. name .. "' OR Name='The " .. name .. "')AND (Status='defunct' OR Status='unknown')", groupBy = '_pageTitle'})
--local rideResultsPastLocations=cargo.query('Roller_Coaster_Past_Locations, Rides','Roller_Coaster_Past_Locations.Name=Name, CONCAT(Roller_Coaster_Past_Locations.Park)=Park,CONCAT(Roller_Coaster_Past_Locations.Operator)=Operator,Roller_Coaster_Past_Locations._pageTitle=_pageTitle, Rides._pageTitle=RidesPageTitle, Rides.Location=Location',{where = "(Roller_Coaster_Past_Locations.Name='" .. name .. "' OR Roller_Coaster_Past_Locations.Name='The " .. name .. "')",join = 'Roller_Coaster_Past_Locations._pageID = Rides._pageID'})
-- for i=1,#rideResultsPastLocations do
-- if rideResultsPastLocations[i].RidesPageTitle ~= nil then
-- table.insert(rideResultsPast,rideResultsPastLocations[i])
-- end
--end
table.sort(slideResults, function(a,b) return getSortKey(a) < getSortKey(b) end) -- required in case there are any rides beginning with "The"
table.sort(slideResultsPast, function(a,b) return getSortKey(a) < getSortKey(b) end)
local listItemsSlides = {}
--local listItemsRidesPast = {}
for i=1,#slideResults do
insertListItem(listItemsSlides, slideResults, i)
end
for i=1,#slideResultsPast do
insertListItem(listItemsSlides, slideResultsPast, i)
end
local listSlides = listModule.bulleted(listItemsSlides)
--local listRidesPast = listModule.bulleted(listItemsRidesPast)
-- Starting with...
local seeAlsoCoasterResults=cargo.query('Roller_Coasters','Name, CONCAT(Park)=Park, CONCAT(Operator)=Operator, _pageTitle, Location',{where = "Name LIKE '" .. name .. "%' AND Name <> '" .. name .. "'", groupBy = '_pageTitle'})
local seeAlsoRideResults=cargo.query('Rides','Name, CONCAT(Park)=Park, CONCAT(Operator)=Operator, _pageTitle, Location',{where = "Name LIKE '" .. name .. "%' AND Name <> '" .. name .. "'", groupBy = '_pageTitle'})
--local seeAlsoSlideResults=cargo.query('Water_Slides','Name, CONCAT(Park)=Park, _pageTitle, Location',{where = "Name LIKE '" .. name .. "%' AND Name <> '" .. name .. "'"})
local seeAlsoRideResultsPastLocations=cargo.query('Roller_Coaster_Past_Locations','CONCAT(Roller_Coaster_Past_Locations.Park)=Park,CONCAT(Roller_Coaster_Past_Locations.Operator)=Operator,_pageTitle',{where = "Name LIKE '" .. name .. "%' AND Name <> '" .. name .. "'", groupBy = 'Roller_Coaster_Past_Locations.Park'})
for i=1,#seeAlsoRideResultsPastLocations do
if seeAlsoRideResultsPastLocations[i]._pageTitle ~= nil then
table.insert(seeAlsoRideResults,seeAlsoRideResultsPastLocations[i])
end
end for i=1,#seeAlsoCoasterResults do
if seeAlsoCoasterResults[i]._pageTitle ~= nil then
table.insert(seeAlsoRideResults,seeAlsoCoasterResults[i])
end
end
table.sort(seeAlsoRideResults, function(a,b) return getSortKey(a) < getSortKey(b) end) -- required in case there are any rides beginning with "The"
local listItemsSeeAlsoRides = {}
local listItemsSeeAlsoRidesPast = {}
for i=1,#seeAlsoRideResults do
insertListItem(listItemsSeeAlsoRides, seeAlsoRideResults, i)
end
local seeAlsoListRides = listModule.bulleted(listItemsSeeAlsoRides)
-- Contains...
mw.log("Contains")
local containsCoasterResults=cargo.query('Roller_Coasters','Name, CONCAT(Park)=Park, CONCAT(Operator)=Operator, _pageTitle, Location',{where = "Name LIKE '%" .. name .. "%' AND Name NOT LIKE '" .. name .. "%'", groupBy = '_pageTitle'})
local containsRideResults=cargo.query('Rides','Name, CONCAT(Park)=Park, CONCAT(Operator)=Operator, _pageTitle, Location',{where = "Name LIKE '%" .. name .. "%' AND Name NOT LIKE '" .. name .. "%'", groupBy = '_pageTitle'})
local containsRideResultsPastLocations=cargo.query('Roller_Coaster_Past_Locations','CONCAT(Roller_Coaster_Past_Locations.Park)=Park,CONCAT(Roller_Coaster_Past_Locations.Operator)=Operator,_pageTitle, Location',{where = "Name LIKE '%" .. name .. "%' AND Name NOT LIKE '" .. name .. "%'", groupBy = 'Roller_Coaster_Past_Locations.Park'})
for i=1,#containsRideResultsPastLocations do
if containsRideResultsPastLocations[i]._pageTitle ~= nil then
table.insert(containsRideResults,containsRideResultsPastLocations[i])
end
end for i=1,#containsCoasterResults do
if containsCoasterResults[i]._pageTitle ~= nil then
table.insert(containsRideResults,containsCoasterResults[i])
end
end
table.sort(containsRideResults, function(a,b) return getSortKey(a) < getSortKey(b) end) -- required in case there are any rides beginning with "The"
local listItemsContainsRides = {}
local listItemsContainsRidesPast = {}
for i=1,#containsRideResults do
insertListItem(listItemsContainsRides, containsRideResults, i)
end
local containsListRides = listModule.bulleted(listItemsContainsRides)
-- Output
local htmlOutput = mw.html.create('div')
htmlOutput:wikitext(frame:expandTemplate{ title = 'disambig'})
htmlOutput:newline()
if listProducts ~= "" then
htmlOutput:wikitext("The wiki has articles on the following products named ''" .. name .. "'':"):wikitext(listProducts)
end
if listParks ~= "" then
htmlOutput:wikitext("The wiki has articles on the following amusement parks named ''" .. name .. "'':"):wikitext(listParks)
end
if listParksPast ~= "" then
htmlOutput:wikitext("The wiki has articles on the following amusement parks formerly named ''" .. name .. "'':"):wikitext(listParksPast)
end
if listCoasters ~= "" then
htmlOutput:wikitext("The wiki has articles on the following coasters named ''" .. name .. "'':"):wikitext(listCoasters)
end
if listCoastersPast ~= "" then
htmlOutput:wikitext("The wiki has articles on the following coasters formerly named ''" .. name .. "'':"):wikitext(listCoastersPast)
end
if listRides ~= "" then
htmlOutput:wikitext("The wiki has articles on the following rides named ''" .. name .. "'':"):wikitext(listRides)
end
if listRidesPast ~= "" then
htmlOutput:wikitext("The wiki has articles on the following rides formerly named ''" .. name .. "'':"):wikitext(listRidesPast)
end
if listSlides ~= "" then
htmlOutput:wikitext("The wiki has articles on the following water slides named ''" .. name .. "'':"):wikitext(listSlides)
end
if seeAlsoListRides ~= "" then
htmlOutput:wikitext("The following attractions start with ''" .. name .. "'':"):wikitext(seeAlsoListRides)
end
if containsListRides ~= "" then
htmlOutput:wikitext("The following attractions contain the phrase ''" .. name .. "'':"):wikitext(containsListRides)
end
if args.seeAlso ~= nil then
htmlOutput:newline()
htmlOutput:wikitext("See also:")
htmlOutput:newline()
htmlOutput:wikitext(args.seeAlso)
end
return htmlOutput
end
return p