Pywikibot/replace.py

From Linkwiki
tbd @

Parameters

If the parameter -regex is not included in the command, the bot will do a simple string replacement. Otherwise, it will interpret the search and replace input as regular expressions, which also means that certain characters will need to be escaped (with a \ in front of them).

Basic parameters

Parameter Result
-quiet" There will be no output if a page is not changed.
-pairsfile:"(file)" Odd Lines in (file) will be read as search input, the next even line will be read as corresponding replacement input. This can be used in addition to the pairwise input of the bot command.
-addcat:"(category)" The category (category) will be added to each changed page.
-nocase Search will be case insensitive.
-multiline ^ and $ will match begin and end of a line (otherwise it just matches begin and end of the page).
-recursive Replacement will happen recursively until no longer possible. This might lead to an infinite loop.
-allowoverlap When occurrences of the pattern overlap, replace all of them. This might lead to an infinite loop.
-nopreload Do not preload pages. Useful if disabled on a wiki.
-fullsummary Use one large summary for all command line replacements.
-sleep:(number) If using -fix, multiple regex can be checked at the same time. This parameter slows down processing in order to lighten the load on the CPU.
-fix:(identifier) Perform replacement tasks defined inside the files fixes.py and user-fixes.py (in the folder core/pywikibot). Refer to the table below.
Fixes possible with -fix
  • HTML: Convert HTML tags to wiki syntax, and fix XHTML.
  • isbn: Fix badly formatted ISBNs.
  • syntax: Try to fix bad wiki markup. Do not run this in automatic mode.
  • syntax-safe: Like syntax, but less risky, so you can run this in automatic mode.
  • case-de: fix upper/lower case errors in German
  • grammar-de: fix grammar and typography in German
  • vonbis: Ersetze Binde-/Gedankenstrich durch "bis" (German)
  • music: Links auf Begriffsklärungen (German)
  • datum: specific date formats in German
  • correct-ar: Typo corrections for Arabic Wikipedia and any Arabic wiki.
  • yu-tld: Fix links to .yu domains because it is disabled, see: https://lists.wikimedia.org/pipermail/wikibots-l/2009-February/000290.html
  • fckeditor: Try to convert FCKeditor HTML tags to wiki syntax.

Regex mode

Notes
  • characters which need to be escaped (with \):. ^ $ * + ? { } [ ] \ | ( )
  • A linebreak is written as \n.
  • " needs to be escaped (\") inside the string if the string is enclosed by them.
  • If content is grouped in the search string (()), the content can be included in the replace string by calling the number of the group after an \ (for example \1).
Parameter Result
-regex (search) and (replace) will be interpreted as regex
-dotall . when used in a regex will also match a line break (otherwise it just matches every character except a line break).

Page list generators

These parameters control which pages are chosen to be worked on during the run.

Parameter Result
-page:"(page)" Work on (page).
-pageid:(number) Work on the page with the pageid (number). Multiple pageids can be provided, seperated by ,.
-start:"(page)" Work on all pages in alphabetical order, beginning with (page). Default is -start:!.
-file:"(file)" Work on all pages listed in (file); page titles can be given in linked format ([[(title)]]), or separated by new lines.
-linter Work on all pages that contain lint errors (Extension:Linter). It is possible to select a smaller set by priority (-linter:high, -linter:medium, -linter:low) or by error category (-linter:cat1,cat2,cat3). See Special:LintErrors for a list of the error categories, or use -linter:show.
-cat:"(category)" Work on all non-category pages in (category); do not work on category pages.
-catr:"(category)" Work on all non-category pages in (category), and recursively on all non-category pages in all subcategories of (category); do not work on category pages.
-subcats:"(category)" Work on all non-category category pages in (category); do not work on non-category pages.
-subcatsr:"(category)" Work on all category pages in (category), and recursively on all category pages in all subcategories of (category); do not work on non-category pages.
-ref:"(page)" Work on all pages linking to (page); basically the list generated by Special:WhatLinksHere, thus works with template transclusions too.
-transcludes:"(template)" Work on all pages which transclude (template).
-links:"(page)" Work on all pages which are linked from (page); this is most useful when using a test page to generate a list of linked pages to be worked on.
-prefixindex:"(string)" Work on all pages with titles beginning with (string); basically the list generated by Special:PrefixIndex.
-weblink:"(URL)" Work on all pages that contain an external link to (URL).
-filelinks:"(wiki media file)" Work on all pages that link to a certain uploaded media file.
-imagesused:"(page)" Work on all images that are contained on (page).
-search:"(string)" Work on pages found by a MediaWiki search for (string) across all namespaces.
-usercontribs:"(user)" Work on all pages that were edited by (user).
-property:"(property)" Work on all pages that have (property); see Special:PagesWithProp.
-lonelypages Work on Special:LonelyPages.
-newimages Work on Special:NewFiles.
-newpages Work on Special:NewPages.
-random:(number) Work on (number) pages provided by Special:Random.
-randomredirect:(number) Work on (number) pages provided by Special:RandomRedirect.
-recentchanges Work on pages listed on Special:RecentChanges. Can be filtered by Special:Tags; example: -recentchanges:visualeditor.
-uncat Work on Special:UncategorizedPages.
-uncatcat Work on Special:UncategorizedCategories.
-uncatfiles Work on Special:UncategorizedFiles.
-unusedfiles Work on Special:UnusedFiles.
-wantedpages Work on Special:WantedPages.
-wantedcategories Work on Special:WantedCategories.
-wantedfiles Work on Special:WantedFiles.
-wantedtemplates Work on Special:WantedTemplates.
-querypage:"(name)" Work on page list generated by the special page (name). -querypage shows all possible special pages. For Wiki Aventurica, refer to the table below.
Special pages possible with -querypage at Wiki Aventurica

Filtering

It is possible to filter the chosen pages and only work on those that pass the filter.

Parameter Result
-limit:(number) Only work on (number) pages.
-namespaces:(number)
-namespace:(number)
-ns:(number)
Only work on pages in the (number) namespace. Multiple namespaces can be given by separating them with , (for example -ns:0,2,4), except if also using -start. Namespaces can also be given by prefix (for example -ns:Help,MediaWiki). This parameter should be used before page list generators.
-namespaces:not:(number)
-namespace:not:(number)
-ns:not:(number)
Do not work on pages in the (number) namespace. Multiple namespaces can be given by separating them with , (for example -ns:not:0,2,4), except if also using -start. Namespaces can also be given by prefix (for example -ns:not:Help,MediaWiki). This parameter should be used before page list generators.
-excepttitle:(string) Do not work on pages with titles that contain (string). If -regex is used, (string) will be interpreted as a regular expression.
-requiretitle:(string) Only work on pages with titles that contain (string). If -regex is used, (string) will be interpreted as a regular expression.
-excepttext:(string) Do not work on pages that contain (string). If -regex is used, (string) will be interpreted as a regular expression.
-exceptinside:(string) Do not change occurences of the search expression which lie within (string). If -regex is used, (string) will be interpreted as a regular expression.
-exceptinsidetag:(tag) Do not change occurences of the search expression which lie within (tag). Refer to the table below.
-intersect Only work on pages that are in the intersection of the used page generators (otherwise the union will be used).
-redirect Only work on redirects. -redirect:false will only work on pages.
-catfilter:"(category)" Only work on pages that are also in (category).
-grep:"(regex)" Only work on pages that have content which matches (regex); the regex will be case insensitive and . matches any character.
-grepnot:"(regex)" Only work on pages that do not have content which matches (regex); the regex will be case insensitive and . matches any character.
-titleregex:"(regex)" Only work on pages that have a title which matches (regex); the regex will be case insensitive and . matches any character.
-titleregexnot:"(regex)" Only work on pages that do not have a title which matches (regex); the regex will be case insensitive and . matches any character.
-subpage:(number) Only work on pages that are on maximum subpage level (number). 0 filters out all subpages.
tags possible with -exceptinsidetag
  • category: within category links
  • comment: between <!-- and -->
  • file: within file links
  • gallery: between <gallery> and </gallery>
  • hyperlink: within external links
  • includeonly: between <includeonly> and </includeonly>
  • interwiki: within interwiki-links
  • link: within internal wikilinks, including interwiki, categories, and images
  • math: between <math> and </math>
  • noinclude: between <noinclude> and </noinclude>
  • nowiki: between <nowiki> and </nowiki>
  • pre: between <pre> and </pre>
  • startcolon: lines that start with a colon
  • startspace: lines that start with a space
  • syntaxhighlight: between <syntaxhighlight> and </syntaxhighlight>
  • template: between {{ and }}
  • timeline: between <timeline> and </timeline>