jenkins-bot has submitted this change and it was merged.

Change subject: plugin: get redirects leading to a given page
......................................................................


plugin: get redirects leading to a given page

Change-Id: I3a74f6e910e3c011d3dc9011946b653077ae14eb
Signed-off-by: Loic Dachary <l...@dachary.org>
---
M FLOSSbot/plugin.py
M tests/test_plugin.py
2 files changed, 15 insertions(+), 0 deletions(-)

Approvals:
  Dachary: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/FLOSSbot/plugin.py b/FLOSSbot/plugin.py
index 3ce2474..a0d309a 100644
--- a/FLOSSbot/plugin.py
+++ b/FLOSSbot/plugin.py
@@ -277,6 +277,15 @@
             log.debug("GET failed with " + str(e))
             return None
 
+    def get_redirects(self, title, lang):
+        log.debug("get_redirects " + title + " " + lang)
+        site = pywikibot.site.APISite.fromDBName(lang + 'wiki')
+        p = pywikibot.Page(site, title)
+        return [r.title() for r in p.getReferences(follow_redirects=False,
+                                                   withTemplateInclusion=False,
+                                                   redirectsOnly=True,
+                                                   total=5000)]
+
     def get_sitelink_item(self, dbname):
         if dbname not in self.dbname2item:
             query = """
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index f4cb5b5..8a8b367 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -151,6 +151,12 @@
         found = plugin.search_entity(plugin.bot.site, name, type='item')
         assert found.getID() == second.getID()
 
+    def test_get_redirects(self):
+        bot = Bot.factory(['--verbose'])
+        plugin = Plugin(bot, bot.args)
+        titles = plugin.get_redirects('GNU General Public License', 'en')
+        assert 'GPL' in titles
+
     def test_get_sitelink_item(self):
         bot = Bot.factory(['--verbose'])
         plugin = Plugin(bot, bot.args)

-- 
To view, visit https://gerrit.wikimedia.org/r/316055
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3a74f6e910e3c011d3dc9011946b653077ae14eb
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/bots/FLOSSbot
Gerrit-Branch: master
Gerrit-Owner: Dachary <l...@dachary.org>
Gerrit-Reviewer: Dachary <l...@dachary.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to