jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1061154?usp=email )
Change subject: [IMPR] Recover unlink.py
......................................................................
[IMPR] Recover unlink.py
- update and improve restored unlink.py
- update documentation
- update tests after adding unlink messages
Bug: T223826
Change-Id: Id93308289f398e664d6fd777b53b5bcaa1394b6c
---
M docs/scripts/archive.rst
M docs/scripts/unsorted.rst
M docs/scripts_ref/scripts.rst
M pywikibot/i18n.py
M scripts/CHANGELOG.rst
M scripts/README.rst
M scripts/unlink.py
7 files changed, 54 insertions(+), 33 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/scripts/archive.rst b/docs/scripts/archive.rst
index d745d97..ff7adb6 100644
--- a/docs/scripts/archive.rst
+++ b/docs/scripts/archive.rst
@@ -254,12 +254,6 @@
**Nifty script to convert HTML-tables to MediaWiki's own syntax**
-unlink script
-=============
-
-**This bot unlinks a page on every page that links to it**
-
-
wikisourcetext script
=====================
diff --git a/docs/scripts/unsorted.rst b/docs/scripts/unsorted.rst
index a543041..7826315 100644
--- a/docs/scripts/unsorted.rst
+++ b/docs/scripts/unsorted.rst
@@ -84,6 +84,13 @@
:no-members:
:noindex:
+unlink script
+=============
+
+.. automodule:: scripts.unlink
+ :no-members:
+ :noindex:
+
watchlist script
================
diff --git a/docs/scripts_ref/scripts.rst b/docs/scripts_ref/scripts.rst
index 977a844..10397e5 100644
--- a/docs/scripts_ref/scripts.rst
+++ b/docs/scripts_ref/scripts.rst
@@ -259,6 +259,11 @@
.. automodule:: scripts.transwikiimport
+unlink script
+=============
+
+.. automodule:: scripts.unlink
+
unusedfiles script
==================
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 7d1aa55..f3ac0fb 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -876,11 +876,11 @@
>>> from pywikibot import i18n
>>> bundles = sorted(i18n.bundles(stem=True))
>>> len(bundles)
- 38
+ 39
>>> bundles[:4]
['add_text', 'archivebot', 'basic', 'blockpageschecker']
>>> bundles[-5:]
- ['undelete', 'unprotect', 'unusedfiles', 'weblinkchecker', 'welcome']
+ ['unlink', 'unprotect', 'unusedfiles', 'weblinkchecker', 'welcome']
>>> 'pywikibot' in bundles
True
diff --git a/scripts/CHANGELOG.rst b/scripts/CHANGELOG.rst
index 21852ca..6c6f23b 100644
--- a/scripts/CHANGELOG.rst
+++ b/scripts/CHANGELOG.rst
@@ -1,6 +1,15 @@
Scripts Changelog
=================
+9.4.0
+-----
+
+unlink
+^^^^^^
+
+* unlink script was recovered
+
+
9.3.1
-----
diff --git a/scripts/README.rst b/scripts/README.rst
index 3815f29..881889d 100644
--- a/scripts/README.rst
+++ b/scripts/README.rst
@@ -151,6 +151,8 @@
| unusedfiles.py | Bot appends some text to all unused images and
other |
| | text to the respective uploaders.
|
+--------------------------+---------------------------------------------------------+
+| unlink.py | This bot unlinks a page on every page that links
to it. |
++--------------------------+---------------------------------------------------------+
| upload.py | Upload an image to a wiki.
|
+--------------------------+---------------------------------------------------------+
| watchlists.py | Allows access to the account's watchlist.
|
diff --git a/scripts/unlink.py b/scripts/unlink.py
index 0d73d0c..ea8ed3f 100755
--- a/scripts/unlink.py
+++ b/scripts/unlink.py
@@ -1,14 +1,12 @@
-#!/usr/bin/python
-"""
-This bot unlinks a page on every page that links to it.
+#!/usr/bin/env python3
+"""This bot unlinks a page on every page that links to it.
This script understands this command-line argument:
- -namespace:n Number of namespace to process. The parameter can be used
- multiple times. It works in combination with all other
- parameters, except for the -start parameter. If you e.g.
- want to iterate over all user pages starting at User:M, use
- -start:User:M.
+-always Don't prompt you for each replacement.
+
+-namespace:n Number of namespace to process. The parameter can be used
+ multiple times.
Any other parameter will be regarded as the title of the page
that should be unlinked.
@@ -20,12 +18,21 @@
descriptions:
python pwb.py unlink "Foo bar" -namespace:0 -namespace:6
+
+
+.. versionchanged:: 6.0
+ script was archived.
+.. versionchanged:: 7.0
+ script was deleted.
+.. versionchanged:: 9.4
+ script was recovered.
"""
#
-# (C) Pywikibot team, 2007-2020
+# (C) Pywikibot team, 2007-2024
#
# Distributed under the terms of the MIT license.
#
+from __future__ import annotations
import pywikibot
from pywikibot.bot import SingleSiteBot
@@ -38,11 +45,11 @@
summary_key = 'unlink-unlinking'
- def __init__(self, pageToUnlink, **kwargs):
+ def __init__(self, page_title: str, **kwargs):
"""Initialize a UnlinkBot instance with the given page to unlink."""
super().__init__(**kwargs)
- self.pageToUnlink = pageToUnlink
- self.generator = pageToUnlink.getReferences(
+ self.pageToUnlink = pywikibot.Page(self.site, page_title) # noqa: N803
+ self.generator = self.pageToUnlink.getReferences(
namespaces=self.opt.namespaces, content=True)
@property
@@ -55,36 +62,33 @@
self.unlink(self.pageToUnlink)
-def main(*args):
- """
- Process command line arguments and invoke bot.
+def main(*args: str) -> None:
+ """Process command line arguments and invoke bot.
If args is an empty list, sys.argv is used.
- @param args: command line arguments
- @type args: str
+ :param args: command line arguments
"""
# This temporary string is used to read the title
# of the page that should be unlinked.
- page_title = None
+ page_title: str = ''
options = {}
for arg in pywikibot.handle_args(args):
- if arg.startswith('-namespace:'):
- if 'namespaces' not in options:
- options['namespaces'] = []
+ opt, _, value = arg.partition(':')
+ if opt == '-namespace':
+ options.setdefault('namespaces', [])
try:
- options['namespaces'].append(int(arg[11:]))
+ options['namespaces'].append(int(value))
except ValueError:
- options['namespaces'].append(arg[11:])
+ options['namespaces'].append(value)
elif arg == '-always':
options['always'] = True
else:
page_title = arg
if page_title:
- page = pywikibot.Page(pywikibot.Site(), page_title)
- bot = UnlinkBot(page, **options)
+ bot = UnlinkBot(page_title, **options)
bot.run()
else:
pywikibot.bot.suggest_help(missing_parameters=['page title'])
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1061154?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Id93308289f398e664d6fd777b53b5bcaa1394b6c
Gerrit-Change-Number: 1061154
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]