Unsorted scripts#
basic script#
An incomplete sample script
This is not a complete bot; rather, it is a template from which simple bots can be made. You can rename it to mybot.py, then edit it in whatever way you want.
Use global -simulate
option for test purposes.
No changes to live wiki will be done.
The following parameters are supported:
- -always
The bot won’t ask for confirmation when putting a page
- -text:
Use this text to be added; otherwise ‘Test’ is used
- -replace:
Don’t add text but replace it
- -top
Place additional text on top of the page
- -summary:
Set the action summary message for the edit.
This sample script is a ConfigParserBot
.
All settings can be made either by giving option with the command line
or with a settings file which is scripts.ini by default. If you don’t
want the default values you can add any option you want to change to
that settings file below the [basic] section like:
[basic] ; inline comments starts with colon
# This is a commend line. Assignments may be done with '=' or ':'
text: A text with line break and
continuing on next line to be put
replace: yes ; yes/no, on/off, true/false and 1/0 is also valid
summary = Bot: My first test edit with pywikibot
Every script has its own section with the script name as header.
In addition the following generators and filters are supported but cannot be set by settings file:
This script supports use of pagegenerators
arguments.
change_pagelang script#
This script changes the content language of pages
These command line parameters can be used to specify which pages to work on:
This script supports use of pagegenerators
arguments.
Furthermore, the following command line parameters are supported:
- -setlang
What language the pages should be set to
- -always
If a language is already set for a page, always change it to the one set in -setlang.
- -never
If a language is already set for a page, never change it to the one set in -setlang (keep the current language).
Note
This script is a
ConfigParserBot
. All options can be set
within a settings file which is scripts.ini by default.
Added in version 5.1.
coordinate_import script#
Coordinate importing script
Usage:
python pwb.py coordinate_import -site:wikipedia:en -cat:Category:Coordinates_not_on_Wikidata
This will work on all pages in the category “coordinates not on Wikidata” and will import the coordinates on these pages to Wikidata.
The data from the “GeoData” extension (https://www.mediawiki.org/wiki/Extension:GeoData) is used so that extension has to be setup properly. You can look at the [[Special:Nearby]] page on your local Wiki to see if it’s populated.
You can use any typical pagegenerator to provide with a list of pages:
python pwb.py coordinate_import -lang:it -family:wikipedia -namespace:0 -transcludes:Infobox_stazione_ferroviaria
You can also run over a set of items on the repo without coordinates and try to import them from any connected page. To do this, you have to explicitly provide the repo as the site using -site argument.
Example
python pwb.py coordinate_import -site:wikidata:wikidata -namespace:0 -querypage:Deadendpages
The following command line parameters are supported:
- -always
If used, the bot won’t ask if it should add the specified text.
- -create
Create items for pages without one.
Note
This script is a ConfigParserBot
.
All options can be set within a settings file which is scripts.ini by
default.
This script supports use of pagegenerators
arguments.
delinker script#
Delink removed files from wiki
This script keeps track of image deletions and delinks removed files from current wiki in namespace 0. This script is suitable to delink files from an image repository as well as for local images.
The following parameters are supported:
- -category:
Retrieve pages to delink from “Pages with missing files” category. Usually the category is found on Q4989282 wikibase item but can be overwritten by giving the category title with that option. -since option is ignored.
- -exclude:
If the deletion log contains this pattern, the file is not delinked (default is ‘no-delink’).
- -localonly
Retrieve deleted File pages from local log only
- -since:
Start the deletion log with this timestamp given in MediaWiki timestamp format. If no
-since
option is given, the start timestamp is read from setting file. If the option is empty, the processing starts from the very beginning. If the script stops, the last timestamp is written to the settings file and the next script call starts there if no-since
is given.
Note
This script is a ConfigParserBot
.
All settings can be made either by giving option with the command
line or with a settings file which is scripts.ini by default. If you
don’t want the default values you can add any option you want to
change to that settings file below the [delinker] section like.
Added in version 7.2: This script is completely rewriten from compat branch.
Changed in version 9.4: -category option was added.
djvutext script#
This bot uploads text from djvu files onto pages in the “Page” namespace
Note
It is intended to be used for Wikisource.
The following parameters are supported:
- -index:
name of the index page (without the Index: prefix)
- -djvu:
path to the djvu file, it shall be: .. hlist:
* path to a file name * dir where a djvu file name as index is located optional, by default is current dir '.'
- -pages:<start>-<end>,...<start>-<end>,<start>-<end>
upload; optional,
start=1
,end=djvu file number of images
. Page ranges can be specified as:A-B -> pages A until B A- -> pages A until number of images A -> just page A -B -> pages 1 until B
This script is a ConfigParserBot
. The
following options can be set within a settings file which is scripts.ini
by default:
- -summary:
(str) Custom edit summary. Use quotes if edit summary contains spaces.
- -force
Overwrites existing text optional, default False.
- -always
Do not bother asking to confirm any of the changes.
download_dump script#
This bot downloads dump from dumps.wikimedia.org
This script supports the following command line parameters:
-filename:# The name of the file (e.g. abstract.xml)
-storepath:# The stored file’s path.
- -dumpdate:# The dumpdate date of the dump (default to
latest
)formatted as YYYYMMDD.
Note
This script is a
ConfigParserBot
. All options can be set
within a settings file which is scripts.ini by default.
Added in version 3.0.20180108.
fixing_redirects script#
Correct all redirect links in featured pages or only one page of each wiki
Can be used with:
- -always
The bot won’t ask for confirmation when putting a page
- -featured
Run over featured pages (for some Wikimedia wikis only)
- -overwrite
Usually only the link is changed ([[Foo]] -> [[Bar|Foo]]). This parameters sets the script to completly overwrite the link text ([[Foo]] -> [[Bar]]).
- -ignoremoves
Do not try to solve deleted pages after page move.
This script supports use of pagegenerators
arguments.
misspelling script#
This script fixes links that contain common spelling mistakes
This is only possible on wikis that have a template for these misspellings.
Command line options:
- -always:XY instead of asking the user what to do, always perform the same
action. For example, XY can be “r0”, “u” or “2”. Be careful with this option, and check the changes made by the bot. Note that some choices for XY don’t make sense and will result in a loop, e.g. “l” or “m”.
- -main
only check pages in the main namespace, not in the Talk, Project, User, etc. namespaces.
- -start:XY goes through all misspellings in the category on your wiki
that is defined (to the bot) as the category containing misspelling pages, starting at XY. If the -start argument is not given, it starts at the beginning.
noreferences script#
This script adds a missing references section to pages
It goes over multiple pages, searches for pages where <references /> is missing although a <ref> tag is present, and in that case adds a new references section.
These command line parameters can be used to specify which pages to work on:
This script supports use of pagegenerators
arguments.
Furthermore, the following command line parameters are supported:
- -xml
Retrieve information from a local XML dump (pages-articles or pages-meta-current, see https://dumps.wikimedia.org). Argument can also be given as “-xml:filename”.
- -always
Don’t prompt you for each replacement.
- -quiet
Use this option to get less output
If neither a page title nor a page generator is given, it takes all pages from the default maintenance category.
It is strongly recommended not to run this script over the entire article namespace (using the -start) parameter, as that would consume too much bandwidth. Instead, use the -xml parameter, or use another way to generate a list of affected articles
parser_function_count script#
Used to find expensive templates that are subject to be converted to Lua
It counts parser functions and then orders templates by number of these and uploads the first n titles or alternatively templates having count()>n.
Parameters:
- -start
Will start from the given title (it does not have to exist). Parameter may be given as “-start” or “-start:title”. Defaults to ‘!’.
- -first
Returns the first n results in decreasing order of number of hits (or without ordering if used with -nosort) Parameter may be given as “-first” or “-first:n”.
- -atleast
Returns templates with at least n hits. Parameter may be given as “-atleast” or “-atleast:n”.
- -nosort
Keeps the original order of templates. Default behaviour is to sort them by decreasing order of count(parserfunctions).
- -save
Saves the results. The file is in the form you may upload it to a wikipage. May be given as “-save:<filename>”. If it exists, titles will be appended.
- -upload
Specify a page in your wiki where results will be uploaded. Parameter may be given as “-upload” or “-upload:title”. Say good-bye to previous content if existed.
Precedence of evaluation: results are first sorted in decreasing order of templates, unless nosort is switched on. Then first n templates are taken if first is specified, and at last atleast is evaluated. If nosort and first are used together, the program will stop at the nth hit without scanning the rest of the template namespace. This may be used to run it in more sessions (continue with -start next time).
First is strict. That means if results #90-120 have the same number of parser functions and you specify -first:100, only the first 100 will be listed (even if atleast is used as well).
Should you specify neither first nor atleast, all templates using parser functions will be listed.
reflinks script#
Fetch and add titles for bare links in references
This bot will search for references which are only made of a link
without title (i.e. <ref>[https://www.google.fr/]</ref>
or
<ref>https://www.google.fr/</ref>
) and will fetch the html title
from the link to use it as the title of the wiki link in the reference,
i.e.
<ref>[https://www.google.fr/search?q=test test - Google Search]</ref>
The bot checks every 20 edits a special stop page. If the page has been edited, it stops.
As it uses it, you need to configure reflinks.py for your wiki, or it will not work.
pdfinfo is needed for parsing pdf titles.
The following parameters are supported:
- -xml:dump.xml
Should be used instead of a simple page fetching method from pagegenerators.py for performance and load issues
- -xmlstart
Page to start with when using an XML dump
This script is a ConfigParserBot
. The
following options can be set within a settings file which is scripts.ini
by default:
- -always
Doesn’t ask every time whether the bot should make the change. Do it always.
- -limit:n
(int) Stops after n edits
- -ignorepdf
Do not handle PDF files (handy if you use Windows and can’t get pdfinfo)
- -summary
(str) Use a custom edit summary. Otherwise it uses the default one from translatewiki
The following generators and filters are supported:
This script supports use of pagegenerators
arguments.
replicate_wiki script#
This bot replicates pages in a wiki to a second wiki within one family
Example:
python pwb.py replicate_wiki [-r] -ns 10 -family:wikipedia -o nl li fy
or:
python pwb.py replicate_wiki [-r] -ns 10 -family:wikipedia -lang:nl li fy
to copy all templates from nlwiki to liwiki and fywiki. It will show which pages have to be changed if -r is not present, and will only actually write pages if -r is present.
You can add replicate_replace to your user config file (user-config.py), which has the following format:
replicate_replace = {
'wikipedia:li': {'Hoofdpagina': 'Veurblaad'}
}
to replace all occurrences of ‘Hoofdpagina’ with ‘Veurblaad’ when writing to liwiki. Note that this does not take the origin wiki into account.
The following parameters are supported:
- -r, --replace
actually replace pages (without this option you will only get an overview page)
- -o, --original
original wiki (you may use -lang:<code> option instead)
- -ns, --namespace
specify namespace
- -dns, --dest-namespace
destination namespace (if different)
destination_wiki destination wiki(s)
unlink script#
This bot unlinks a page on every page that links to it
This script understands this command-line argument:
- -always
Don’t prompt you for each replacement.
- -namespace:n
Number of namespace to process. The parameter can be used multiple times.
Any other parameter will be regarded as the title of the page that should be unlinked.
Example
Removes links to the page [[Foo bar]] in articles and image descriptions:
python pwb.py unlink “Foo bar” -namespace:0 -namespace:6
Changed in version 6.0: script was archived.
Changed in version 7.0: script was deleted.
Changed in version 9.4: script was recovered.
watchlist script#
Allows access to the bot account’s watchlist
The watchlist can be updated manually by running this script.
Syntax:
python pwb.py watchlist [-all | -count | -count:all | -new]
Command line options:
- -all
Reloads watchlists for all wikis where a watchlist is already present.
- -count
Count only the total number of pages on the watchlist of the account the bot has access to.
- -count:all
Count only the total number of pages on all wikis watchlists that the bot is connected to.
- -new
Load watchlists for all wikis where accounts is set in user config file
Changed in version 7.7: watchlist is retrieved in parallel tasks.