Module:Check DYK hook
This module checks the format of Wikipedia:Did you know hooks used in {{DYK talk}} and {{Article history}}.
Usage
This module can be used from templates or from other Lua modules.
From templates
From templates, call the isValidHook function, and use the |hook= parameter to specify the hook.
{{#invoke:Check DYK hook|isValidHook|hook=hook}}
Valid hooks will return a value of "yes"; invalid hooks will return the empty string.
You can also use the first positional parameter to specify the hook. If you do this, it is recommended to use |1= explicitly; if not, and the hook contains an equals sign, the text before the equals sign will be treated as a parameter name and the hook will not be recognised.
From modules
From modules, call the _isValidHook function with the hook as the first positional parameter.
mCheckDYKHook = require('Module:Check DYK hook')
result = mCheckDYKHook._isValidHook(hook)
Valid hooks will return true; invalid hooks will return false.
-- This module performs validation checks for [[WP:DYK]] hooks
local libraryUtil = require('libraryUtil')
local p = {}
local validationPatternGroups = {
{
-- Check that hooks start with three periods, followed by an acceptable
-- follow-on word.
"^%.%.%. *that",
"^%.%.%. *about",
},
{
-- Check that hooks end with a question mark, or another acceptable
-- phrase.
[[.%?%]*'*"?$]],
[[.?</span>%]*'*"?$]],
"[Yy]ou probably did%.+$",
}
}
function p._isValidHook(hook)
-- Whether the given hook is valid.
-- We use the patterns in the validationPatternGroups table to find whether
-- a hook is valid or not. Hooks are treated as valid if they match at least
-- one pattern from each group.
libraryUtil.checkType("_isValidHook", 1, hook, "string")
for _, patternGroup in ipairs(validationPatternGroups) do
local found = false
for _, pattern in ipairs(patternGroup) do
if mw.ustring.find(hook, pattern) then
found = true
break
end
end
if not found then
return false
end
end
return true
end
function p.isValidHook(frame)
local args = frame.args
local hook = args.hook or args[1]
if not hook then
error("No hook specified")
end
hook = hook:match('^%s*(.-)%s*$') -- Trim whitespace
if p._isValidHook(hook) then
return "yes"
else
return ""
end
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.