Module:Sandbox/WikiJunkie

.mw-parser-output .documentation,.mw-parser-output .documentation-metadata{border:1px solid var(--border-color-base,#a2a9b1);background-color:#ecfcf4;color:inhe

Module:Sandbox/WikiJunkie
-- Beta functions getname2 and getinternal links

local p = {}

local function loadwikinames()
    local wikinames = {}	
	wikinames[1] = "wikisource"
	wikinames[2] = "wikibooks"
	wikinames[3] = "wikinews"
	wikinames[4] = "wikiquote"
	wikinames[5] = "wikivoyage"
	wikinames[6] = "wiki"
	return wikinames
end  

function p.getname(frame)
	local name=mw.wikibase.getEntityIdForTitle(frame.args[1])
	if name == "" or name == nil then return "" end
	return name
	end

function p.getname2(frame)
	local names=frame.args[1]
	local name = ""
	local image = ""
	local items = {}
	local index = 1
    local id = ""
	local latitude = ''
	local longitude = ''
	local marker = ''
    local entity = ''
    local data = ""
    local separator = '\n'
    local lang = ''
    local wiki = ''
    local wikiname = ''
    
 for str in string.gmatch(names,"([^"..separator.."]+)") do
 	if str ~= nil and str ~= "" then
 		str = string.gsub(str,"^%s+","")
     	str = string.gsub(str,"%s+$","")
     	if str ~= "" then
	       items[index] = str
	       index = index + 1
	       end
	    end
	end    

 for i=1,#items do
 	name = items[i]
 	id = ""
    wikiname = '' 	
	id=mw.wikibase.getEntityIdForTitle(items[i])
    if id == nil then id = '' end
    
if id ~= nil and id ~= '' then
    entity = mw.wikibase.getEntityObject(id)	

    if entity == nil then
		latitude = ""
	    longitude = ""
	    end
	    
	local claims = entity.claims
	if claims == nil then
		latitude = ""
		longitude = ""
	    end	
--	if claims.P625 ~= nil then
if pcall(function () t =claims.P625 end ) then
 		if pcall(function () t =entity.claims.P625[1].mainsnak.datavalue.value.latitude end ) then		
		latitude = entity.claims.P625[1].mainsnak.datavalue.value.latitude
		else latitude = "" end
 		if pcall(function () t =entity.claims.P625[1].mainsnak.datavalue.value.longitude end ) then		
		longitude = entity.claims.P625[1].mainsnak.datavalue.value.longitude
		else longitude = "" end
end

--	if claims.P18 ~= nil then
--		image = entity.claims.P18[1].mainsnak.datavalue.value
--		if image == nil then
--			image = ""
--
-- Replace above due to error of getting a nil value
-- Lua error in line 3210: attempt to index field 'datavalue' (a nil value).
image=""
if pcall(function () t =claims.P625 end ) then
 		if pcall(function () t =entity.claims.P18[1].mainsnak.datavalue.value end ) then		
		      image = entity.claims.P18[1].mainsnak.datavalue.value
		    else
		    	image = ""
			end		   

end

		
	end

    wikiname = ""	
	lang = mw.language.getContentLanguage(id).code
	wiki = lang .. "wiki"
	if pcall(function()t1 = entity:getSitelink("wiki") end) then	
        wikiname = entity:getSitelink(wiki) or ""
    else
    	wikiname = ""
    end

if id == "" then wikiname = "" end
if id ~= nil and id ~= "" then
			name = "[[" .. name .. "]]"
end
    marker = '* {{see | name=' .. name .. " | lat=" .. latitude .. " | long=" .. longitude .. " | image=" .. image .. " | wikipedia=" .. wikiname .. " | wikidata=" .. id .. "}}"
    data = data .. marker .. "\n"
    marker = ''
    name = ''
    latitude = ''
    longitude = ''
    image= ''
    id = ''
    wikiname = ''
	
end
    
    return data
    end

-- Load a page and scan it for internal links

function p.getinternallinks(frame)
		local page = frame.args[1] or "Main Page"
        local title = mw.title.new(page)
        local displayactual = frame.args['option'] or "yes"
        if title == nil then return end

        if title.id == 0 then
            return "Page does not exist!"
        end

        local data = title:getContent()
		
		if data == nil or data == "" then
			return
		end

		local tt = {}
		local count = 0
		local output = ""
		local separator = "@@@@@"
		local newstr = ""		
			

		data = string.gsub(data,"\n","@@@@@")								--change \n to separator @@@@@
		data = string.gsub(data,"@","BULLET")								--because I use @@@@@ as a separator changing @ to BULLET
		data = string.gsub(data,"%s+"," ")									--change multiple spaces to a space
		data = string.gsub(data,"%[%[","@@@@@[[")							--change [[ to separator @@@@@[[
		data = string.gsub(data,"%]%]","]]@@@@@")							--change ]] to separator ]]@@@@@
		data = string.gsub(data,"@@@@@@@@@@","@@@@@")						--change ]] to separator ]]@@@@@

		for str in string.gmatch(data,"([^"..separator.."]+)") do

			if str ~= nil and str ~= "" then

-- Get rid of File,file,Image,image
 str = string.gsub(str,"%[%[[fF]ile.*",'')
 str = string.gsub(str,"%[%[[iI]mage.*",'')

				str = string.gsub(str,'%s*$','')       					-- drop ending space
				str = string.gsub(str,'^%s+','')
					if string.find(str, '^%[%[') == 1 then			    -- Key is to have [[ at beginning
					    str = string.gsub(str,'%_'," ")
						str = string.gsub(str,'%%2C',",")
						str = string.gsub(str,'%s+%|%s+','|')
						str = string.gsub(str,'%[%[%#','[[' .. page .. '#')
-- Display only actual link make it an option
if displayactual == "yes" then
	str = string.gsub(str,"%|.*%]%]","]]")
end
					    count = count + 1
--					    localstr = str.gsub(str,'^.*|','')
                        localstr = str.gsub(str,'|.*','')
                        localstr = string.upper (localstr)

						tt[count] = localstr .. "@-@" .. str
						end
				end
		end

		table.sort(tt)
		local previous = ""

		for key,value in pairs(tt) do
value = string.gsub(value,'^.*@-@','')
			if value ~= previous then
                output = output .. value .. " -- "
			end
			    previous = value
		end		

		output = string.gsub(output,"BULLET","@")
		output = string.gsub(output," -- $","")
	return output
end


return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.