jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/178780 )
Change subject: [IMPR] support inheritance of the __STATICREDIRECT__
......................................................................
[IMPR] support inheritance of the __STATICREDIRECT__
Support inheritance of the __STATICREDIRECT__ magic word via
transclusion. No longer load the whole page text to determine
the result.
Tests added.
API:Pagepropes was introduced with mw 1.17
API:Pageswithprop was introduced with mw 1.21
We can assume that the 'staticredirect' page property is used.
Change-Id: I9609ef6196c0caf0444ce8bd0583f33084213944
---
M pywikibot/page/__init__.py
M tests/page_tests.py
2 files changed, 28 insertions(+), 13 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index cf96533..7c22bef 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -722,20 +722,18 @@
return self.site.page_isredirect(self)
def isStaticRedirect(self, force: bool = False) -> bool:
- """
- Determine whether the page is a static redirect.
+ """Determine whether the page is a static redirect.
A static redirect must be a valid redirect, and contain the magic
word __STATICREDIRECT__.
+ .. versionchanged:: 7.0.0
+ __STATICREDIRECT__ can be transcluded
+
:param force: Bypass local caching
"""
- if self.isRedirectPage():
- static_keys = self.site.getmagicwords('staticredirect')
- text = self.get(get_redirect=True, force=force)
- if static_keys:
- return any(key in text for key in static_keys)
- return False
+ return self.isRedirectPage() \
+ and 'staticredirect' in self.properties(force=force)
def isCategoryRedirect(self) -> bool:
"""Return True if this is a category redirect page, False
otherwise."""
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 9a37684..7723ba1 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -962,14 +962,22 @@
'R2' is a normal page and 'R3' does not exist.
"""
- family = 'wikipedia'
- code = 'en'
+ sites = {
+ 'en': {
+ 'family': 'wikipedia',
+ 'code': 'en',
+ },
+ 'test': {
+ 'family': 'wikipedia',
+ 'code': 'test',
+ },
+ }
cached = True
def testIsRedirect(self):
"""Test ``Page.isRedirectPage()`` and
``Page.getRedirectTarget``."""
- site = self.get_site()
+ site = self.get_site('en')
p1 = pywikibot.Page(site, 'User:Legoktm/R1')
p2 = pywikibot.Page(site, 'User:Legoktm/R2')
self.assertTrue(p1.isRedirectPage())
@@ -977,9 +985,18 @@
self.assertEqual(p3, p2)
self.assertIsInstance(p3, pywikibot.User)
+ def testIsStaticRedirect(self):
+ """Test ``Page.isStaticRedirect()``."""
+ site = self.get_site('test')
+ page = pywikibot.Page(site, 'Static Redirect')
+ self.assertTrue(page.isRedirectPage())
+ self.assertTrue(page.isStaticRedirect())
+ self.assertIn('staticredirect', page.properties())
+ self.assertIn('__STATICREDIRECT__', page.text)
+
def testPageGet(self):
"""Test ``Page.get()`` on different types of
pages."""
- site = self.get_site()
+ site = self.get_site('en')
p1 = pywikibot.Page(site, 'User:Legoktm/R2')
p2 = pywikibot.Page(site, 'User:Legoktm/R1')
p3 = pywikibot.Page(site, 'User:Legoktm/R3')
@@ -1000,7 +1017,7 @@
def test_set_redirect_target(self):
"""Test set_redirect_target method."""
# R1 redirects to R2 and R3 doesn't exist.
- site = self.get_site()
+ site = self.get_site('en')
p1 = pywikibot.Page(site, 'User:Legoktm/R2')
p2 = pywikibot.Page(site, 'User:Legoktm/R1')
p3 = pywikibot.Page(site, 'User:Legoktm/R3')
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/178780
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I9609ef6196c0caf0444ce8bd0583f33084213944
Gerrit-Change-Number: 178780
Gerrit-PatchSet: 5
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)disroot.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)disroot.org>
Gerrit-Reviewer: Rubin <rubin.happy(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Meno25 <meno25mail(a)gmail.com>
Gerrit-MessageType: merged