Skip to content

Fetching templates

William Jacoby edited this page Oct 14, 2026 · 1 revision

Fetching templates

tools/fetch_template.py fetches a template's current text through the MediaWiki API and writes it to templates/ with the header filled in:

python3 tools/fetch_template.py Nowrap "See also"

It fetches from English Wikipedia unless --site names another Wikimedia wiki: mediawiki (MediaWiki.org), meta (Meta-Wiki) or commons (Wikimedia Commons), all CC BY-SA 4.0. Before fetching it reads the wiki's licence from its API, and it stops if that isn't CC BY-SA.

python3 tools/fetch_template.py --site mediawiki Note

It records the exact revision copied, and removes the source's page-only part (its documentation and categories: what is outside <onlyinclude>, or inside <noinclude>), since the header takes its place. It leaves Changes: TODO for you to fill in, and adds a Needs adapting: line when the text uses something the wiki can't run:

  • Lua (#invoke);
  • TemplateStyles;
  • the Translate extension's <translate> markup;
  • HTML other than tables, which the wiki shows as text;
  • a parser function or magic word the wiki doesn't have.

It also lists the other templates each one calls, and which of them aren't in the repository yet.

  • Redirects: a name that's only a redirect on the wiki, such as Smaller (to Small), isn't fetched; the tool says where it points, so the real template is fetched under its own name.
  • Known templates: a template already in the record at its latest revision isn't downloaded again. --force fetches it anyway, and also replaces a file that's already in templates/; without it, an existing file is never replaced.
  • --dry-run only reports, writing no files and changing no record.

Then adapt the template by hand: rewrite any Lua part in plain wiki text, and write down what you changed. --help lists every option.

Clone this wiki locally