Module:sandbox/propertyID

From Rhizome Catalog
Jump to: navigation, search

local p = {}
 
 
function p.id(frame)
 
    if not mw.wikibase then
        return "no mw.wikibase"
    end
 
    entity = mw.wikibase.getEntityObject()
 
    if entity == nil then
        return "no entity"
    end
 
    return entity.id
end
 
 
function p.label(frame)
    return mw.wikibase.label( frame.args[1] )
end
 
 
function p.list(frame)
        rows = ""
        for item_number=4880,4950 do
            local item_id = "Q" .. item_number
 
            local label = mw.wikibase.label( item_id )
            if label == nil then
               label = ""
            end
            row = "<tr><td>" .. item_id .. "</td><td>" .. label .. "</td></tr>\n"
            rows = rows .. row
        end
    return "<table class=\"wikitable sortable\">\n<tr><th>id</th><th>label</th></tr>\n" .. rows .. "</table>"
end

 function p.proplist(frame)
        rows = ""
        for prop_number=80,100 do
            local prop_id = "P" .. prop_number
 
            local proplabel = mw.wikibase.label( prop_id )
            if proplabel == nil then
               proplabel = ""
            end
            row = "<tr><td>" .. prop_id .. "</td><td>" .. proplabel .. "</td></tr>\n"
            rows = rows .. row
        end
    return "<table class=\"wikitable sortable\">\n<tr><th>id</th><th>plabel</th></tr>\n" .. rows .. "</table>"
end
 
 
function p.getItem(frame)
 
    local item = mw.wikibase.getEntity( "Q1996" )
    local instance_of = item.formatPropertyValues( "P3" )
    return instance_of.value
end
 
 
function p.page(frame)
    if frame.args[1] == nil then
        entity = mw.wikibase.getEntityObject()
        if not entity then return nil end
        id = entity.id
    else
        id = frame.args[1]
    end
    return mw.wikibase.sitelink( id )
end
 
return p