Module:GetShortDescription/doc: Difference between revisions

Content deleted Content added
remove requirement for Module:Transcluder
No edit summary
 
(27 intermediate revisions by 3 users not shown)
Line 1:
{{distinguish|Module:Get short description}}
{{Module rating|beta}}<!-- may need to be semiprotected -->
{{Lua|Module:Arguments rating|protected}}
{{Uses WikidataHigh-use}}
{{Lua|Module:Arguments|Module:Lang}}
{{info|This module is required by [[Module:Annotated link]].}}
{{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]].}}
 
== Usage ==
<code><nowiki>{{#invoke:GetShortDescription|main |name= |only= |prefer= |fallback= |lang_italic= |lang_nocat= |lang_size= |lang_cat= |lang_rtl= |lang_no= }}</nowiki></code>
=== Namename ===
By providing only the '''required''' page name (including namespace), the module will look for an explicit {{tlx|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 non-Englishof a foreign language (i.e. not ''en''), the result will be wrappedappropriately informatted by [[Module:Lang]] (the module powering {{tlx|lang}}), byin defaultaccordance with [[MOS:OTHERLANG]]; see [[#Non-EnglishForeign language wikidata descriptions]] (below).
:'''Markup:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Wikipedia}}</nowiki></code>
:'''Result:''' {{#invoke:GetShortDescription|main|name=Wikipedia}}
This is equivalent to stating {{para|prefer|explicit}}; see [[#prefer]] (below).
 
=== only ===
This is equivalent to stating {{para|prefer|explicit}}; see [[#Prefer]] (below).
Providing a value for {{para|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 ====
'''Code:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Example }}</nowiki></code>
:'''Markup:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Wikipedia |only=explicit }}</nowiki></code>
:'''Result:''' {{#invoke:GetShortDescription|main|name=Wikipedia|only=explicit}}
 
==== wikidata ====
'''Result:''' {{#invoke:GetShortDescription|main|name=Example}}
:'''Markup:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Wikipedia |only=wikidata }}</nowiki></code>
:'''Result:''' {{#invoke:GetShortDescription|main|name=Wikipedia|only=wikidata}}
 
=== Onlyprefer ===
StatingProviding a value for {{para|onlyprefer}} will limitinitiate the search tofor beingthe onlystated description, but try for the statedalternative descriptionif none is found. If no description is found, the result will be an empty string, unless a fallback is provided; see [[#Fallbackfallback]] (below).
==== Explicit or nothing ====
'''Code:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Example |only=explicit }}</nowiki></code>
 
==== explicit or wikidata ====
'''Result:''' {{#invoke:GetShortDescription|main|name=Example|only=explicit}}
:'''Markup:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Wikipedia |prefer=explicit }}</nowiki></code>
:'''Result:''' {{#invoke:GetShortDescription|main|name=Wikipedia |prefer=explicit}}
 
==== Wikidatawikidata or nothingexplicit ====
:'''CodeMarkup:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=ExampleWikipedia |onlyprefer=wikidata }}</nowiki></code>
:'''Result:''' {{#invoke:GetShortDescription|main|name=Wikipedia |prefer=wikidata}}
 
=== fallback ===
'''Result:''' {{#invoke:GetShortDescription|main|name=Example|only=wikidata}}
If a value for {{para|fallback}} is provided, and no description is found by the expressed route, the result will be the stated fallback.
 
==== Preferonly or fallback ====
:'''Markup:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Example |only=explicit |fallback=This is a fallback }}</nowiki></code>
Stating {{para|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).
:'''Result:''' {{#invoke:GetShortDescription|main|name=Example|only=explicit|fallback=This is a fallback}}
==== Explicit or wikidata or nothing ====
'''Code:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Example |prefer=explicit }}</nowiki></code>
 
==== prefer or fallback ====
'''Result:''' {{#invoke:GetShortDescription|main|name=Example|prefer=explicit}}
:'''Markup:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Example |prefer=wikidata |fallback=This is a fallback }}</nowiki></code>
:'''Result:''' {{#invoke:GetShortDescription|main|name=Example|prefer=wikidata|fallback=This is a fallback}}
 
=== Foreign language wikidata descriptions ===
==== Wikidata or explicit or nothing ====
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 {{para|lang_no|yes}} or adjusted via the parameters for {{tlc|lang}}: {{para|lang_italic}}, {{para|lang_nocat}}, {{para|lang_size}}, {{para|lang_cat}} and {{para|lang_rtl}}; see [[Template:Lang/doc|lang's documentation]] for details.
'''Code:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Example |prefer=wikidata }}</nowiki></code>
 
== Requiring this module ==
'''Result:''' {{#invoke:GetShortDescription|main|name=Example|prefer=wikidata}}
=== Instances when a table is returned ===
Providing a value for {{para|objectify_alarm}} will cause alarming messages (red informational messages) to be returned as [[mw:Extension:Scribunto/Lua reference manual#table|tables]].
 
Providing a value for {{para|report_redlinks}} will cause the return of a report instead of nothing in the event that the page named is nonexistent (i.e. a [[WP:REDLINK]]) and a search for a {{tlc|short description}} template is processed.
=== Fallback ===
If a {{para|fallback}} is provided, and no description is found by the expressed route, the result will be the stated fallback.
==== Only or fallback ====
'''Code:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Example |only=explicit |fallback=This is a fallback }}</nowiki></code>
 
A table will also be returned in the event that the module is instructed to {{para|prefer|explicit}} (its default), and returns a Wikidata description. If the reason for there being no explicit short description is because it was set to ''[[WP:SDNONE|none]]''; the table will include a value for <code>table.none</code>
'''Result:''' {{#invoke:GetShortDescription|main|name=Example|only=explicit|fallback=This is a fallback}}
 
See below for examples of these behaviors:
==== Prefer or fallback ====
'''Code:''' <code><nowiki>{{#invoke:GetShortDescription|main |name=Example |prefer=wikidata |fallback=This is a fallback }}</nowiki></code>
 
<syntaxhighlight lang="lua">local getShortDescription = require( 'Module:GetShortDescription' ).main
'''Result:''' {{#invoke:GetShortDescription|main|name=Example|prefer=wikidata|fallback=This is a fallback}}
 
local short_description = getShortDescription( {
=== Non-English wikidata descriptions ===
-- required
Should a wikidata description be retrieved, which is declared (at the source) as being non-English (en), the return will be wrapped in {{tlx|lang}} by default; this may be disabled with {{para|lang_no|yes}}.
name = 'page name',
 
-- optional
The parameters for {{tlc|lang}} may be provided via: {{para|lang_italic}}, {{para|lang_nocat}}, {{para|lang_size}}, {{para|lang_cat}} and {{para|lang_rtl}}; see [[Template:Lang/doc|lang's documentation]] for details.
prefer = 'explicit' or 'wikidata',
only = 'explicit' or 'wikidata',
fallback = 'fallback',
 
objectify_alarm = true,
<includeonly>{{Sandbox other||
report_redlinks = true,
<!-- Categories below this line; interwikis at Wikidata -->
 
lang_no = 'yes',
 
-- {{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 we've requested to report_redlinks or to objectify_alarm then
if type( short_description ) == 'table' then
if short_description.alarm then
-- An alarming message has been returned
local alarming_message = short_description.alarm
elseif short_description.redlink then
-- Do something about that
elseif short_description.wikidata then
-- A Wikidata description was returned without being explicitly requested
local wikidata_description = short_description.wikidata
if short_description.none then
-- Because the explicit short desc was 'none'
end
end
end</syntaxhighlight>
 
<includeonly>{{Sandbox other||
[[Category:Modules using data from Wikidata]]
[[Category:Short description related modules]]
}}</includeonly>
 
<noinclude>
[[Category:Module documentation pages]]
</noinclude>