Module:Get short description/sandbox
Appearance
From Wikipedia, the free encyclopedia
Not to be confused with Module:GetShortDescription.
Implements {{get short description }}.
The above documentation is transcluded from Module:Get short description/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
require('strict') --[[--------------------------< P A T T E R N S _ T >---------------------------------------------------------- a sequence of patterns to match canonical template name and its redirects by transclusion counts as of 2024年08月15日: 'Short description', -- 6,090,442 (canonical form) 'Short Description', -- 124 'Des', -- 20 'Shortdesc', -- 10 'Short desc', -- 8 'Shortdescription', -- 6 ]] localpatterns_t={ '[Ss]hort [Dd]escription', '[Dd]es', '[Ss]hort *desc', '[Ss]hortdescription', } --[[-----------------------------< G E T C O N T E N T >------------------------------------------------------- fetch the article's raw wikitext ]] localfunctiongetContent(title) localsuccess,titleObj=pcall(mw.title.new,title)-- get a title object for title ifnotsuccessthenreturnnilend-- return nil if sommat went wron returntitleObj:getContent()-- return wikitext else end --[[-----------------------------< M A I N >------------------------------------------------------------------- ]] localfunctionmain(frame,title)-- do we really need <title> here? localtitle=frame.args[1] localwikitext=getContent(title) ifwikitext==nilthenreturn""end-- sommat went wrong, abandon for_,patterninipairs(patterns_t)do-- for each pattern in the sequence of redirect patterns localdescription=wikitext:match('{{%s*'..pattern..'%s*|%s*([^|}]+)%s*');-- try to find a match ifdescriptionthen returndescription;-- found one, stop looking and done end end end --[[-----------------------------< E X P O R T S >------------------------------------------------------------- ]] return{ main=main, }