Zum Inhalt springen

Wikipedia:Lua/Modul/PageUtil/en

aus AufEinWort, der freien Forschung
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 19. September 2025 um 07:50 Uhr durch Nikolaos (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „{{LuaModuleDoc}} <onlyinclude>'''<code>PageUtil</code>''' – Module with functions for entire wiki pages. == {{Anker|template}} Functions for templates == ; getCategories {{Anker|getCategories}} : Which categories apply to this page? : ''Parameter (optional):'' :; 1 :: Page name :: ''Default:'' Current page : Result is a list of category titles separated by <code>|</code> :* „{{#invoke:PageUtil|getCategories}}“ ; getContentModel {{Anker|getContentM…“). Sie kann sich erheblich von der aktuellen Version unterscheiden.
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Vorlagenprogrammierung Diskussionen Lua Unterseiten
Modul Deutsch English

Modul: Dokumentation
Weiterleitung der Diskussionsseite fehlt

PageUtil – Module with functions for entire wiki pages.

Functions for templates

getCategories
Which categories apply to this page?
Parameter (optional):
1
Page name
Default: Current page
Result is a list of category titles separated by |
  • „Wikipedia:Lua/Modul/Dokumentation|•Lua|•Modul|•en|•PageUtil|AufEinWort:Obereinordnung fehlt|AufEinWort:Untereinordnung fehlt|AufEinWort:Ordnung fehlt|AufEinWort:Einordnung fehlt“
getContentModel
Parameter (optional):
1
Page name
Default: Current page
Result is content model of this page
getProtection
Is this page protected?
Parameters (all optional):
1
Page name
Default: Current page
2
action
Default: edit
Others: move / create / upload
Result is one of: empty, ½, ¾, 1
isRedirect
Is this a redirect page?
Result is empty, if transcluded in regular page; on redirect page a non-empty string
merge
Merge pages.
Result is a string concatenating particular content without line breaks.
Up to 200 pages and sections might be transcluded.
Parameters (all optional):
1
First text element.
One of following formats:
  1. [[ page name ]]
    Transclude entire page.
    Links on this page will be replaced by internal links.
  2. #lst: [[ page name ]] mark
    #lstx: [[ page name ]] mark
    Transclude section of a page.
    Since it is unknown which fragments could be accessed, for this page no inner links will be modified.
  3. Other arbitrary text.
    Line breaks can be created safely by the following syntax:
| <nowiki />
=== Conclusion ===
<nowiki />
2 3 4 5 6 7 8 9 …
More text elements, any number.
The text elements will be transcluded in numerical sequence of parameter name.
failsafe

The Failsafe interface is heading for version management of globally distributed Lua modules. It enables modules equipped with this interface to

  • ensure, that a library module required by a template or another module available as local copy does support certain functionality, or complain if not.
  • administrate global updating and linking of module codes via Wikidata.

The Failsafe interface is present both at template level and for direct Lua access.

The functions in detail are (not all supported yet completely by every library):

Parameter
Value Result current
nothing
false
local version ID »2025-01-01«
Minimal version version ID required at least
date in ISO format

It will be compared whether the current local implementation matches this version or later.

  • empty, if minimal version not achieved
  • 2001-01-01 → »2025-01-01«
  • 2099-01-01 → »«
wikidata version ID of global upstream
  • version ID at Wikidata
  • local, if not found there
»2025-01-01«
item ID of the Wikidata item
  • empty if not defined
Q89064539
~ Corresponding version ID locally and registered at Wikidata
  • empty, if up to date
  • version ID at Wikidata, if not equal
»2025-01-01«
@ Is the current (module) page linked correctly with Wikidata item?
  • empty, if linked to the item which is supposed
  • Iitem ID, if not
The return value is in template programming empty or under Lua false, otherwis a non-empty string as described.

Functions for Lua modules (API)

Some functions described above can be used by other modules per require():

local lucky, PageUtil = pcall( require, "Module:PageUtil" )
if type( PageUtil ) == "table" then
 PageUtil = PageUtil()
else
 -- error case; PageUtil contains message
 return "<span class=\"error\">" .. PageUtil .. "</span>"
end

Subsequently there are available:

PageUtil.getProtection( source, stage )
  • source – (optional) string or mw.title for that page
  • stage – (optional) string with action
Returns number, one of: 0, 0.5, 0.75, 1
PageUtil.merge( args, frame )
  • args – table with parameters like for templates
  • frame – object or nil
PageUtil.failsafe( since )

Directly available are:

mw.title.getCurrentTitle().categories
mw.title.getCurrentTitle().contentModel
mw.title.getCurrentTitle().isRedirect

Usage

General library; no limitations.

Dependencies

None.