jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1167257?usp=email )
Change subject: [bugfix] Ignore SectionError in page_empty_check and count it
as empty
......................................................................
[bugfix] Ignore SectionError in page_empty_check and count it as empty
Also move it to Subject as static method
Bug: T398983
Change-Id: I0b228b3d3c45a10fccb13909e7018ca9f637e05c
---
M scripts/interwiki.py
1 file changed, 31 insertions(+), 24 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index f441e51..abbde43 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -384,6 +384,7 @@
NoPageError,
NoUsernameError,
PageSaveRelatedError,
+ SectionError,
ServerError,
SiteDefinitionError,
SpamblacklistError,
@@ -1129,7 +1130,7 @@
# must be behind the page.isRedirectPage() part
# otherwise a redirect error would be raised
- if page_empty_check(page):
+ if self.page_empty_check(page):
self.conf.remove.append(str(page))
self.conf.note(f'{page} is empty. Skipping.')
if page == self.origin:
@@ -1568,7 +1569,7 @@
pywikibot.info(f'Not editing {page}: page does not exist')
raise SaveError("Page doesn't exist")
- if page_empty_check(page):
+ if self.page_empty_check(page):
pywikibot.info(f'Not editing {page}: page is empty')
raise SaveError('Page is empty.')
@@ -1816,6 +1817,34 @@
pywikibot.warning(f'{page.site.family.name}: {page} links '
f'to incorrect {linkedPage}')
+ @staticmethod
+ def page_empty_check(page: pywikibot.Page) -> bool:
+ """Return True if page should be skipped as it is almost empty.
+
+ Pages in content namespaces are considered empty if they contain
+ fewer than 50 characters, and other pages are considered empty if
+ they are not category pages and contain fewer than 4 characters
+ excluding interlanguage links and categories.
+ """
+ try:
+ txt = page.text
+ except SectionError:
+ # Section doesn't exist — treat page as empty
+ return True
+
+ # Check if the page is in content namespace
+ if page.namespace().content:
+ # Check if the page contains at least 50 characters
+ return len(txt) < 50
+
+ if not page.is_categorypage():
+ site = page.site
+ txt = textlib.removeLanguageLinks(txt, site=site)
+ txt = textlib.removeCategoryLinks(txt, site=site)
+ return len(txt.strip()) < 4
+
+ return False
+
class InterwikiBot:
@@ -2128,28 +2157,6 @@
return True
-def page_empty_check(page) -> bool:
- """Return True if page should be skipped as it is almost empty.
-
- Pages in content namespaces are considered empty if they contain
- less than 50 characters, and other pages are considered empty if
- they are not category pages and contain less than 4 characters
- excluding interlanguage links and categories.
- """
- txt = page.text
- # Check if the page is in content namespace
- if page.namespace().content:
- # Check if the page contains at least 50 characters
- return len(txt) < 50
-
- if not page.is_categorypage():
- txt = textlib.removeLanguageLinks(txt, site=page.site)
- txt = textlib.removeCategoryLinks(txt, site=page.site)
- return len(txt) < 4
-
- return False
-
-
class InterwikiDumps(OptionHandler):
"""Handle interwiki dumps."""
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1167257?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: I0b228b3d3c45a10fccb13909e7018ca9f637e05c
Gerrit-Change-Number: 1167257
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[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]