ws.parser_helpers.template_expansion module

class ws.parser_helpers.template_expansion.MagicWords(src_title)

Bases: object

Class for handling MediaWiki magic words.

VARIABLES = {'!', 'ARTICLEPAGENAME', 'ARTICLEPAGENAMEE', 'ARTICLESPACE', 'ARTICLESPACEE', 'BASEPAGENAME', 'BASEPAGENAMEE', 'CASCADINGSOURCES', 'CONTENTLANG', 'CONTENTLANGUAGE', 'CURRENTDAY', 'CURRENTDAY2', 'CURRENTDAYNAME', 'CURRENTDOW', 'CURRENTHOUR', 'CURRENTMONTH', 'CURRENTMONTH1', 'CURRENTMONTHABBREV', 'CURRENTMONTHNAME', 'CURRENTMONTHNAMEGEN', 'CURRENTTIME', 'CURRENTTIMESTAMP', 'CURRENTVERSION', 'CURRENTWEEK', 'CURRENTYEAR', 'DIRECTIONMARK', 'DIRMARK', 'FULLPAGENAME', 'FULLPAGENAMEE', 'LOCALDAY', 'LOCALDAY2', 'LOCALDAYNAME', 'LOCALDOW', 'LOCALHOUR', 'LOCALMONTH', 'LOCALMONTH1', 'LOCALMONTHABBREV', 'LOCALMONTHNAME', 'LOCALMONTHNAMEGEN', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCALWEEK', 'LOCALYEAR', 'NAMESPACE', 'NAMESPACEE', 'NAMESPACENUMBER', 'NUMBEROFACTIVEUSERS', 'NUMBEROFADMINS', 'NUMBEROFARTICLES', 'NUMBEROFEDITS', 'NUMBEROFFILES', 'NUMBEROFPAGES', 'NUMBEROFUSERS', 'NUMBEROFVIEWS', 'PAGEID', 'PAGELANGUAGE', 'PAGENAME', 'PAGENAMEE', 'REVISIONDAY', 'REVISIONDAY2', 'REVISIONID', 'REVISIONMONTH', 'REVISIONMONTH1', 'REVISIONSIZE', 'REVISIONTIMESTAMP', 'REVISIONUSER', 'REVISIONYEAR', 'ROOTPAGENAME', 'ROOTPAGENAMEE', 'SCRIPTPATH', 'SERVER', 'SERVERNAME', 'SITENAME', 'STYLEPATH', 'SUBJECTPAGENAME', 'SUBJECTPAGENAMEE', 'SUBJECTSPACE', 'SUBJECTSPACEE', 'SUBPAGENAME', 'SUBPAGENAMEE', 'TALKPAGENAME', 'TALKPAGENAMEE', 'TALKSPACE', 'TALKSPACEE'}
VARIABLES_COLON = {'ARTICLEPAGENAME', 'ARTICLEPAGENAMEE', 'ARTICLESPACE', 'ARTICLESPACEE', 'BASEPAGENAME', 'BASEPAGENAMEE', 'CASCADINGSOURCES', 'DEFAULTCATEGORYSORT', 'DEFAULTSORT', 'DEFAULTSORTKEY', 'DISPLAYTITLE', 'FULLPAGENAME', 'FULLPAGENAMEE', 'NAMESPACE', 'NAMESPACEE', 'NAMESPACENUMBER', 'NUMBERINGROUP', 'NUMINGROUP', 'PAGEID', 'PAGENAME', 'PAGENAMEE', 'PAGESINCAT', 'PAGESINCATEGORY', 'PAGESINNAMESPACE', 'PAGESINNS', 'PAGESIZE', 'PROTECTIONEXPIRY', 'PROTECTIONLEVEL', 'REVISIONDAY', 'REVISIONDAY2', 'REVISIONID', 'REVISIONMONTH', 'REVISIONMONTH1', 'REVISIONTIMESTAMP', 'REVISIONUSER', 'REVISIONYEAR', 'ROOTPAGENAME', 'ROOTPAGENAMEE', 'SUBJECTPAGENAME', 'SUBJECTPAGENAMEE', 'SUBJECTSPACE', 'SUBJECTSPACEE', 'SUBPAGENAME', 'SUBPAGENAMEE', 'TALKPAGENAME', 'TALKPAGENAMEE', 'TALKSPACE', 'TALKSPACEE'}
PARSER_FUNCTIONS = {'#dateformat', '#expr', '#formatdate', '#if', '#ifeq', '#iferror', '#ifexist', '#ifexpr', '#language', '#rel2abs', '#special', '#switch', '#tag', '#time', '#timel', '#titleparts', 'anchorencode', 'canonicalurl', 'filepath', 'formatnum', 'fullurl', 'gender', 'grammar', 'int', 'lc', 'lcfirst', 'localurl', 'ns', 'nse', 'padleft', 'padright', 'plural', 'uc', 'ucfirst', 'urlencode'}
classmethod is_magic_word(name)
get_replacement(magic)
ws.parser_helpers.template_expansion.prepare_content_for_rendering(wikicode)

Prepare the wikicode of a page for rendering.

I.e. do the same wikicode transformations that MediaWiki does before rendering a page:

  • the partial transclusion tags <noinclude>, <includeonly> and <onlyinclude> are handled so that only content inside the <noinclude> or <onlyinclude> tags remains

Parameters

wikicode – the wikicode of the template

Returns

None, the wikicode is modified in place.

ws.parser_helpers.template_expansion.prepare_template_for_transclusion(wikicode, template)

Prepares the wikicode of a template for transclusion:

  • the partial transclusion tags <noinclude>, <includeonly> and <onlyinclude> are handled

  • template arguments ({{{foo}}} etc.) are substituted with the supplied parameters as specified on the target page

Parameters
  • wikicode – the wikicode of the template

  • template – the template object holding parameters for substitution

Returns

None, the wikicode is modified in place.

ws.parser_helpers.template_expansion.expand_templates(title, wikicode, content_getter_func, *, substitute_magic_words=True)

Recursively expands all templates on a MediaWiki page.

Parameters
  • title (ws.parser_helpers.title.Title) – The title of the page where the templates will be expanded. Used for infinite loop prevention and context (e.g. relative transclusions like {{/foo/bar}}).

  • wikicode – The content of the page where templates should be expanded, as a mwparserfromhell.wikicode.Wikicode object.

  • content_getter_func – A callback function which should return the content of a transcluded page. It is called as content_getter_func(title), where title is the Title object representing the title of the transcluded page. The function should raise ValueError if the requested page does not exist.

  • substitute_magic_words (bool) – Whether to substitute magic words. Note that only a couple of interesting/important cases are actually handled.

Returns

None, the wikicode is modified in place.