Manual:Pywikipediabot/template.py

From MediaWiki.org
Jump to: navigation, search
Wikimedia-logo-meta.png

This page was moved from MetaWiki.
It probably requires cleanup – please feel free to help out. In addition, some links on the page may be red; respective pages might be found at Meta. Remove this template once cleanup is complete.

Bug blank.svg
Subversion repository of Wikimedia has this file:
Pwb icon.svg
Pywikipediabot
scripts
Quick overview
Quick Start Guide
Installation (Mac)
user_config.py

Wikidata
Non-Wikimedia wikis
Basic use
Scripts
Development
Further help

v  d  e

In other languages: en - ja


This pyWikipedia bot 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.
  • -user: Only edit pages for an user.
  • 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.

Output [edit]

Example of output when running this bot (using windows which does not need "python" typed in):

C:\Users\t\Desktop\pywikipedia> template.py "TOCright" "TOCright test"
Getting references to [[Template:TOCright]] via API...
Getting 3 pages from dead:en...
>>> Talk:Zombrex Posters <<<
- {{TOCright}}
+ {{TOCright test}}
Do you want to accept these changes? ([y]es, [N]o, [e]dit, open in [b]rowser, [a]ll, [q]uit) n
0 pages were changed.