Manual:Pywikibot/redirect.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.

Language: English  • français • italiano • 日本語 • русский
Bug blank.svg
Wikimedia Git repository has this file:
compat: redirect.py

Script which fixes double redirects, and deletes broken redirects.

Requires access to MediaWiki's maintenance pages or to a XML dump file. Delete function requires adminship.

Syntax[edit]

Syntax:

 python redirect.py action [-argument]

where action can be one of these:

  • double - fix redirects which point to other redirects
  • broken - delete redirects where targets don't exist. Requires adminship, otherwise it will paste db-r1 to call a human admin.

and argument (optional) can be:

  • xml:filename.xml - Retrieve information from a local XML dump (https://dumps.wikimedia.org). If this argument isn't given, info will be loaded from a special page of the live wiki. Cannot be used with moves or api.
  • api - Retrieve information using Mediawiki's API. Cannot be used with xml.
  • moves - Instead of using Special:Doubleredirects, use the page move log to find double-redirect candidates (only works with action "double", does not work with -xml)
  • namespace:n - Namespace to process. Works only with an XML dump or API. Can be repeated multiple times.
  • offset:n - With XML number of redirect to restart with (see progress). With -moves, the number of hours ago to start scanning moved page
  • always - Don't prompt you for each replacement.
  • delete - Enables deletion of broken redirects.
  • start:page - with API start page
  • until:page - with API last page
  • number:page - with API number of pages to process

If neither api nor api nor moves are present, information will be loaded using a special page

Example[edit]

This syntax fixes all the double redirects. Since no argument is defined, it uses Special:DoubleRedirects of the live wiki to find double redirects by default. It will ask for confirmation before making changes:

 redirect.py double

This syntax will attempt to resolve all broken redirects by directing them to the page's most recent move destination. If this fails, then the redirects will be deleted or marked for deletion, depending on whether or not the bot is logged in as a sysop. Confirmation will be asked for before each change:

redirect.py broken -delete

Global arguments available for all bots

These options will override the configuration in user-config.py settings.

Name Description Default/config name compat core
-dir:PATH Read the bot's configuration data from directory given by PATH, instead of from the default directory.
-lang:xx Set the language of the wiki you want to work on. xx should be the language code. mylang
-family:xyz Set the family of the wiki you want to work on, e.g. wikipedia, wiktionary, commons, wikitravel, …. family
-user:xyz Log in as user 'xyz' instead of the default username.
-daemonize:xyz Immediately return control to the terminal and redirect stdout and stderr to xyz (only use for bots that require no input from stdin).
-help Show a help text for the invoked script.
-log Enable the logfile. Logs will be stored in the logs subdirectory.
-log:xyz Enable the logfile, using xyz as the filename.
-nolog Disable the logfile (if it's enabled by default).
-maxlag Sets a new maxlag parameter to a number of seconds. Defer bot edits during periods of database server lag. maxlag
-debug:item
-debug
Enable the logfile and include extensive debugging data for component "item" (for all components if the second form is used).
-putthrottle:nn
-pt:nn
Set the minimum time (in seconds) the bot will wait between saving pages. put_throttle
-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
-cosmeticchanges
-cc
Toggles the cosmetic_changes setting made in config.py or user_config.py to its inverse and overrules it. All other settings and restrictions are untouched. not selected
-simulate Disables writing to the server. Useful for testing and debugging of new code (if given, doesn't do any real changes, but only shows what would have been changed).
-<config_var>:n You may use all given numeric config variables as option and modify it with command line.