Pywikibot/template.py

From Wikibooks, open books for an open world
Jump to: navigation, search
Bug blank.svg
Git repository of Wikimedia has this file:

This pywikibot script replaces a template with another, and converts the old MediaWiki boilerplate format to the new template format.

Usage[edit]

Syntax: python template.py [-remove] [xml[:filename]] "oldTemplate" ["newTemplate"]
Example: python template.py "Cities in Washington" "Cities in Washington State"

Specify the template on the command line. The program will pick up the template page, and look for all pages using it. It will then automatically loop over them, and replace the template.

Command line options[edit]

  • -remove: Remove every occurence of the template from every article
  • -subst: Resolves the template by putting its text directly into the article. This is done by changing {{...}} or {{msg:...}} into {{subst:...}}
  • -xml: retrieve information from a local dump (http://download.wikimedia.org). if this argument isn't given, info will be loaded from the maintenance page of the live wiki. argument can also be given as "-xml:filename.xml".
  • -namespace: Only process templates in the given namespace number (may be used multiple times).
  • -summary: Lets you pick a custom edit summary. Use quotes if edit summary contains spaces.
  • -always: Don't bother asking to confirm any of the changes, Just Do It.
  • -category: Appends the given category to every page that is edited. This is useful when a category is being broken out from a template parameter or when templates are being upmerged but more information must be preserved.
  • oldTemplate: old template name
  • newTemplate: new template name. If only one argument is given, the bot resolves the template by putting its text directly into the article. This is done by changing {{...}} or {{msg:...}} into {{subst:...}}. If you want to address a template which has spaces, put quotation marks around it.

Global arguments available for all bots

arg Description Default
-family:xyz Set the family of the wiki you want to work on, e.g. wikipedia, wiktionary, commons, wikitravel, …. This will override the configuration in user-config.py settings. user-config.py parameter: family
-lang:xx Set the language of the wiki you want to work on, overriding the configuration in user-config.py where xx should be the language code[1]. user-config.py parameter: mylang
-log Enable the logfile. Logs will be stored in the logs subdirectory. user-config.py parameter: log ?
-log:xyz Enable the logfile, using xyz as the filename.
-nolog Disable the logfile (if it's enabled by default).
-putthrottle:nn
-pt:nn
Set the minimum time (in seconds) the bot will wait between saving pages. user-config.py parameter: putthrottle ?
-verbose
-v
Make the program output more detailed messages than usual to the standard output about its current work, or progress, while it is proceeding. This may be helpful when debugging or dealing with unusual situations. not selected
  1. Commons uses 'commons' for lang and family; Meta uses 'meta' for both.