Images scripts#

checkimages script#

Script to check recently uploaded files

This script checks if a file description is present and if there are other problems in the image’s description.

This script will have to be configured for each language. Please submit translations as addition to the Pywikibot framework.

Everything that needs customisation is indicated by comments.

This script understands the following command-line arguments:

-limit              The number of images to check (default: 80)

-commons            The bot will check if an image on Commons has the same name
                    and if true it reports the image.

-duplicates[:#]     Checking if the image has duplicates (if arg, set how many
                    rollback wait before reporting the image in the report
                    instead of tag the image) default: 1 rollback.

-duplicatesreport   Report the duplicates in a log *AND* put the template in
                    the images.

-maxusernotify      Maximum notifications added to a user talk page in a single
                    check, to avoid email spamming.

-sendemail          Send an email after tagging.

-break              To break the bot after the first check (default: recursive)

-sleep[:#]          Time in seconds between repeat runs (default: 30)

-wait[:#]           Wait x second before check the images (default: 0)

-skip[:#]           The bot skip the first [:#] images (default: 0)

-start[:#]          Use allimages() as generator
                    (it starts already from File:[:#])

-cat[:#]            Use a category as generator

-regex[:#]          Use regex, must be used with -url or -page

-page[:#]           Define the name of the wikipage where are the images

-url[:#]            Define the url where are the images

-nologerror         If given, this option will disable the error that is risen
                    when the log is full.

Instructions for the real-time settings. For every new block you have to add:

<------- ------->

In this way the bot can understand where the block starts in order to take the right parameter.

  • Name= Set the name of the block

  • Find= search this text in the image’s description

  • Findonly= search for exactly this text in the image’s description

  • Summary= That’s the summary that the bot will use when it will notify the

    problem.

  • Head= That’s the incipit that the bot will use for the message.

  • Text= This is the template that the bot will use when it will report the

    image’s problem.

commons_information script#

Insert a language template into the description field

data_ingestion script#

A generic bot to do data ingestion (batch uploading) of photos or other files

In addition it installs related metadata. The uploading is primarily from a url to a wiki-site.

Required configuration files#

  • a ‘Data ingestion’ template on a wiki site that specifies the name of a csv file, and csv configuration values.

  • a csv file that specifies each file to upload, the file’s copy-from URL location, and some metadata.

Required parameters#

The following parameters are required. The ‘csvdir’ and the ‘page:csvFile’ will be joined creating a path to a csv file that should contain specified information about files to upload.

-csvdir

A directory path to csv files

-page

A wiki path to templates. One of the templates at this location must be a ‘Data ingestion’ template with the following parameters.

Required parameters

csvFile

Optional parameters
sourceFormat

options: ‘csv’

sourceFileKey

options: ‘StockNumber’

csvDialect

options: ‘excel’, ‘’

csvDelimiter

options: any delimiter, ‘,’ is most common

csvEncoding

options: ‘utf8’, ‘Windows-1252’

formattingTemplate

titleFormat

Example ‘Data ingestion’ template#

{{Data ingestion
|sourceFormat=csv
|csvFile=csv_ingestion.csv
|sourceFileKey=%(StockNumber)
|csvDialect=
|csvDelimiter=,
|csvEncoding=utf8
|formattingTemplate=Template:Data ingestion test configuration
|titleFormat=%(name)s - %(set)s.%(_ext)s
}}

Csv file#

A full example can be found at tests/data/csv_ingestion.csv The ‘url’ field is the location a file will be copied from.

csv field Headers::

description.en,source,author,license,set,name,url

Usage#

python pwb.py data_ingestion -csvdir:<local_dir/> -page:<cfg_page_on_wiki>

Example

pwb.py data_ingestion -csvdir:"test/data" -page:"User:<Your-Username>/data_ingestion_test_template"

Warning

Put it in one line, otherwise it won’t work correctly.

image script#

This script can be used to change one image to another or remove an image

Syntax:

python pwb.py image image_name [new_image_name]

If only one command-line parameter is provided then that image will be removed; if two are provided, then the first image will be replaced by the second one on all pages.

Command line options:

-summary:  Provide a custom edit summary. If the summary includes spaces,
           surround it with single quotes, such as:
           -summary:'My edit summary'
-always    Don't prompt to make changes, just do them.
-loose     Do loose replacements. This will replace all occurrences of the name
           of the image (and not just explicit image syntax). This should work
           to catch all instances of the image, including where it is used as a
           template parameter or in image galleries. However, it can also make
           more mistakes. This only works with image replacement, not image
           removal.

Examples

The image “FlagrantCopyvio.jpg” is about to be deleted, so let’s first remove it from everything that displays it:

python pwb.py image FlagrantCopyvio.jpg

The image “Flag.svg” has been uploaded, making the old “Flag.jpg” obsolete:

python pwb.py image Flag.jpg Flag.svg

imagetransfer script#

Script to copy images to Wikimedia Commons, or to another wiki

Syntax:

python pwb.py imagetransfer {<pagename>|<generator>} [<options>]

The following parameters are supported:

-interwiki        Look for images in pages found through interwiki links.

-keepname         Keep the filename and do not verify description while
                  replacing

-tolang:x         Copy the image to the wiki in code x

-tofamily:y       Copy the image to a wiki in the family y

-tosite:s         Copy the image to the given site like wikipedia:test

-force_if_shared  Upload the file to the target, even if it exists on that
                  wiki's shared repo

-asynchronous     Upload to stash.

-chunk_size:n     Upload in chunks of n bytes.

-file:z           Upload many files from textfile: [[Image:x]]
                                                   [[Image:y]]

If pagename is an image description page, offers to copy the image to the target site. If it is a normal page, it will offer to copy any of the images used on that page, or if the -interwiki argument is used, any of the images used on a page reachable via interwiki links.

This script supports use of pagegenerators arguments.

nowcommons script#

Script to delete files that are also present on Wikimedia Commons

Do not run this script on Wikimedia Commons itself. It works based on a given array of templates defined below.

Files are downloaded and compared. If the files match, it can be deleted on the source wiki. If multiple versions of the file exist, the script will not delete. If the SHA1 comparison is not equal, the script will not delete.

A sysop rights on the local wiki is required if you want all features of this script to work properly.

This script understands various command-line arguments:

-always         run automatically, do not ask any questions. All files
                that qualify for deletion are deleted. Reduced screen
                output.

-replace        replace links if the files are equal and the file names
                differ

-replacealways  replace links if the files are equal and the file names
                differ without asking for confirmation

-replaceloose   Do loose replacements. This will replace all occurrences
                of the name of the file (and not just explicit file
                syntax).  This should work to catch all instances of the
                file, including where it is used as a template parameter
                or in galleries. However, it can also make more mistakes.

-replaceonly    Use this if you do not have a local sysop rights, but do
                wish to replace links from the NowCommons template.

Example

python pwb.py nowcommons -replaceonly -replaceloose -replacealways -replace

Note

This script is a ConfigParserBot. All options can be set within a settings file which is scripts.ini by default.

unusedfiles script#

This bot appends some text to all unused images and notifies uploaders

Parameters:

-limit          Specify number of pages to work on with "-limit:n" where
                n is the maximum number of articles to work on.
                If not used, all pages are used.
-always         Don't be asked every time.

This script is a ConfigParserBot. The following options can be set within a settings file which is scripts.ini by default::

-nouserwarning  Do not warn uploader about orphaned file.
-filetemplate:  Use a custom template on unused file pages.
-usertemplate:  Use a custom template to warn the uploader.