Wiki Basics
Wikitext Syntax¶
Wikitext, also known as wikicode, is a lightweight markup language used across Wikimedia projects, including Wikipedia and the German Wiktionary, to format and organize content. Wikitext provides special syntax for adding links, formatting text, creating section headings, and more. A key feature of wikitext is its use of templates, which help standardize and structure the content.
"Wiki contributors" write their entries in wikitext, which is then processed and displayed as a formatted wikipage.
Below, some examples of wikitext syntax, for a more detailed overview of the wikitext syntax here and more examples here.
Examples of wikitext syntax:
- Headings: Created using equal signs (
=
), with the number of equal signs on either side of the heading indicating its level.
Wikitext 1 2= Main Heading = == Subheading ==
- Templates: Defined within double curly braces (
{{ }}
)
Wikitext 1
{{template_name|non-named-parameter|named-param=value}}
- Internal Links: Formatted with double square brackets (
[[ ]]
).- Bold Text: Indicated with triple quotes (
'''bold'''
).- Italics: Indicated with double quotes (
''italics''
).
Although regular expressions can be used to parse wikitext, doing so can be quite challenging. This is especially true because wikitext allows for nested templates and uses quotation marks for both bold and italic text, among other formatting features.
Fortunately, there are some Python packages available for parsing wikitext. For a full list of parsers available in different languages, visit this wiki page.
In this tutorial, we will use the package mwparserfromhell
. You can check out the project site on GitHub here and view its documentation page here.
Although I have not had the chance to use it, another Python wiki parser that may be worth exploring is wikitextparser
.
Wiki Namespaces¶
Wikimedia projects use namespaces to organize and categorize pages based on their purpose, such as main content pages, templates, help pages, and discussion pages.
Below is a list of some important namespaces in the German Wiktionary. For the full list, see here.
ID | Description | Prefix English | Prefix German | Count in Wiktionary |
---|---|---|---|---|
0 | The Main namespace, or default namespace, contains the actual content. - word entries of dictionary section |
- | - | 1,142,612 pages |
108 | For Flexion pages. | Flexion | Flexion | 67,542 |
106 | For List of rhyming words. | Reim | Reim | 48,028 |
10 | For Template/Vorlage pages. | Template | Vorlage | 7,258 |
12 | For Help/Hilfe resources. | Help | Hilfe | 588 |
Namespaces have an ID (such as '0'
, '108'
) and prefixes. The prefixes are part of the page titles and help with navigating the site. The only namespace without a prefix is the main content namespace ('0'
).
For instance, if you are interested in information about the word schön, you can visit the main content page for schön (without a prefix) or its declension table, which can be found under Flexion:schön (with the Flexion prefix).
Wiki Templates¶
Templates (or Vorlage in German) can be thought of as small functions. They have a name, as well as named and unnamed parameters, which are separated by pipes.
The first, second, third, etc., unnamed parameters are assigned the names 1
, 2
, 3
, and so on.
Templates have their own namespace in wiki projects ('10'
), with the prefix Template
in English and Vorlage
in German. This means that if you need to read the documentation for a template in the German Wiktionary, you can simply search for the page titled Vorlage:name_of_template
.
Below are some examples of templates, including the wikicode, their end result on the web page, and their documentation page.
Examples of Templates¶
For instance, the template named Wort der Woche
has two unnamed parameters.
The template Deutsch Adjektiv Übersicht
generates the declension tables for adjectives. In this example, it has three named parameters: Positiv
, Komparativ
, and Superlativ
.
Wikitext | |
---|---|
1 2 3 4 5 |
|
Different word forms rely on different templates to generate the inflection tables. For instance, verbs use the Deutsch Verb Übersicht
template.
Wikitext | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 |
|
Templates can hide large amounts of code behind the scenes; for example, this small template produces a large table.
Wikitext | |
---|---|
1 2 3 4 5 |
|