Jump to content

Module:GetShortDescription/doc: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
information for requisition and about objectify_alarm
alter docs inline with alteration of module; now using Module:Arguments (again)
Line 1: Line 1:
{{Module rating|beta}}
{{Module rating|beta}}
{{Lua|Module:Lang}}
{{Lua|Module:Arguments|Module:Lang}}
{{info|This module is required by [[Module:AnnotatedLink]].}}
{{info|This module is required by [[Module:AnnotatedLink]].}}
{{info|This module may, by design, output alarming informational messages under certain circumstances; if these messages are displayed on any page invoking this module directly or via any other module or template using it, the page will be added to [[:Category:Pages displaying alarming messages about Module:GetShortDescription]].}}
{{info|This module may, by design, output alarming informational messages under certain circumstances; if these messages are displayed on any page invoking this module directly or via any other module or template using it, the page will be added to [[:Category:Pages displaying alarming messages about Module:GetShortDescription]].}}
Line 60: Line 60:


local short_description = getShortDescription( {
local short_description = getShortDescription( {
-- required
args = {
-- required
name = 'page name',
name = 'page name',


-- optional
-- optional
prefer = 'explicit' or 'wikidata',
prefer = 'explicit' or 'wikidata',
only = 'explicit' or 'wikidata',
only = 'explicit' or 'wikidata',
fallback = 'fallback',
fallback = 'fallback',
objectify_alarm = true or false,
objectify_alarm = true or false,
lang_no = true or false,
lang_no = true or false,


-- optional {{lang}} options
-- optional {{lang}} options
lang_italic = <yes, no, unset, invert, default>,
lang_italic = <yes, no, unset, invert, default>,
lang_nocat = <yes, y, true, t, on, 1>,
lang_nocat = <yes, y, true, t, on, 1>,
lang_size = <CSS font-size e.g. '1.5em'>,
lang_size = <CSS font-size e.g. '1.5em'>,
lang_cat = <no, n, false, f, off, 0>,
lang_cat = <no, n, false, f, off, 0>,
lang_rtl = <no (default), yes>
lang_rtl = <no (default), yes>
}
} )
} )



Revision as of 03:47, 1 February 2023

Usage

{{#invoke:GetShortDescription|main |name= |only= |prefer= |fallback= |lang_italic= |lang_nocat= |lang_size= |lang_cat= |lang_rtl= |lang_no= }}

name

By providing only the required page name (including namespace), the module will look for an explicit {{short description}} in that page, but if not found, will try to fetch the wikidata description. If neither are found, the result will be an empty string.

If the result is a wikidata description, and it is declared (at the source) as being of a foreign language (i.e. not en), the result will be appropriately formatted by Module:Lang (the module powering {{lang}}), in accordance with MOS:OTHERLANG; see #Foreign language wikidata descriptions (below).

Markup: {{#invoke:GetShortDescription|main |name=Example }}
Result: table

This is equivalent to stating |prefer=explicit; see #prefer (below).

only

Providing a value for |only= will limit the search to being only for the stated description. If no description is found, the result will be an empty string, unless a fallback is provided; see #fallback (below).

explicit

Markup: {{#invoke:GetShortDescription|main |name=Example |only=explicit }}
Result:

wikidata

Markup: {{#invoke:GetShortDescription|main |name=Example |only=wikidata }}
Result: table

prefer

Providing a value for |prefer= will initiate the search for the stated description, but try for the alternative if none is found. If no description is found, the result will be an empty string, unless a fallback is provided; see #fallback (below).

explicit or wikidata

Markup: {{#invoke:GetShortDescription|main |name=Example |prefer=explicit }}
Result: table

wikidata or explicit

Markup: {{#invoke:GetShortDescription|main |name=Example |prefer=wikidata }}
Result: table

fallback

If a value for |fallback= is provided, and no description is found by the expressed route, the result will be the stated fallback.

only or fallback

Markup: {{#invoke:GetShortDescription|main |name=Example |only=explicit |fallback=This is a fallback }}
Result:

prefer or fallback

Markup: {{#invoke:GetShortDescription|main |name=Example |prefer=wikidata |fallback=This is a fallback }}
Result: table

Foreign language wikidata descriptions

Should a wikidata description be retrieved, which is declared (at the source) as being of a foreign language (i.e. not en), per MOS:OTHERLANG, the return will be formatted as appropriate by Module:Lang by default. This may be disabled with |lang_no=yes or adjusted via the parameters for {{lang}}: |lang_italic=, |lang_nocat=, |lang_size=, |lang_cat= and |lang_rtl=; see lang's documentation for details.

Requiring this module

objectify_alarm

For use via other modules; application of this option via template or direct invocation will return "table" instead of the alarming message.

Providing a value for |objectify_alarm= will cause alarming messages (red informational messages) to be returned as tables; this allows for a simple test instead of needing to parse the return value; see below for use case.

local getShortDescription = require( 'Module:GetShortDescription' ).main

local short_description = getShortDescription( {
  -- required
  name = 'page name',

  -- optional
  prefer = 'explicit' or 'wikidata',
  only = 'explicit' or 'wikidata',
  fallback = 'fallback',
  objectify_alarm = true or false,
  lang_no = true or false,

  -- optional {{lang}} options
  lang_italic = <yes, no, unset, invert, default>,
  lang_nocat = <yes, y, true, t, on, 1>,
  lang_size = <CSS font-size e.g. '1.5em'>,
  lang_cat = <no, n, false, f, off, 0>,
  lang_rtl = <no (default), yes>
} )

-- If objectify_alarm was true...
if type( short_description ) == 'table' then
  -- An alarming message has been returned
  return short_description.alarm
end