Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage  



1.1  From templates  





1.2  From modules  
















Module:Check DYK hook






Slovenščina
 

Edit links
 









Module
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 





Permanently protected module

From Wikipedia, the free encyclopedia
 


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.
  [[.%?%]*'*"?$]],
  [[.&#63;</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

Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Check_DYK_hook&oldid=991316958"

Hidden category: 
Wikipedia template-protected modules
 



This page was last edited on 29 November 2020, at 12:31 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki