×
Create a new article
Write your page title here:
We currently have 1,707 articles on The Quelmar Wiki. Type your article name above or click on one of the titles below and start writing!



The Quelmar Wiki

Module:Worldbuilders: Difference between revisions

No edit summary
No edit summary
Line 3: Line 3:
function p.getWorldbuilderSection(frame)
function p.getWorldbuilderSection(frame)
-- Get the title of the current page
-- Get the title of the current page
local pageTitle = mw.title.getCurrentTitle().text
local pageTitle = mw.title.getCurrentTitle().prefixedText


-- Fetch the content of the Talk page
-- Construct the Talk page URL
local talkPageTitle = 'Talk:' .. pageTitle
local talkPageTitle = pageTitle:gsub(" ", "_") -- Replace spaces with underscores
local talkPage = mw.title.new(talkPageTitle)
local baseWikiUrl = 'https://quelmarwiki.com/wiki/'
local talkContent = talkPage:getContent()
local talkPageUrl = baseWikiUrl .. 'Talk:' .. talkPageTitle


-- Define the URL for adding the Worldbuilder section
-- Construct the edit URL for adding the Worldbuilder section
local editSectionUrl = talkPageUrl .. '?action=edit&section=new&preloadtitle=Worldbuilders&preload=Template:WorldbuilderPreload'
local addSectionParams = {
action = 'edit',
section = 'new',
preloadtitle = 'Worldbuilders',
preload = 'Template:WorldbuilderPreload' -- Assuming you have a template for preload content
}
local addSectionUrl = mw.uri.fullUrl(talkPageTitle, addSectionParams).full


-- Link text
-- Link text
local addLinkText = 'Add worldbuilding credits now!'
local addLinkText = 'Add worldbuilding credits now!'

-- Fetch the content of the Talk page
local talkPage = mw.title.new('Talk:' .. pageTitle)
local talkContent = talkPage and talkPage:getContent() or nil


-- Check if the Talk page exists and has content
-- Check if the Talk page exists and has content
if not talkContent then
if not talkContent or talkContent == '' then
return '[' .. addSectionUrl .. ' ' .. addLinkText .. ']'
return '[' .. editSectionUrl .. ' ' .. addLinkText .. ']'
end
end


Line 33: Line 31:
-- Check if the Worldbuilder section exists
-- Check if the Worldbuilder section exists
if not worldbuilderSection then
if not worldbuilderSection then
return '[' .. addSectionUrl .. ' ' .. addLinkText .. ']'
return '[' .. editSectionUrl .. ' ' .. addLinkText .. ']'
end
end



Revision as of 01:46, 10 January 2024

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

local p = {}

function p.getWorldbuilderSection(frame)
    -- Get the title of the current page
    local pageTitle = mw.title.getCurrentTitle().prefixedText

    -- Construct the Talk page URL
    local talkPageTitle = pageTitle:gsub(" ", "_")  -- Replace spaces with underscores
    local baseWikiUrl = 'https://quelmarwiki.com/wiki/'
    local talkPageUrl = baseWikiUrl .. 'Talk:' .. talkPageTitle

    -- Construct the edit URL for adding the Worldbuilder section
    local editSectionUrl = talkPageUrl .. '?action=edit&section=new&preloadtitle=Worldbuilders&preload=Template:WorldbuilderPreload'

    -- Link text
    local addLinkText = 'Add worldbuilding credits now!'

    -- Fetch the content of the Talk page
    local talkPage = mw.title.new('Talk:' .. pageTitle)
    local talkContent = talkPage and talkPage:getContent() or nil

    -- Check if the Talk page exists and has content
    if not talkContent or talkContent == '' then
        return '[' .. editSectionUrl .. ' ' .. addLinkText .. ']'
    end

    -- Extract the Worldbuilder section
    local sectionPattern = '==%s*Worldbuilders%s*==(.*)'
    local worldbuilderSection = talkContent:match(sectionPattern)

    -- Check if the Worldbuilder section exists
    if not worldbuilderSection then
        return '[' .. editSectionUrl .. ' ' .. addLinkText .. ']'
    end

    -- Return the Worldbuilder section content
    return worldbuilderSection
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies. (Hi Margarita's Table. 🇩🇪)

Recent changes

  • Mslilith • 00:47
  • 192.168.0.15 • 00:46
  • John L • Yesterday at 06:29
  • Jeffbuterbaugh • Yesterday at 00:19
  • Cookies help us deliver our services. By using our services, you agree to our use of cookies. (Hi Margarita's Table. 🇩🇪)