General pages changes scripts#

archivebot script#

archivebot.py - Discussion page archiving bot

usage:

python pwb.py archivebot [OPTIONS] [TEMPLATE_PAGE]

Multiple TEMPLATE_PAGE templates can be given in a single command. The default is User:MiszaBot/config. The bot examines backlinks (i.e. Special:WhatLinksHere) to all given TEMPLATE_PAGE templates. It then processes those pages (unless a specific page is specified via options) and archives old discussions.

This is done by splitting each page into threads and scanning them for timestamps. Threads older than a configured threshold are moved to an archive page. The archive page name can be based on the thread’s title, or include a counter that increments when the archive reaches a configured size.

The transcluded configuration template may include the following parameters:

{{TEMPLATE_PAGE
|archive =
|algo =
|counter =
|maxarchivesize =
|minthreadsleft =
|minthreadstoarchive =
|archiveheader =
|key =
}}

Parameters meanings:

archive

Name of the archive page where threads will be moved. Must be a subpage of the current page, unless a valid key is provided. Supports variables.

algo

Specifies the maximum age of a thread using the syntax: old(<delay>), where <delay> can be in seconds (s), hours (h), days (d), weeks (w), or years (y). For example: 24h or 5d. Default: old(24h).

counter

The current value of the archive counter used in archive page naming. Will be updated automatically by the bot. Default: 1.

maxarchivesize

The maximum size of an archive page before incrementing the counter. A suffix of K or M may be used for kilobytes or megabytes. Default: 200K.

minthreadsleft

Minimum number of threads that must remain on the main page after archiving. Default: 5.

minthreadstoarchive

Minimum number of threads that must be eligible for archiving before any are moved. Default: 2.

archiveheader

Content placed at the top of each newly created archive page. Supports variables. If not set explicitly, a localized default will be retrieved from Wikidata using known archive header templates. If no localized template is found, the fallback {{talkarchive}} is used.

Note

If no archiveheader is set and no localized template can be retrieved from Wikidata, the fallback {{talkarchive}} is used. This generic fallback may not be appropriate for all wikis, so it is recommended to set archiveheader explicitly in such cases.

key

A secret key that, if valid, allows archive pages to exist outside of the subpage structure of the current page.

Variables below can be used in the value of the “archive” parameter in the template above. Numbers are represented as ASCII digits by default; alternatively, localized digits may be used. Localized digits are only available for a few site languages. Please refer to NON_ASCII_DIGITS to check if a localized version is available.

ascii

localized

Description

%(counter)d

%(localcounter)s

the current value of the counter

%(year)d

%(localyear)s

year of the thread being archived

%(isoyear)d

%(localisoyear)s

ISO year of the thread being archived

%(isoweek)d

%(localisoweek)s

ISO week number of the thread being archived

%(semester)d

%(localsemester)s

semester term of the year of the thread being archived

%(quarter)d

%(localquarter)s

quarter of the year of the thread being archived

%(month)d

%(localmonth)s

month (as a number 1-12) of the thread being archived

%(monthname)s

localized name of the month above

%(monthnameshort)s

first three letters of the name above

%(week)d

%(localweek)s

week number of the thread being archived

The ISO calendar defines the first week of the year as the week containing the first Thursday of the Gregorian calendar year. This means:

  • If January 1st falls on a Monday, Tuesday, Wednesday, or Thursday, then the week containing January 1st is considered the first week of the year.

  • If January 1st falls on a Friday, Saturday, or Sunday, then the first ISO week starts on the following Monday.

Because of this, up to three days at the start of January can belong to the last week of the previous year according to the ISO calendar.

Options (may be omitted):

-help

Show this help message and exit.

-calc:PAGE

Calculate key for PAGE and exit.

-file:FILE

Load list of pages from FILE.

-force

Override security options.

-locale:LOCALE

Switch to locale LOCALE.

-namespace:NS

Only archive pages from the given namespace.

-page:PAGE

Archive a single PAGE. Default namespace is a user talk page.

-salt:SALT

Specify salt.

-keep

Preserve thread order in archive even if threads are archived later.

-sort

Sort archive by timestamp; should not be used with keep.

-async

Run the bot in parallel tasks.

Version historty:

Changed in version 7.6: Localized variables for the archive parameter are supported. User:MiszaBot/config is the default template. The -keep option was added.

Changed in version 7.7: -sort and -async options were added.

Changed in version 8.2: KeyboardInterrupt support added when using the -async option.

Changed in version 10.3: If archiveheader is not set, the bot now attempts to retrieve a localized template from Wikidata (based on known item IDs). If none is found, {{talkarchive}} is used as fallback.

movepages script#

This script can move 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:

-from

The page to move from.

-to

The page to move to.

-noredirect

Leave no redirect behind.

-notalkpage

Do not move this page’s talk page (if it exists)

-nosubpages

Do not move subpages

-prefix

Move pages by adding a namespace prefix to the names of the pages. (Will remove the old namespace prefix if any) Argument can also be given as -prefix:namespace:.

-always

Don’t prompt to make changes, just do them.

-skipredirects

Skip redirect pages (Warning: increases server load)

-summary

(str) Prompt for a custom summary, bypassing the predefined message texts. Argument can also be given as -summary:XYZ.

-pairsfile

Read pairs of file names from a file. The file must be in a format [[frompage]] [[topage]] [[frompage]] [[topage]] … Argument can also be given as -pairsfile:filename

pagefromfile script#

Bot to upload pages from a text file

This bot takes its input from the UTF-8 text file that contains a number of pages to be put on the wiki. The pages should all have the same beginning and ending text (which may not overlap). The beginning and ending text is not uploaded with the page content by default.

As a pagename is by default taken the first text block from the page content marked in bold (wrapped between ‘’’ and ‘’’). If you expect the page title not to be present in the text or marked by different markers, use -titlestart, -titleend, and -notitle parameters.

Specific arguments:

-file:xxx

The filename we are getting our material from, the default value is “dict.txt”

-begin:xxx

The text that marks the beginning of a page, the default value is “{{-start-}}”

-end:xxx

The text that marks the end of the page, the default value is “{{-stop-}}”

-include

Include the beginning and end markers to the page

-textonly

Text is given without markers. Only one page text is given. -begin and -end options are ignored.

-titlestart:xxx

The text used in place of ‘’’ for identifying the beginning of a page title

-titleend:xxx

The text used in place of ‘’’ for identifying the end of the page title

-notitle

Do not include the page title, including titlestart and titleend, to the page. Can be used to specify unique page title above the page content

-title:xxx

The page title is given directly. Ignores -titlestart, -titleend and -notitle options

-nocontent:xxx

If the existing page contains specified statement, the page is skipped from editing

-noredirect

Do not upload on redirect pages

-summary:xxx

The text used as an edit summary for the upload. If the page exists, standard messages for prepending, appending, or replacement are appended after it.

-autosummary

Use MediaWiki’s autosummary when creating a new page, overrides -summary-

-minor

Set the minor edit flag on page edits

-showdiff

Show difference between current page and page to upload, also forces the bot to ask for confirmation on every edit.

If the page to be uploaded already exists, it is skipped by default. But you can override this behavior if you want to:

-appendtop

Add the text to the top of the existing page

-appendbottom

Add the text to the bottom of the existing page

-force

Overwrite the existing page

It is possible to define a separator after the ‘append’ modes which is added between the existing and the new text. For example a parameter -appendtop:foo would add ‘foo’ between them. A new line can be added between them by specifying ‘n’ as a value.

tracking param remover script#

Script to remove tracking URL query parameters from external URLs

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:

-always

Don’t prompt for each removal

Added in version 10.3.