手册:Pywikibot/touch.py

From mediawiki.org
This page is a translated version of the page Manual:Pywikibot/touch.py and the translation is 5% complete.

touch.py is a Pywikibot script used to go over multiple pages of a wiki, and edit them without changes.

This is for example used to get category links in templates working.

When a page needs to be changed in order to refresh all kinds of relations, touch.py can do the work. This script updates a record without making any changes. Technically, what it does is take each page and save it, without making any changes (null edit), thus refreshing the relations with categories and other relations. This usually doesn’t appear in the page history, however in rare cases it may result in a page history entry (usually due to misbehaving extensions, or when the previous editor managed to leave something in the page which is Pre-save transformed in the bot’s edit).

Scenario 1

When a category is added to a much used template, running touch.py will add the existing pages to the category.

Parameters

Basically touch.py understands the same like replace.py as well as the general parameters .


可用的生成器和过滤器

生成器选项
参数 描述
-cat 工作于指定分类中的所有页面。 参数也可提供为“-cat:分类名”或“-cat:分类名|起始索引”(也可使用 # 而非 |,以下同)
-catr 类似 -cat,同时递归包含指定分类的子分类、子子分类...中的页面。参数也可提供为“-catr:分类名”或“-catr:分类名|起始标题”。
-subcats 工作于指定分类的所有子分类。 参数也可提供为“-subcats:分类名”或“-subcats:分类名|起始标题”。
-subcatsr 类似 -subcats,但包括子子分类等。参数也可提供为“-subcatsr:分类名”或“-subcatsr:分类名|起始标题”。
-uncat 工作于所有未分类的页面。
-uncatcat 工作于所有未分类的分类。
-uncatfiles 工作于所有未分类的文件。
-file 从指定名称的文本文件读取要处理的页面列表。文件中的页面标题可以有方括号包裹(例如 [[Page]]),或用新行分隔。也支持用参数提供为“-file:文件名”。
-filelinks 工作于使用了指定图像/媒体文件的所有页面。 也可用参数提供为“-filelinks:文件名”。
-search 工作于在MediaWiki搜索结果中找到的所有页面,适用于所有名字空间
-logevents 工作于在指定的“特殊:日志”中找到的条目。 此值可以是以下值的逗号分隔列表:
logevent,username,start,end

或为了向后兼容性:

logevent,username,total

使用空字符串则会使用默认值。可以使用下列参数作为日志事件类别选项,如下:

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

将使用默认页面数 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 2012
某些情况下必须写为 -logevents:"move,Usr,20"
-interwiki 工作于指定页面及其他语言中的等效页面。 这可能用于对抗跨站点垃圾信息发布。注意:这样机器人将会修改若干个 wiki 网站上的页面,这可能缺乏充足测试,故请检查您的编辑!
-links 工作于指定页面所链接的所有页面。 也可用参数提供为“-links:页面标题”。
-liverecentchanges 工作于“最近更改”实时供稿列出的页面。 如果设为 -liverecentchanges:x,将在最后 x 个最近更改上运行。
-imagesused 工作于指定页面包含的所有图像上。 也可用参数提供为“-imagesused:页面标题”。
-newimages 工作于最新上传的图像。 如果提供为 -newimages:x,将在最新上传的 x 个图像上运行。
-newpages 工作于最新创建的页面。 如果提供为 -newpages:x,将在最新创建的 x 个页面上运行。
-recentchanges 工作于最近更改的页面。 如果提供为 -recentchanges:x,将在最近更改的 x 个页面上运行。如果提供为 -recentchanges:offset,duration,将使用“自偏移”(offset)的 x 分钟开始“持续”(duration)y 分钟的时间范围。

例如:
-recentchanges:20 - 提供最近更改的 20 个页面
-recentchanges:120,70 - will give pages with 120 offset minutes and 70 minutes of timespan
-recentchanges:visualeditor,10 - 提供最近更改且标记有“visualeditor”的 10 个页面
-recentchanges:"mobile edit,60,35" - 将检索标有'mobile edit'(移动版编辑)且在指定偏移和持续时间范围内的页面

支持rctags,rctag必须是第一个参数。
-unconnectedpages Work on the most recent unconnected pages to the Wikibase repository. Given as -unconnectedpages:x, will work on the x most recent unconnected pages.
-ref 工作于所有链接到指定页面的页面。 参数可提供为“-ref:引用的页面标题”。
-start 指定机器人应从哪个标题开始按字母顺序遍历 home wiki 的所有页面。 参数可提供为“-start:页面标题”。 也可以包含一个名字空间。 例如“-start:Template:!”将使机器人工作于模板名字空间的所有页面。 默认值为 start:!
-prefixindex Work on pages commencing with a common prefix.
-transcludes Work on all pages that use a certain template. Argument can also be given as "-transcludes:Title".
-unusedfiles 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.
-lonelypages 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.
-unwatched 工作于所有未被任何人监视的条目。 参数可为“-unwatched:n”,n 是最多返回的条目数量。
-property:name 工作于所有具指定属性的页面,来自Special:PagesWithProp。
-usercontribs 工作于指定用户编辑过的所有条目。 (例如:-usercontribs:DumZiBoT)
-weblink 工作于包含指定外部链接的所有条目;可提供为“-weblink:url”
-withoutinterwiki 工作于所有不含跨语言链接的页面。 也可将参数提供为“-withoutinterwiki:n”,n 是要获取的数量。
-mysqlquery 执行一条 Mysql 查询,例如 "SELECT page_namespace, page_title, FROM page WHERE page_namespace = 0",并工作于返回的结果的页面上。另见 手册:Pywikibot/MySQL
-sparql 执行一条SPARQL SELECT查询字符串,包含?item,并工作于返回结果的页面上。
-sparqlendpoint 指定 SPARQL 端点网址(可选) (例如:-sparqlendpoint:http://myserver.com/sparql)
-searchitem 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.
-random 工作于 Special:Random 所返回的随机页面上。 参数可提供为“-random:n”,n 是要返回的页面数量。
-randomredirect 工作于 Special:RandomRedirect 所返回的随机重定向页。 参数可提供为“-randomredirect:n”,n 是返回的页面数量。
-google 工作于 Google 搜索结果中找到的所有页面上。 需要一个 Google Web API 许可密钥。 注意,Google 不再提供许可密钥。 操作指南另见 config.py 中的 google_key。 也可用“-google:搜索字符串”提供参数。
-yahoo 工作于 Yahoo 搜索中找到的所有页面。 依赖于 Python 模块 pYsearch。 操作指南另见 config.py 中的 yahoo_appid。
-page 工作于单个页面。 也可用参数“-page:页面标题”提供,并可多次指定来提供多个页面。
-pageid 工作于单个 pageid。 参数也可提供为“-pageid:pageid1,pageid2,.”或“-pageid:'pageid1|pageid2|..'”,并支持多次指定。
-linter 工作于包含 lint 错误的页面。 所用站点上必须已启用 Linter 扩展。 -linter 会选择所有分类。 -linter:high、-linter:medium 或 -linter:low 根据优先级选择分类。 可用逗号间隔来提供多个分类,如 -linter:cat1,cat2,cat3 添加“/int”标识要开始查询的 Lint ID:例如 -linter:high/10000 -linter:show 只显示可用分类。
过滤器选项
参数 描述
-catfilter 过滤页面生成器的结果,只返回指定分类中的页面。 另见 -cat 生成器的参数格式。
-grep 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.
-grepnot Like -grep, but return the page only if the regular expression does not match.
-intersect 工作于提供的全部生成器的交叉点。
-limit 与其他参数配合使用时,-limit:n 指定了最多处理 n 个页面。
-namespaces
-namespace
-ns
Filter the page generator to only yield pages in the specified namespaces. Separate multiple namespace numbers or names with commas.

Examples:

-ns:0,2,4 -ns:Help,MediaWiki

You may use a preleading "not" to exclude the namespace. Examples:

-ns:not:2,3 -ns:not:Help,File

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.
-onlyif 页面需要包含特定声明,否则不返回数据项。 格式为属性 = 值,限定符 = 值。 可以传递多个(或 none)限定符,以逗号分隔。

例如:
P1=Q2 (属性 P1 必须包含值 Q2)
P3=Q4,P5=Q6,P6=Q7 (property P3 with value Q4 and qualifiers: P5 with value Q6 and P6 with value Q7)

值可以是页面ID,下列格式的坐标: latitude,longitude[,precision] (所有值为十进制表示,年份,或纯字符串。 可以多次提供该参数,仅返回存在所有声明的项目页。 参数也可提供为"-onlyif:expression"。
-onlyifnot 页面必须不含该声明,否则将不返回数据项。 用法和例子见上方 -onlyif
-ql 基于页面质量过滤页面。 仅在 contentmodel 等于“proofread-page”时适用,否则无效果。 有效值是范围 0-4。 可以用逗号分隔多个值。
-subpage -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.
-titleregex 条目标题必须匹配一个正则表达式,否则不返回该页面。 可提供多个 -titleregex:regexpr,匹配任意一个正则表达式的页面将被返回。 正则表达式将不区分大小写,并且.(点)匹配任意字符。
-titleregexnot 类似-titleregex,但仅返回正则表达式不匹配的页面。

Furthermore the parameter purge is supported which applies a purge operation instead of a null edit to the selected files.

The script understands also some additional various command-line arguments:

参数描述
-botflag Force botflag in case of edits with changes
-converttitles (purge argument) Convert titles to other variants if necessary
-forcelinkupdate (purge argument) Update the links tables
-forcerecursivelinkupdate (purge argument) Update the links table, and update the links tables for any page that uses this page as a template
-redirects (purge argument) Automatically resolve redirects

Examples

$ python3 touch.py -start:!
$ python3 touch.py -lang:fr -family:wiktionary -cat:anglais
$ python3 touch.py -lang:fr -family:wiktionary -transcludes:"pron-rég" -purge


可用的全域參數

这些选项将覆盖user-config.py 设置中的配置。

全域选项
参数 描述 配置变量
-dir:路径 从路径给出的目录中读取bot的配置数据,而不是从默认目录中读取。  
-config:file The user config filename. Default is user-config.py. user-config.py
-lang:xx 设置要使用的wiki的语言,覆盖user-config.py中的配置。xx应该是语言代码。 mylang
-family:xyz 设置你想要工作的wiki的系列,例如维基百科,维基词典,维基导游,...... 这将覆盖user-config.py中的配置。 family
-user:xyz 以用户'xyz'而不是默认用户名登录。 usernames
-daemonize:xyz 控制权立即交回终端,标准输出(stdout)和标准错误(stderr)重定向到文件xyz。(仅用于不需要从“标准输入”输入内容的机器人)。  
-help 显示帮助文本。  
-log 启用日志文件,默认文件名“script_name-bot.log”,日志存储在logs子目录中。 log
-log:xyz 启用日志文件,文件名'xyz'。 logfilename
-nolog 禁用日志文件(如果默认启用)。  
-maxlag 设置新的maxlag参数,单位秒。 数据库服务器高压力时机器人编辑的延迟秒数。config.py中设置有默认值。 maxlag
-putthrottle:n
-pt:n
-put_throttle:n
设置机器人在保存页面之间的最小间隔时间(单位:秒)。 put_throttle
-debug:item
-debug
启用日志文件并包括“item”组件的广泛调试数据(如果使用形式二,则包括所有组件)。 debug_log
-verbose
-v
使机器人提供额外的控制台输出内容,这可能对调试有益。 verbose_output
-cosmeticchanges
-cc
切换config.py或user-config.py中的cosmetic_changes设置,使其反转。 其他设置和限制不受影响。 cosmetic_changes
-simulate 禁用对服务器的写入。 适合用于测试和调试新编写的代码(如果设置,不会做任何实际更改,只显示将更改的内容)。 simulate
-<config var>:n 您可以使用所有给定的数字配置变量作为选项,并使用命令行进行修改。