Module:Wikipedia fork: Difference between revisions

No edit summary
Tag: Manual revert
No edit summary
 
Line 1: Line 1:
local mHatnote = require('Module:Hatnote')
local mHatnote   = require('Module:Hatnote')
local mArguments = require('Module:Arguments')
local mArguments = require('Module:Arguments')
local libraryUtil = require('libraryUtil')
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local checkType   = libraryUtil.checkType
local p = {}
local p = {}


function p.wikipedia_fork(frame)
function p.wikipedia_fork(frame)
    -- Get arguments from the frame
     local args = mArguments.getArgs(frame)
     local args = mArguments.getArgs(frame)
     return p._wikipedia_fork(args)
     return p._wikipedia_fork(args)
Line 12: Line 11:


function p._wikipedia_fork(args)
function p._wikipedia_fork(args)
    -- Check that args is a table
     checkType('_wikipedia_fork', 1, args, 'table', true)
     checkType('_wikipedia_fork', 1, args, 'table', true)
     args = args or {}
     args = args or {}


     -- Retrieve the article name and import date
     -- look for either date or import_date
     local articleName = args.article_name or mw.title.getCurrentTitle().text
     local articleName = args.article_name or mw.title.getCurrentTitle().text
     local importDate = args.import_date or "an unknown date"
     local importDate = args.date or args.import_date or "an unknown date"


    -- Create the forked article message
     local message = string.format(
     local message = string.format(
         "This article was forked from the [https://en.wikipedia.org/wiki/%s Wikipedia article] on %s.",
         "This article incorporated content from the [https://en.wikipedia.org/wiki/%s Wikipedia article] on %s.",
         mw.uri.encode(articleName, "PATH"), -- Encode the article name for URL
         mw.uri.encode(articleName, "PATH"),
         importDate
         importDate
     )
     )


    -- Define the hatnote options to enforce `<div>` and add classes
     local hnOptions = {
     local hnOptions = {
         selfref = args.selfref or false,
         selfref     = args.selfref or false,
         inline = 0, -- Force `<div>` structure
         inline       = 0,
         extraclasses = 'hatnote navigation-not-searchable'
         extraclasses = 'hatnote navigation-not-searchable'
     }
     }


    -- Return the message wrapped in a hatnote
     return mHatnote._hatnote(message, hnOptions)
     return mHatnote._hatnote(message, hnOptions)
end
end


return p
return p