Module:ElementNavigation: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Reverted
// via Wikitext Extension for VSCode
Tag: Manual revert
Line 14: Line 14:
  * - Blueprint integration as a custom block
  * - Blueprint integration as a custom block
]]
]]
-- External dependencies
local ErrorHandling = require('Module:ErrorHandling')
local Blueprint = require('Module:LuaTemplateBlueprint')
-- MediaWiki global for linting
local mw = mw or {} -- This allows linting to work while still using the global mw in MediaWiki


local p = {}
local p = {}


p.elementName = "navigation"
p.elementName = "navigation"
-- Helper function to add this element to a template with custom configuration
-- @param template table The Blueprint template object
-- @param errorContext table The error context for safe require
-- @param options table Optional configuration overrides
function p.addToTemplate(template, errorContext, options)
    options = options or {}
   
    -- Only proceed if we're properly loaded
    local self = errorContext and ErrorHandling.safeRequire(errorContext, 'Module:ElementNavigation', false) or p
   
    if self and self.elementName then
        -- Register this element with Blueprint
        Blueprint.registerElement(self.elementName, self)
       
        -- Add the element to the template
        Blueprint.addElementToTemplate(template, 'navigation')
       
        -- Set up configuration with defaults that can be overridden
        template.config.navigation = {
            autoDetect = options.autoDetect ~= nil and options.autoDetect or true,
            patterns = options.patterns or self.defaultConfig.patterns,
            prevField = options.prevField or self.defaultConfig.prevField,
            nextField = options.nextField or self.defaultConfig.nextField,
            prevLabel = options.prevLabel or "← %s",
            nextLabel = options.nextLabel or "%s →",
            prevClass = options.prevClass or self.defaultConfig.prevClass,
            nextClass = options.nextClass or self.defaultConfig.nextClass,
            rowHeight = options.rowHeight or self.defaultConfig.rowHeight
        }
       
        return true
    end
   
    return false
end
p.defaultConfig = {
p.defaultConfig = {
     autoDetect = true,
     autoDetect = true,
Line 252: Line 208:
                 -- Use "class=" parameter in MediaWiki link syntax for proper styling
                 -- Use "class=" parameter in MediaWiki link syntax for proper styling
                 table.insert(output, string.format(
                 table.insert(output, string.format(
                     '<div class="%s">[[%s|%s]]</div>',
                     '<div class="element-navigation-prev">[[%s|%s]]</div>',
                     prevClass, prevPage, prevLabel
                     prevPage, prevLabel
                 ))
                 ))
             else
             else
Line 265: Line 221:
                 -- Use "class=" parameter in MediaWiki link syntax for proper styling
                 -- Use "class=" parameter in MediaWiki link syntax for proper styling
                 table.insert(output, string.format(
                 table.insert(output, string.format(
                     '<div class="%s">[[%s|%s]]</div>',
                     '<div class="element-navigation-next">[[%s|%s]]</div>',
                     nextClass, nextPage, nextLabel
                     nextPage, nextLabel
                 ))
                 ))
             else
             else