Module:Page assessment: Difference between revisions
Appearance
Content deleted Content added
fix |
check for redirects |
||
Line 21: | Line 21: | ||
end |
end |
||
--[[ |
|||
Checks if a page is a redirect without using the expensive mw.title.isRedirect |
|||
@param {string} wikitext - page wikitext, from mw.title:getContent() |
|||
@returns {boolean} |
|||
--]] |
|||
function util.isRedirect(wikitext) |
|||
return string.match( |
|||
text, |
|||
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]" |
|||
) and true or false |
|||
end |
|||
--[[ |
--[[ |
||
Creates a pattern for finding the value given to a parameter within any template |
Creates a pattern for finding the value given to a parameter within any template |
||
Line 38: | Line 50: | ||
elseif not subjectWikitext then -- talk page does not exist |
elseif not subjectWikitext then -- talk page does not exist |
||
return "unassessed" |
return "unassessed" |
||
elseif util.isRedirect(subjectWikitext) then |
|||
return "redirect" |
|||
else |
else |
||
local classParam = mw.ustring.match(talkpageWikitext, "{{.-%|%s*class%s*=([^}%|]*)", 0) or "" |
local classParam = mw.ustring.match(talkpageWikitext, "{{.-%|%s*class%s*=([^}%|]*)", 0) or "" |
Revision as of 14:10, 22 December 2020
![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
This module returns a page's assessment (class rating), by:
- Detecting non-existent pages (Needed class); or
- Detecting non-existent talk pages (Unassessed class); or
- Detecting redirects and disambiguation pages (Redirect or Disambig class); or
- Looking at the talk page for the value in the first
|class=
parameter; or - Looking at the namespace of the page
Usage
text
Returns the class as text.
{{#invoke:Page assessment|main|page name}}
- Examples
{{#invoke:Page assessment|main|Wikipedia}}
→ Lua error in package.lua at line 80: module 'Module:No globals' not found.{{#invoke:Page assessment|main|Wiktionary}}
→ Lua error in package.lua at line 80: module 'Module:No globals' not found.{{#invoke:Page assessment|main|Wikt}}
→ Lua error in package.lua at line 80: module 'Module:No globals' not found.
icon
Returns the class as an icon.
{{#invoke:Page assessment|icon|page name}}
- Examples
{{#invoke:Page assessment|icon|Wikipedia}}
→ Lua error in package.lua at line 80: module 'Module:No globals' not found.{{#invoke:Page assessment|icon|Wiktionary}}
→ Lua error in package.lua at line 80: module 'Module:No globals' not found.{{#invoke:Page assessment|icon|Wikt}}
→ Lua error in package.lua at line 80: module 'Module:No globals' not found.
iconLink
Returns the class as an icon and a link to the page.
{{#invoke:Page assessment|iconLink|page name}}
- Examples
{{#invoke:Page assessment|iconLink|Wikipedia}}
→ Lua error in package.lua at line 80: module 'Module:No globals' not found.{{#invoke:Page assessment|iconLink|Wiktionary}}
→ Lua error in package.lua at line 80: module 'Module:No globals' not found.{{#invoke:Page assessment|iconLink|Wikt}}
→ Lua error in package.lua at line 80: module 'Module:No globals' not found.
In other templates
The output can be passed into other templates or modules, for example to generate table cells:
{|class=wikitable ! Class !! Article |- {{class|{{#invoke:Page assessment|main|Wiktionary}}}}<td>[[Wiktionary]]</td> |}
Class | Article |
---|---|
??? | Wiktionary |
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}
local util = {}
--[[
Gets the wikitext of a page and its related talk or subject page (nil if it does
not exist)
@param {string} pageName
@returns {string|nil, string|nil} subject page wikitext, talk page wikitex
]]--
function util.getWikitext(pageName)
local title = mw.title.new(pageName)
if not title then
return nil, nil
end
local subjectTitle = title.subjectPageTitle
local talkpageTitle = title.talkPageTitle
return subjectTitle:getContent(), talkpageTitle:getContent()
end
--[[
Checks if a page is a redirect without using the expensive mw.title.isRedirect
@param {string} wikitext - page wikitext, from mw.title:getContent()
@returns {boolean}
--]]
function util.isRedirect(wikitext)
return string.match(
text,
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]"
) and true or false
end
--[[
Creates a pattern for finding the value given to a parameter within any template
call.
@param {string} param
@returns {string} pattern
]]--
function util.paramValuePattern(param)
return "{{[^}]*|%s*" .. param .. "%s*=([^|{}]+)"
end
function p.class(pageName)
local subjectWikitext, talkpageWikitext = util.getWikitext(pageName)
if not subjectWikitext then -- page does not exist
return "needed"
elseif not subjectWikitext then -- talk page does not exist
return "unassessed"
elseif util.isRedirect(subjectWikitext) then
return "redirect"
else
local classParam = mw.ustring.match(talkpageWikitext, "{{.-%|%s*class%s*=([^}%|]*)", 0) or ""
return mw.text.trim(classParam)
end
end
function p.main(frame)
local args = getArgs(frame, {
parentFirst = true
})
return p.class(args[1])
end
p.util = util
return p