ws.ArchWiki.header module¶
- ws.ArchWiki.header.get_header_parts(wikicode, magics=None, cats=None, langlinks=None, remove_from_parent=False)¶
According to Help:Style, the layout of the page should be as follows:
Magic words (optional) (includes only {{DISPLAYTITLE:…}} and {{Lowercase title}})
Categories
Interlanguage links (if any)
Article status templates (optional)
Related articles box (optional)
Preface or introduction
Table of contents (automatic)
Article-specific sections
Only 1-3 are safe to be updated automatically. This function will extract the header parts from the wikicode and return them as tuple
(parent, magics, cats, langlinks)
, whereparent
is an instance ofmwparserfromhell.wikicode.Wikicode
containing all extracted elements. It is assumed that all header elements are children of the same parent node, otherwiseHeaderError
is raised.If
remove_from_parent
isTrue
, the extracted header elements are also removed from the parent node andbuild_header()
should be called to insert them back.The parameters
magics
,cats
andlanglinks
can be lists of objects (either string, wikicode or node) to be added to the header if not already present. These deduplication rules are applied:supplied magic words take precedence over those present in wikicode
category links are considered duplicate when they point to the same category (e.g. [[Category:Foo]] is equivalent to [[category:foo]])
interlanguage links are considered duplicate when they have the same language tag (i.e. there can be only one interlanguage link for each language)
The lists of magics and langlinks are sorted, the order of catlinks is preserved.
- ws.ArchWiki.header.build_header(wikicode, parent, magics, cats, langlinks)¶
- ws.ArchWiki.header.fix_header(wikicode)¶