jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[cleanup]] deprecate BasePage.userName() and BasePage(isIpEdit)

BasePage.userName() is too similar with User.username and can easily
replaced by latest_revision.user.

BasePage.isIpEdit() can easily be replaced by latest_revision.anon.

BasePage.editTime() is already deprecated and can be replaced by
latest_revision.timestamp.

Update scripts and tests

Change-Id: Ib0ec97de6b166668d92b0c2dd7bb29479d342a9b
---
M pywikibot/page/_basepage.py
M scripts/clean_sandbox.py
M scripts/noreferences.py
M tests/page_tests.py
4 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index 596bacc..aba8ab5 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -743,12 +743,24 @@
includecomments=includecomments)
return self._expanded_text

+ @deprecated('latest_revision.user', since='9.3.0')
def userName(self) -> str:
- """Return name or IP address of last user to edit page."""
+ """Return name or IP address of last user to edit page.
+
+ .. deprecated:: 9.3
+ Use :attr:`latest_revision.user<latest_revision>`
+ instead.
+ """
return self.latest_revision.user # type: ignore[attr-defined]

+ @deprecated('latest_revision.anon', since='9.3.0')
def isIpEdit(self) -> bool:
- """Return True if last editor was unregistered."""
+ """Return True if last editor was unregistered.
+
+ .. deprecated:: 9.3
+ Use :attr:`latest_revision.anon<latest_revision>`
+ instead.
+ """
return self.latest_revision.anon # type: ignore[attr-defined]

@cached
diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py
index 6b450cb..44fb69d 100755
--- a/scripts/clean_sandbox.py
+++ b/scripts/clean_sandbox.py
@@ -248,12 +248,14 @@
else:
translated_msg = i18n.twtranslate(
self.site, 'clean_sandbox-cleaned')
+
subst = 'subst:' in self.translated_content
pos = text.find(self.translated_content.strip())
+ latest_user = sandbox_page.latest_revision.user
if text.strip() == self.translated_content.strip():
pywikibot.info(
'The sandbox is still clean, no change necessary.')
- elif subst and sandbox_page.userName() == self.site.user():
+ elif subst and latest_user == self.site.user():
pywikibot.info(
'The sandbox might be clean, no change necessary.')
elif pos != 0 and not subst:
diff --git a/scripts/noreferences.py b/scripts/noreferences.py
index 5ad450b..a13a1dc 100755
--- a/scripts/noreferences.py
+++ b/scripts/noreferences.py
@@ -775,7 +775,7 @@
if super().skip_page(page):
return True

- if self.site.sitename == 'wikipedia:en' and page.isIpEdit():
+ if self.site.sitename == 'wikipedia:en' and page.latest_revision.anon:
pywikibot.warning(
f'Page {page} is edited by IP. Possible vandalized')
return True
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 0df6d1a..c4bcd8c 100755
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -464,15 +464,20 @@
# we only check that the returned objects are of correct type.
self.assertIsInstance(mainpage.get(), str)
self.assertIsInstance(mainpage.latest_revision_id, int)
- self.assertIsInstance(mainpage.userName(), str)
- self.assertIsInstance(mainpage.isIpEdit(), bool)
+
+ with suppress_warnings(
+ r'pywikibot\.page\._basepage.BasePage\.\w+ is deprecated since '
+ r'release [89]\.[03]\.0; use latest_revision\..+ instead\.',
+ FutureWarning):
+ self.assertIsInstance(mainpage.userName(), str)
+ self.assertIsInstance(mainpage.isIpEdit(), bool)
+ self.assertIsInstance(mainpage.editTime(), pywikibot.Timestamp)
+
self.assertIsInstance(mainpage.exists(), bool)
self.assertIsInstance(mainpage.isRedirectPage(), bool)
self.assertIsInstance(mainpage.isDisambig(), bool)
self.assertIsInstance(mainpage.has_permission(), bool)
self.assertIsInstance(mainpage.botMayEdit(), bool)
- self.assertIsInstance(mainpage.latest_revision.timestamp,
- pywikibot.Timestamp)
self.assertIsInstance(mainpage.permalink(), str)

def test_talk_page(self):

To view, visit change 1054341. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib0ec97de6b166668d92b0c2dd7bb29479d342a9b
Gerrit-Change-Number: 1054341
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <dalangi-ctr@wikimedia.org>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot