Spiderjjr45 (talk | contribs) (Created page with "local p = {} -- Function to fetch and return the Worldbuilder section local function getWorldbuilderSection() local pageTitle = mw.title.getCurrentTitle().text local talkPageTitle = 'Talk:' .. pageTitle local talkPage = mw.title.new(talkPageTitle) local talkContent = talkPage:getContent() if not talkContent then return '' end local sectionPattern = '==%s*Worldbuilder%s*==(.*)' local worldbuilderSection = talkContent:match(sectio...") |
Spiderjjr45 (talk | contribs) No edit summary |
||
(16 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
⚫ | |||
⚫ | |||
-- Get the title of the current page |
|||
⚫ | |||
local pageTitle = mw.title.getCurrentTitle(). |
local pageTitle = mw.title.getCurrentTitle().prefixedText |
||
⚫ | |||
⚫ | |||
⚫ | |||
-- Construct the Talk page URL |
|||
⚫ | |||
local talkPageTitle = pageTitle:gsub(" ", "_") -- Replace spaces with underscores |
|||
return '' |
|||
local baseWikiUrl = 'https://quelmarwiki.com/wiki/' |
|||
⚫ | |||
⚫ | |||
local editSectionUrl = talkPageUrl .. '?action=edit§ion=new&preloadtitle=Worldbuilders&preload=Template:WorldbuilderPreload' |
|||
-- Link text |
|||
local addLinkText = 'Add worldbuilding credits now!' |
|||
-- Fetch the content of the Talk page |
|||
⚫ | |||
⚫ | |||
-- Check if the Talk page exists and has content |
|||
⚫ | |||
return '[' .. editSectionUrl .. ' ' .. addLinkText .. ']' |
|||
end |
end |
||
-- Extract the Worldbuilder section |
|||
local sectionPattern = '==%s*Worldbuilders%s*==(.*)' |
|||
local worldbuilderSection = talkContent:match(sectionPattern) |
local worldbuilderSection = talkContent:match(sectionPattern) |
||
-- Check if the Worldbuilder section exists |
|||
if not worldbuilderSection then |
if not worldbuilderSection then |
||
return '' |
return '[' .. editSectionUrl .. ' ' .. addLinkText .. ']' |
||
end |
end |
||
-- Create the internal wiki link for "Worldbuilders" using the fullText of the talkPage |
|||
⚫ | |||
local worldbuildersLink = '[[' .. talkPage.fullText .. '|Worldbuilders]]' |
|||
⚫ | |||
-- Prepend "Worldbuilders" link to the section content |
|||
-- Automatically execute the function when the module is invoked |
|||
⚫ | |||
p = getWorldbuilderSection() |
|||
⚫ | |||
return p |
return p |
Latest revision as of 02:54, 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§ion=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 -- Create the internal wiki link for "Worldbuilders" using the fullText of the talkPage local worldbuildersLink = '[[' .. talkPage.fullText .. '|Worldbuilders]]' -- Prepend "Worldbuilders" link to the section content return worldbuildersLink .. ':\n' .. worldbuilderSection end return p