Created page with "local p = {} function p.propertiesOfPage( frame ) local pageName = frame.args[1] or '' if pageName == '' then return '' end local rows = mw.neowiki.query([[ MATCH (page:Page {wiki_id: $wikiId}) WHERE page.name = $pageName MATCH (page)-[:HasSubject]->(s:Subject) UNWIND keys(s) AS prop WITH DISTINCT prop WHERE NOT prop IN ['id', 'wiki_id', 'name'] RETURN prop ORDER BY prop ]], { pageName = pageName,..."
 
No edit summary
 
Line 21: Line 21:
     for _, row in ipairs( rows ) do
     for _, row in ipairs( rows ) do
         table.insert( result, '* ' .. row.prop )
         table.insert( result, '* ' .. row.prop )
    end
    return table.concat( result, '\n' )
end
function p.pagesWithProperty( frame )
    local propertyName = frame.args[1] or ''
    if propertyName == '' then return '' end
    local rows = mw.neowiki.query([[
        MATCH (page:Page)-[:HasSubject]->(s:Subject)
        WHERE s[$propertyName] IS NOT NULL
        RETURN DISTINCT page.name AS pageName
        ORDER BY pageName
    ]], { propertyName = propertyName })
    if rows == nil or #rows == 0 then return 'No pages found.' end
    local result = {}
    for _, row in ipairs( rows ) do
        table.insert( result, '* [[' .. row.pageName .. ']]' )
    end
    return table.concat( result, '\n' )
end
function p.pagesWithPropertyValue( frame )
    local propertyName = frame.args[1] or ''
    local propertyValue = frame.args[2] or ''
    if propertyName == '' or propertyValue == '' then return '' end
    local rows = mw.neowiki.query([[
        MATCH (page:Page)-[:HasSubject]->(s:Subject)
        WHERE s[$propertyName] = $propertyValue
          OR $propertyValue IN s[$propertyName]
        RETURN DISTINCT page.name AS pageName
        ORDER BY pageName
    ]], { propertyName = propertyName, propertyValue = propertyValue })
    if rows == nil or #rows == 0 then return 'No pages found.' end
    local result = {}
    for _, row in ipairs( rows ) do
        table.insert( result, '* [[' .. row.pageName .. ']]' )
     end
     end
     return table.concat( result, '\n' )
     return table.concat( result, '\n' )

Latest revision as of 15:24, 20 July 2026

Documentation for this module may be created at Module:NeoWikiQueries/doc

local p = {}

function p.propertiesOfPage( frame )
    local pageName = frame.args[1] or ''
    if pageName == '' then return '' end

    local rows = mw.neowiki.query([[
        MATCH (page:Page {wiki_id: $wikiId})
        WHERE page.name = $pageName
        MATCH (page)-[:HasSubject]->(s:Subject)
        UNWIND keys(s) AS prop
        WITH DISTINCT prop
        WHERE NOT prop IN ['id', 'wiki_id', 'name']
        RETURN prop ORDER BY prop
    ]], { pageName = pageName, wikiId = mw.site.server })

    -- Fallback: use the wiki's DB name as wikiId if mw.site.server doesn't match
    if rows == nil or #rows == 0 then return 'No properties found.' end

    local result = {}
    for _, row in ipairs( rows ) do
        table.insert( result, '* ' .. row.prop )
    end
    return table.concat( result, '\n' )
end

function p.pagesWithProperty( frame )
    local propertyName = frame.args[1] or ''
    if propertyName == '' then return '' end

    local rows = mw.neowiki.query([[
        MATCH (page:Page)-[:HasSubject]->(s:Subject)
        WHERE s[$propertyName] IS NOT NULL
        RETURN DISTINCT page.name AS pageName
        ORDER BY pageName
    ]], { propertyName = propertyName })

    if rows == nil or #rows == 0 then return 'No pages found.' end

    local result = {}
    for _, row in ipairs( rows ) do
        table.insert( result, '* [[' .. row.pageName .. ']]' )
    end
    return table.concat( result, '\n' )
end

function p.pagesWithPropertyValue( frame )
    local propertyName = frame.args[1] or ''
    local propertyValue = frame.args[2] or ''
    if propertyName == '' or propertyValue == '' then return '' end

    local rows = mw.neowiki.query([[
        MATCH (page:Page)-[:HasSubject]->(s:Subject)
        WHERE s[$propertyName] = $propertyValue
           OR $propertyValue IN s[$propertyName]
        RETURN DISTINCT page.name AS pageName
        ORDER BY pageName
    ]], { propertyName = propertyName, propertyValue = propertyValue })

    if rows == nil or #rows == 0 then return 'No pages found.' end

    local result = {}
    for _, row in ipairs( rows ) do
        table.insert( result, '* [[' .. row.pageName .. ']]' )
    end
    return table.concat( result, '\n' )
end

return p