ws.ArchWiki.header module

exception ws.ArchWiki.header.HeaderError

Bases: Exception

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:

  1. Magic words (optional) (includes only {{DISPLAYTITLE:…}} and {{Lowercase title}})

  2. Categories

  3. Interlanguage links (if any)

  4. Article status templates (optional)

  5. Related articles box (optional)

  6. Preface or introduction

  7. Table of contents (automatic)

  8. 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), where parent is an instance of mwparserfromhell.wikicode.Wikicode containing all extracted elements. It is assumed that all header elements are children of the same parent node, otherwise HeaderError is raised.

If remove_from_parent is True, the extracted header elements are also removed from the parent node and build_header() should be called to insert them back.

The parameters magics, cats and langlinks 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)