jenkins-bot has submitted this change and it was merged.
Change subject: Introduce set_redirect_target method in Page class
......................................................................
Introduce set_redirect_target method in Page class
It set target of redirect page any given page or page and section.
It also can create the redirect or change an ordinary page to a redirect.
The main reason to do this is that It can be altered to support
set redirect in subclasses like ItemPage or CategoryPage and be used generally.
Added one example in the capitalize_redirects script.
Change-Id: Idbe5a1c3e6bb43afe019823fd5eb120c00d9dbec
---
M pywikibot/page.py
M scripts/capitalize_redirects.py
2 files changed, 59 insertions(+), 7 deletions(-)
Approvals:
XZise: Looks good to me, but someone else must approve
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index ad0a643..abfda80 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1911,6 +1911,63 @@
result.append((pywikibot.Page(link, self.site), positional))
return result
+ def set_redirect_target(self, target_page, create=False, force=False,
+ keep_section=False, **kwargs):
+ """
+ Change the page's text to point to the redirect page.
+
+ @param target_page: target of the redirect, this argument is required.
+ @type target_page: pywikibot.Page or string
+ @param summary: The edit summary which must be set if the page should
+ be saved too. If omitted the page won't be saved.
+ @type summary: string
+ @param create: if true, it creates the redirect even if the page
+ doesn't exist.
+ @type create: bool
+ @param force: if true, it set the redirect target even the page
+ doesn't exist or it's not redirect.
+ @type force: bool
+ @param keep_section: if the old redirect links to a section
+ and the new one doesn't it uses the old redirect's section.
+ @type keep_section: bool
+ @param kwargs: Arguments which are used for saving the page directly
+ afterwards. If none are provided the page isn't saved.
+ """
+ if isinstance(target_page, basestring):
+ target_page = pywikibot.Page(self.site, target_page)
+ elif self.site != target_page.site:
+ raise pywikibot.InterwikiRedirectPage(self, target_page)
+ if not self.exists() and not (create or force):
+ raise pywikibot.NoPage(self)
+ if self.exists() and not self.isRedirectPage() and not force:
+ raise pywikibot.IsNotRedirectPage(self)
+ redirect_regex = self.site.redirectRegex()
+ if self.exists():
+ old_text = self.get(get_redirect=True)
+ else:
+ old_text = u''
+ result = redirect_regex.search(old_text)
+ if result:
+ oldlink = result.group(1)
+ if keep_section and '#' in oldlink and target_page.section() is None:
+ sectionlink = oldlink[oldlink.index('#'):]
+ target_page = pywikibot.Page(
+ self.site,
+ target_page.title() + sectionlink
+ )
+ prefix = self.text[:result.start()]
+ suffix = self.text[result.end():]
+ else:
+ prefix = ''
+ suffix = ''
+
+ target_link = target_page.title(asLink=True, textlink=True,
+ allowInterwiki=False)
+ target_link = '#{0} {1}'.format(self.site.redirect(), target_link)
+ self.text = prefix + target_link + suffix
+ if kwargs:
+ self.save(**kwargs)
+
class FilePage(Page):
diff --git a/scripts/capitalize_redirects.py b/scripts/capitalize_redirects.py
index 05a388e..42fe6c1 100644
--- a/scripts/capitalize_redirects.py
+++ b/scripts/capitalize_redirects.py
@@ -85,13 +85,8 @@
site,
'capitalize_redirects-create-redirect',
{'to': page_t})
- page_cap.text = u"#%s %s" % (site.redirect(),
- self.current_page.title(
- asLink=True, textlink=True))
- try:
- page_cap.save(comment)
- except:
- pywikibot.output(u"An error occurred, skipping...")
+ page_cap.set_redirect_target(self.current_page, create=True,
+ summary=comment)
def main(*args):
--
To view, visit https://gerrit.wikimedia.org/r/185159
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idbe5a1c3e6bb43afe019823fd5eb120c00d9dbec
Gerrit-PatchSet: 12
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Additional failure handling with more precise warning
......................................................................
Additional failure handling with more precise warning
- we can check for 'code' and 'info' in the result['edit'] and
print these two error hints instead of "unknown failure reason"
and its bigger 'warning' content.
This is useful e.g. for abusefilter warnings.
Change-Id: Iccb16b967531e5e8afbee97ef378c1a89bded3d3
---
M pywikibot/site.py
1 file changed, 6 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
Mpaa: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 4a139fa..409426b 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3860,6 +3860,12 @@
return False
elif 'spamblacklist' in result['edit']:
raise SpamfilterError(page, result['edit']['spamblacklist'])
+ elif 'code' in result['edit'] and 'info' in result['edit']:
+ self.unlock_page(page)
+ pywikibot.error(
+ u"editpage: %s\n%s, "
+ % (result['edit']['code'], result['edit']['info']))
+ return False
else:
self.unlock_page(page)
pywikibot.error(u"editpage: unknown failure reason %s"
--
To view, visit https://gerrit.wikimedia.org/r/173785
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iccb16b967531e5e8afbee97ef378c1a89bded3d3
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Remove site.randompages() continuation uniqueness test
......................................................................
Remove site.randompages() continuation uniqueness test
Uniqueness is not guaranteed by the API, and thus should not
be guaranteed on the site api level.
Bug: T84944
Change-Id: I5a9a8c6d056f0d23fa300a8ed462d8673218241d
---
M tests/site_tests.py
1 file changed, 5 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_tests.py b/tests/site_tests.py
index d0f85d5..b4ecfd4 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1323,12 +1323,15 @@
"""Test random methods of a site."""
def test_unlimited_small_step(self):
- """Test site.randompages() without limit."""
+ """Test site.randompages() continuation.
+
+ Note that uniqueness is not guaranteed if multiple requests are
+ performed, so we also don't test this here.
+ """
mysite = self.get_site()
pages = []
for rndpage in mysite.randompages(step=5, total=None):
self.assertIsInstance(rndpage, pywikibot.Page)
- self.assertNotIn(rndpage, pages)
pages.append(rndpage)
if len(pages) == 11:
break
--
To view, visit https://gerrit.wikimedia.org/r/187495
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5a9a8c6d056f0d23fa300a8ed462d8673218241d
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>