Framawiki has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/398770 )
Change subject: [bugfix] Add protocol in Page.permalink() ...................................................................... [bugfix] Add protocol in Page.permalink() Bug: T182854 Change-Id: I2c0d73274f7490c5afe53101e063e6d136984de5 --- M pywikibot/page.py M tests/page_tests.py 2 files changed, 29 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/70/398770/1 diff --git a/pywikibot/page.py b/pywikibot/page.py index d9580b6..54a6c74 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -541,7 +541,7 @@ # TODO: what about redirects, errors? return self._revisions[oldid].text - def permalink(self, oldid=None, percent_encoded=True): + def permalink(self, oldid=None, percent_encoded=True, show_protocol=False): """Return the permalink URL of an old revision of this page. @param oldid: The revid of the revision desired. @@ -551,8 +551,9 @@ title = self.title(asUrl=True) else: title = self.title(asUrl=False).replace(' ', '_') - return "//%s%s/index.php?title=%s&oldid=%s" \ - % (self.site.hostname(), + return "%s//%s%s/index.php?title=%s&oldid=%s" \ + % (self.site.protocol() + ':' if show_protocol else '', + self.site.hostname(), self.site.scriptpath(), title, (oldid if oldid is not None else self.latest_revision_id)) diff --git a/tests/page_tests.py b/tests/page_tests.py index 10aa170..8b9a494 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -1094,6 +1094,31 @@ self.assertEqual(pywikibot.page.html2unicode('py'), 'py') +class TestPermalink(DefaultSiteTestCase): + """ + Test permalink function + """ + + family = 'test' + code = 'test' + + def test_permalink(self): + site = self.get_site() + p1 = pywikibot.Page(site, 'User:Framawiki/pwb_tests/permalink') + self.assertEqual(p1.permalink(), + '//test.wikipedia.org/w/index.php?title=User%3A' + 'Framawiki/pwb_tests/permalink&oldid=340685') + self.assertEqual(p1.permalink(oldid='340684'), + '//test.wikipedia.org/w/index.php?title=User%3A' + 'Framawiki/pwb_tests/permalink&oldid=340684') + self.assertEqual(p1.permalink(percent_encoded=False), + '//test.wikipedia.org/w/index.php?title=User:' + 'Framawiki/pwb_tests/permalink&oldid=340685') + self.assertEqual(p1.permalink(show_protocol=True), + 'https://test.wikipedia.org/w/index.php?title=User%3A' + 'Framawiki/pwb_tests/permalink&oldid=340685') + + if __name__ == '__main__': # pragma: no cover try: unittest.main() -- To view, visit https://gerrit.wikimedia.org/r/398770 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2c0d73274f7490c5afe53101e063e6d136984de5 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Framawiki <framaw...@tools.wmflabs.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits