Module:Path stripper

From Wikisphere
Jump to navigation Jump to search

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

local p = {}


function p.main(frame)

  
	local param = (type(frame.getParent) == 'function') and frame:getParent().args or frame
    
    if(param[1] == nil) then
      return ''
    end

    param = param[1]

    a, b, page, link = string.find(param, '^%[%[(.+)%|(.+)%]%]$')

    if(page == ':' .. link) then
       page = link
    end


    local str
     if(a == nil) then 
         c, d, str = string.find(param, '^%[%[(.+)%]%]$')

         if(c == nil) then
            return param
         end

     elseif (page ~= link) then
         return param
     else
       str = page
     end
    

    local result = mw.ustring.gsub(str, '^(.*/)(.+)$', '%1%2|%2')

    result = '[[' .. result .. ']]'

    return result



end
--=p.main("[[Shorena/News/Abcd|Shorena/News/Abc]]")
--=p.main("[[Shorena/News/Abcd]]")
return p