|Wikimedia Git repository has this file: scripts/category.py
|Scripts per a Pywikibot
Removes or adds categories to pages on a Mediawiki site.
The syntax is:
python pwb.py category action [-option]
where action can be one of the following.
|mass-add a category to a list of pages
|remove category tag from all pages in a category
|move all pages in a category to another category
|tidy up a category by moving its articles into subcategories
|assisted diffusing of large categories
|show a tree of subcategories of a given category
|make a list of all of the articles that are in a category
and option can be one of the following.
|sort persons by their last name
|If a page doesn't exist, do not skip it, create it instead
Only for this action, page generator options are supported.
* -overwrite - This overwrites the current page with the list even if something is already there. * -showimages - This displays images rather than linking them in the list. * -talkpages - This outputs the links to talk pages of the pages to be listified in addition to the pages themselves.
* -nodelsum - This specifies not to use the custom edit summary as the deletion reason. Instead, it uses the default deletion reason for the language, which is "Category was disbanded" in English.
|Creates a nice wikitable on the talk page of target category that contains detailed page history of the source category.
|Don't delete the old category after move
|Don't update the wikibase repository
|If that option is not set, it only moves the talk and main page together.
|Only move the pages/subcategories of a category, if the target page (and talk page, if -allowsplit is not set) doesn't exist.
|Use sortKey of the old category also for the new category.
If not specified, sortKey is removed.
An alternative method to keep sortKey is to use -inplace option.
|Filter the articles in the specified namespaces. Separate multiple namespace numbers or names with commas.
Options for several actions
|reset the database
|The category to move from (for the move option)
Also, the category to remove from in the remove option Also, the category to make a list of in the listify option
See note below table.
|The category to move to (for the move option)
Also, the name of the list to make in the listify option
See note below table.
|Don't prompt to delete emptied categories (do it automatically).
|Pick a custom edit summary for the bot.
|Use this flag to change categories in place rather than rearranging them.
|Recurse through all subcategories of categories.
|While removing pages from a category, keep the subpage links and do not remove them
|Only work on pages whose titles match the given regex (for move and remove actions).
|The max depth limit beyond which no subcategories will be listed.
If the category names have spaces in them you may need to use a special syntax in your shell so that the names aren't treated as separate parameters.
For instance, in BASH, use single quotes, e.g.
For categories containing a colon you must explicitly prepend the namespace prefix
category: or its localized equivalent.
For actions tidy and tree, the bot will store the category structure locally in
This saves time and server load, but if it uses these data later, they may be outdated; use the
-rebuild parameter in this case.
For example, to create a new category from a list of persons, type:
python pwb.py category add -person
and follow the on-screen instructions.
Or to do it all from the command-line, use the following syntax:
python pwb.py category move -from:US -to:"United States"
This will move all pages in the category US to the category United States.
Generators and filters available
|Work on all pages which are in a specific category. Argument can also be given as "-cat:categoryname" or as "-cat:categoryname|fromtitle" (using # instead of | is also allowed in this one and the following)
|Like -cat, but also recursively includes pages in subcategories, sub-subcategories etc. of the given category. Argument can also be given as "-catr:categoryname" or as "-catr:categoryname|fromtitle".
|Work on all subcategories of a specific category. Argument can also be given as "-subcats:categoryname" or as "-subcats:categoryname|fromtitle".
|Like -subcats, but also includes sub-subcategories etc. of the given category. Argument can also be given as "-subcatsr:categoryname" or as "-subcatsr:categoryname|fromtitle".
|Work on all pages which are not categorised.
|Work on all categories which are not categorised.
|Work on all files which are not categorised.
|Read a list of pages to treat from the named text file. Page titles in the file may be either enclosed with brackets (example:
[[Page]]), or be separated by new lines. Argument can also be given as "-file:filename".
|Work on all pages that use a certain image/media file. Argument can also be given as "-filelinks:filename".
|Work on all pages that are found in a MediaWiki search across all namespaces.
|Work on articles that were on a specified Special:Log. The value may be a comma separated list of these values:
or for backward compatibility:
To use the default value, use an empty string. You have options for every type of logs given by the log event parameter which could be one of the following:
spamblacklist, titleblacklist, gblblock, renameuser, globalauth, gblrights, gblrename, abusefilter, massmessage, thanks, usermerge, block, protect, rights, delete, upload, move, import, patrol, merge, suppress, tag, managetags, contentmodel, review, stable, timedmediahandler, newusers
It uses the default number of pages 10.
-logevents:move gives pages from move log (usually redirects) -logevents:delete,,20 gives 20 pages from deletion log -logevents:protect,Usr gives pages from protect by user Usr -logevents:patrol,Usr,20 gives 20 patroled pages by Usr -logevents:upload,,20121231,20100101 gives upload pages in the 2010s, 2011s, and 2012s -logevents:review,,20121231 gives review pages since the beginning till the 31 Dec 2012 -logevents:review,Usr,20121231 gives review pages by user Usr since the beginning till the 31 Dec 2012In some cases it must be given as
|Work on the given page and all equivalent pages in other languages. This can, for example, be used to fight multi-site spamming. Attention: this will cause the bot to modify pages on several wiki sites, this is not well tested, so check your edits!
|Work on all pages that are linked from a certain page. Argument can also be given as "-links:linkingpagetitle".
|Work on pages from the live recent changes feed. If used as -liverecentchanges:x, work on x recent changes.
|Work on all images that contained on a certain page. Can also be given as "-imagesused:linkingpagetitle".
|Work on the most recent new images. If given as -newimages:x, will work on x newest images.
|Work on the most recent new pages. If given as -newpages:x, will work on x newest pages.
|Work on the pages with the most recent changes. If given as
-recentchanges:x, will work on the x most recently changed pages. If given as
-recentchanges:offset,duration it will work on pages changed from 'offset' minutes with 'duration' minutes of timespan.
|Work on the most recent unconnected pages to the Wikibase repository. Given as -unconnectedpages:x, will work on the x most recent unconnected pages.
|Work on all pages that link to a certain page. Argument can also be given as "-ref:referredpagetitle".
|Specifies that the robot should go alphabetically through all pages on the home wiki, starting at the named page. Argument can also be given as "-start:pagetitle". You can also include a namespace. For example, "-start:Template:!" will make the bot work on all pages in the template namespace. default value is start:!
|Work on pages commencing with a common prefix.
|Work on all pages that use a certain template. Argument can also be given as "-transcludes:Title".
|Work on all description pages of images/media files that are not used anywhere. Argument can be given as "-unusedfiles:n" where n is the maximum number of articles to work on.
|Work on all articles that are not linked from any other article. Argument can be given as "-lonelypages:n" where n is the maximum number of articles to work on.
|Work on all articles that are not watched by anyone. Argument can be given as "-unwatched:n" where n is the maximum number of articles to work on.
|Work on all pages with a given property name from Special:PagesWithProp.
|Work on all articles that were edited by a certain user. (Example : -usercontribs:DumZiBoT)
|Work on all articles that contain an external link to a given URL; may be given as "-weblink:url"
|Work on all pages that don't have interlanguage links. Argument can be given as "-withoutinterwiki:n" where n is the total to fetch.
|Takes a Mysql query string like "SELECT page_namespace, page_title, FROM page WHERE page_namespace = 0" and works on the resulting pages. See Manual:Pywikibot/MySQL.
|Takes a SPARQL SELECT query string including ?item and works on the resulting pages.
|Specify SPARQL endpoint URL (optional). (Example : -sparqlendpoint:http://myserver.com/sparql)
|Takes a search string and works on Wikibase pages that contain it. Argument can be given as "-searchitem:text", where text is the string to look for, or "-searchitem:lang:text", where lang is the language to search items in.
|Work on random pages returned by Special:Random. Can also be given as "-random:n" where n is the number of pages to be returned.
|Work on random redirect pages returned by Special:RandomRedirect. Can also be given as "-randomredirect:n" where n is the number of pages to be returned.
|Work on all pages that are found in a Google search. You need a Google Web API license key. Note that Google doesn't give out license keys anymore. See google_key in config.py for instructions. Argument can also be given as "-google:searchstring".
|Work on all pages that are found in a Yahoo search. Depends on python module pYsearch. See yahoo_appid in config.py for instructions.
|Work on a single page. Argument can also be given as "-page:pagetitle", and supplied multiple times for multiple pages.
|Work on a single pageid. Argument can also be given as "-pageid:pageid1,pageid2,." or "-pageid:'pageid1|pageid2|..'" and supplied multiple times for multiple pages.
|Work on pages that contains lint errors. Extension Linter must be available on the site. -linter select all categories. -linter:high, -linter:medium or -linter:low select all categories for that prio. Single categories can be selected with commas as in -linter:cat1,cat2,cat3 Adding '/int' identifies Lint ID to start querying from: e.g. -linter:high/10000 -linter:show just shows available categories.
|Filter the page generator to only yield pages in the specified category. See -cat generator for argument format.
|A regular expression that needs to match the article otherwise the page won't be returned. Multiple -grep:regexpr can be provided and the page will be returned if content is matched by any of the regexpr provided. Case insensitive regular expressions will be used and dot matches any character, including a newline.
|Like -grep, but return the page only if the regular expression does not match.
|Work on the intersection of all the provided generators.
|When used with any other argument -limit:n specifies a set of pages, work on no more than n pages in total.
|Filter the page generator to only yield pages in the specified namespaces. Separate multiple namespace numbers or names with commas.
You may use a preleading "not" to exclude the namespace. Examples:
If used with -newpages/-random/-randomredirect/-linter generators, -namespace/-ns must be provided before -newpages/-random/-randomredirect/-linter. If used with -recentchanges generator, efficiency is improved if -namespace is provided before -recentchanges.If used with -start generator, -namespace/-ns shall contain only one value.
|A claim the page needs to contain, otherwise the item won't be returned. The format is property=value,qualifier=value. Multiple (or none) qualifiers can be passed, separated by commas.
|A claim the page must not contain, otherwise the item won't be returned. For usage and examples, see
|Filter pages based on page quality. This is only applicable if contentmodel equals 'proofread-page', otherwise has no effects. Valid values are in range 0-4. Multiple values can be comma-separated.
|-subpage:n filters pages to only those that have depth n i.e. a depth of 0 filters out all pages that are subpages, and a depth of 1 filters out all pages that are subpages of subpages.
|A regular expression that needs to match the article title otherwise the page won't be returned. Multiple -titleregex:regexpr can be provided and the page will be returned if title is matched by any of the regexpr provided. Case insensitive regular expressions will be used and dot matches any character.
-titleregex, but return the page only if the regular expression does not match.
Nota: Generators and Filters are available for add action only. tidy and listify action only accepts namespace filter
Global arguments available
This page is outdated.
These options will override the configuration in user-config.py settings.
|Read the bot's configuration data from directory given by PATH, instead of from the default directory.
|The user config filename. Default is user-config.py.
|Set the language of the wiki you want to work on, overriding the configuration in user-config.py. xx should be the language code.
|Set the family of the wiki you want to work on, e.g. wikipedia, wiktionary, wikitravel, ... This will override the configuration in user-config.py.
|Log in as user 'xyz' instead of the default username.
|Immediately return control to the terminal and redirect stdout and stderr to file xyz. (only use for bots that require no input from stdin).
|Show the help text.
|Enable the log file, using the default filename 'script_name-bot.log' Logs will be stored in the logs subdirectory.
|Enable the log file, using 'xyz' as the filename.
|Disable the log file (if it is enabled by default).
|Sets a new maxlag parameter to a number of seconds. Defer bot edits during periods of database server lag. Default is set by config.py
|Set the minimum time (in seconds) the bot will wait between saving pages.
|Enable the log file and include extensive debugging data for component "item" (for all components if the second form is used).
|Have the bot provide additional console output that may be useful in debugging.
|Toggles the cosmetic_changes setting made in config.py or user-config.py to its inverse and overrules it. All other settings and restrictions are untouched.
|Disables writing to the server. Useful for testing and debugging of new code (if given, doesn't do any real changes, but only shows what would have been changed).
|You may use all given numeric config variables as option and modify it with command line.