Manual:Pywikibot/redirect.py

From MediaWiki.org
Jump to navigation Jump to search
Other languages: English  • français • italiano • 日本語 • русский
Git logo
Wikimedia Git repository has this file: scripts/redirect.py

Script to resolve double redirects, and to delete broken redirects.

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

Syntax:

python pwb.py redirect action [-arguments ...]

where action can be one of these:

action description
double
do
Fix redirects which point to other redirects. Shortcut action command is "do".
broken
br
Tries to fix redirect which point to nowhere by using the last moved target of the destination page. If this fails and the -delete option is set, it either deletes the page or marks it for deletion depending on whether the account has admin rights. It will mark the redirect not for deletion if there is no speedy deletion template available. Shortcut action command is "br".
both Both of the above. Retrieves redirect pages from live wiki, not from a special page.

and arguments can be:

argument description
-xml Retrieve information from a local XML dump (https://download.wikimedia.org). Argument can also be given as "-xml:filename.xml". Cannot be used with -fullscan or -moves.
-fullscan Retrieve redirect pages from live wiki, not from a special page Cannot be used with -xml.
-moves

Use the page move log to find double-redirect candidates. Only works with action "double", does not work with -xml.

NOTE: You may use only one of these options above. If neither of -xml -fullscan -moves is given, info will be loaded from a special page of the live wiki.

-page:title Work on a single page
-namespace:n Namespace to process. Can be given multiple times, for several namespaces. If omitted, only the main (article) namespace is treated.
-offset:n With -moves, the number of hours ago to start scanning moved pages. With -xml, the number of the redirect to restart with (see progress). Otherwise, ignored.
-start:title The starting page title in each namespace. Page need not exist.
-until:title The possible last page title in each namespace. Page needs not exist.
-total:n The maximum count of redirects to work upon. If omitted, there is no limit.
-delete Prompt the user whether broken redirects should be deleted (or marked for deletion if the account has no admin rights) instead of just skipping them.
-sdtemplate:x Add the speedy deletion template string including brackets. This enables overriding the default template via i18n or to enable speedy deletion for projects other than wikipedias.
-always Don't prompt you for each replacement.


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

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

Global options
ParameterDescriptionConfig variable
-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, overriding the configuration in user-config.py. xx should be the language code. mylang
-family:xyz Set the family of the wiki you want to work on, e.g. wikipedia, wiktionary, wikitravel, ... This will override the configuration in user-config.py. family
-user:xyz Log in as user 'xyz' instead of the default username. usernames
-daemonize:xyz Immediately return control to the terminal and redirect stdout and stderr to file xyz. (only use for bots that require no input from stdin).  
-help Show the help text.  
-log Enable the log file, using the default filename 'script_name-bot.log' Logs will be stored in the logs subdirectory. log
-log:xyz Enable the log file, using 'xyz' as the filename. logfilename
-nolog Disable the log file (if it is enabled by default).  
-maxlag Sets a new maxlag parameter to a number of seconds. Defer bot edits during periods of database server lag. Default is set by config.py maxlag
-putthrottle:n
-pt:n
-put_throttle:n
Set the minimum time (in seconds) the bot will wait between saving pages. put_throttle
-debug:item
-debug
Enable the log file and include extensive debugging data for component "item" (for all components if the second form is used). debug_log
-verbose
-v
Have the bot provide additional console output that may be useful in debugging. verbose_output
-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. cosmetic_changes
-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). simulate
-<config var>:n You may use all given numeric config variables as option and modify it with command line.