Auxiliary scripts#

clean_sandbox script#

This bot resets a (user) sandbox with predefined text

This script understands the following command-line arguments:

This script supports use of pagegenerators arguments.

Furthermore, the following command line parameters are supported:

-hours

(float) Use this parameter if to make the script repeat itself after the given hours. Hours can be defined as a decimal. 0.01 hours are 36 seconds; 0.1 are 6 minutes.

-delay

(int) Use this parameter for a wait time after the last edit was made. If no parameter is given it takes it from hours and limits it between 5 and 15 minutes. The minimum delay time is 5 minutes.

-text

(str) The text that substitutes in the sandbox, you can use this when you haven’t configured clean_sandbox for your wiki.

-textfile

(str) As an alternative to -text, you can use this to provide a file containing the text to be used.

-summary

(str) Summary of the edit made by the bot. Overrides the default from i18n.

This script is a ConfigParserBot. All local parameters can be given inside a scripts.ini file. Options passed to the script are priorized over options read from ini file.

For example:

[clean_sandbox]
# the parameter section for clean_sandbox script
summary = Bot: Cleaning sandbox
text = {{subst:Clean Sandbox}}
hours: 0.5
delay: 7

cosmetic_changes script#

This module can do slight modifications to tidy a wiki page’s source code

The changes are not supposed to change the look of the rendered wiki page.

The following parameters are supported:

-always

Don’t prompt you for each replacement. Warning (see below) has not to be confirmed. ATTENTION: Use this with care!

-async

Put page on queue to be saved to wiki asynchronously.

-summary:XYZ

Set the summary message text for the edit to XYZ, bypassing the predefined message texts with original and replacements inserted.

-ignore:

Ignores if an error occurred and either skips the page or only that method. It can be set to: all - does not ignore errors match - ignores ISBN related errors (default) method - ignores fixing method errors page - ignores page related errors

The following generators and filters are supported:

This script supports use of pagegenerators arguments.

ATTENTION: You can run this script as a stand-alone for testing purposes. However, the changes that are made are only minor, and other users might get angry if you fill the version histories and watchlists with such irrelevant changes. Some wikis prohibit stand-alone running.

For further information see pywikibot/cosmetic_changes.py

transferbot script#

This script transfers pages from a source wiki to a target wiki

It also copies edit history to a subpage.

The following parameters are supported:

-tolang:

The target site code.

-tofamily:

The target site family.

-prefix:

Page prefix on the new site.

-overwrite:

Existing pages are skipped by default. Use this option to overwrite pages.

-target

Use page generator of the target site

Warning

Internal links are not repaired!

Pages to work on can be specified using any of:

This script supports use of pagegenerators arguments.

Examples

Transfer all pages in category “Query service” from the English Wikipedia to the Arabic Wiktionary, adding “Wiktionary:Import enwp/” as prefix:

python pwb.py transferbot -family:wikipedia -lang:en -cat:”Query service” -tofamily:wiktionary -tolang:ar -prefix:”Wiktionary:Import enwp/”

Copy the template “Query service” from the English Wikipedia to the Arabic Wiktionary:

python pwb.py transferbot -family:wikipedia -lang:en -tofamily:wiktionary -tolang:ar -page:”Template:Query service”

Copy 10 wanted templates of German Wikipedia from English Wikipedia to German:

python pwb.py transferbot -family:wikipedia -lang:en -tolang:de -wantedtemplates:10 -target

transwikiimport script#

This script transfers pages from a source wiki to a target wiki

It uses API:Import and it is also able to copy the full edit history.

The following parameters are supported:

-interwikisource:

The interwiki code of the source wiki.

-fullhistory:

Include all versions of the page.

-includealltemplates:

All templates and transcluded pages will be copied (dangerous).

-assignknownusers:

If user exists on target wiki, assign the editions to them

-correspondingnamespace: The number of the corresponding namespace.

-rootpage:

Import as subpages of …

-summary:

Log entry import summary.

-tags:

Change tags to apply to the entry in the import log and to the null revision on the imported pages.

-overwrite:

Existing pages are skipped by default. Use this option to overwrite pages.

-target

Use page generator of the target site This also affects the correspondingnamespace.

Warning

Internal links are not repaired!

Pages to work on can be specified using any of:

This script supports use of pagegenerators arguments.

Examples

Transfer all pages in category “Query service” from the English Wikipedia to the home Wikipedia, adding “Wikipedia:Import enwp/” as prefix:

python pwb.py transwikiimport -interwikisource:en -cat:”Query service” -prefix:”Wikipedia:Import enwp/” -fullhistory -assignknownusers

Copy the template “Query service” from the English Wikipedia to the home Wiktionary:

python pwb.py transferbot -interwikisource:w:en -page:”Template:Query service” -fullhistory -assignknownusers

Copy 10 wanted templates of the home Wikipedia from English Wikipedia to the home Wikipedia:

python pwb.py transferbot -interwikisource:en -wantedtemplates:10 -target -fullhistory -assignknownusers

Advices

The module gives access to all parameters of the API (and special page) and is compatible to the scripts.transferbot script. However for most scenarios the parameters -overwrite, -target and -includealltemplates should be avoided; by default they are set to False.

The correspondingnamespace is used only if the namespaces on both wikis do not correspond one with another.

Correspondingnamespace and rootpage are mutually exclusive.

Target and rootpage are mutually exclusive. (This combination does not seem to be feasible.)

If the target page already exists, the target page will be overwritten if -overwrite is set or skipped otherwise.

The list of pages to be imported can be generated outside of the pywikbot:

for i in {1..10} ; do python3 pwb.py transwikiimport -interwikisource:mul -page:”Page:How to become famous.djvu/$i” -fullhistory -assignknownusers ; done

The pages *``Page:How to become famous.djvu/1``, ``Page:How to become famous.djvu/2`` .. ``Page:How to become famous.djvu/10`` will be copied from wikisource (mul) to the home-wikisource, all versions will be imported and the usernames will be identified (existing pages will be skipped).*

Or generated using the usual pywikibot generators:

python3 pwb.py transwikiimport -interwikisource:mul -prefixindex:”Page:How to become famous.djvu” -fullhistory -assignknownusers -summary:”Book copied from oldwiki.”

All pages like *``Page:How to become famous.djvu``… will be copied from wikisource (mul) to the home-wikisource, all versions will be imported and the usernames will be identified (existing pages will be skipped).*

The global option -simulate disables the import and the bot prints the names of the pages that would be imported. Since the import of pages is a quite exceptionell process and potentially dangerous it should be made carefully and tested in advance.

The -simulate option can help to find out which pages would be moved and what would be the target of the import. However it does not print the titles of the transcluded pages (e.g. templates) if -includealltemplates is set.

This option is quite dangerous. If the title of an existing page on home wiki clashes with the title of one of the linked pages it would be overritten. The histories would be merged. (If the imported version is newer.) Even if -overwrite is not set the linked page can be overwritten.

Hints

The list of wikis that can be used as a interwiki source is defined in the variable $wgImportSources. It can be viewed on the Special:Import page.

Rights

For transwikiimport script and even to access the Special:Import page the appropriate flag on the account must be set, usually administrator, transwiki importer or importer.

Added in version 8.2.