Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/316064

Change subject: [IMPR] Provide recentchanges tag filter
......................................................................

[IMPR] Provide recentchanges tag filter

- Add tag filter to site.recentchanges() method
- Add 'tags' to rcprops
- Add tag filter to pagegenerators.RecentChangesPageGenerator
- Enable tag filtering with pagegenerators -recentchanges option
- Add tests for site and pagegenerators methods

Bug: T147416
Change-Id: Ia636aef46dd36b937a78cb71c9b98819753be2ff
---
M pywikibot/pagegenerators.py
M pywikibot/site.py
M tests/pagegenerators_tests.py
M tests/site_tests.py
4 files changed, 39 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/64/316064/1

diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index e60c98f..94477f1 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -184,7 +184,8 @@
                   given as -recentchanges:x, will work on the x most recently
                   changed pages. If given as -recentchanges:offset,duration it
                   will work on pages changed from 'offset' minutes with
-                  'duration'  minutes of timespan.
+                  'duration'  minutes of timespan. rctags are supported too.
+                  The rctag must be the very first parameter part.
 
                   By default, if no values follow -recentchanges, then we pass
                   -recentchanges:x where x = 60
@@ -192,7 +193,11 @@
                   Examples:
                   -recentchanges:20 gives the 20 most recently changed pages
                   -recentchanges:120,70 will give pages with 120 offset
-                  minutes and 70 minutes of timespan
+                      minutes and 70 minutes of timespan
+                  -recentchanges:visualeditor,10 gives the 20 most recently
+                      changed pages marked with 'visualeditor'
+                  -recentchanges:"mobile edit,60,35" will retrieve pages marked
+                      with 'mobile edit' for the given offset and timespan
 
 -unconnectedpages Work on the most recent unconnected pages to the Wikibase
                   repository. Given as -unconnectedpages:x, will work on the
@@ -694,8 +699,11 @@
         elif arg == '-recentchanges':
             rcstart = None
             rcend = None
+            rctag = None
             total = None
             params = value.split(',') if value else []
+            if params and not params[0].isdigit():
+                rctag = params.pop(0)
             if len(params) == 2:
                 offset = float(params[0])
                 duration = float(params[1])
@@ -704,7 +712,7 @@
             elif len(params) > 2:
                 raise ValueError('More than two parameters passed.')
             else:
-                total = int(value) if value else 60
+                total = int(params[0]) if params else 60
             if len(params) == 2:
                 ts_time = self.site.server_time()
                 rcstart = ts_time + timedelta(minutes=-(offset + duration))
@@ -715,6 +723,7 @@
                                              end=rcend,
                                              site=self.site,
                                              reverse=True,
+                                             tag=rctag,
                                              
_filter_unique=self._filter_unique)
 
         elif arg == '-liverecentchanges':
@@ -1098,7 +1107,7 @@
                                showRedirects=None, showPatrolled=None,
                                topOnly=False, total=None,
                                user=None, excludeuser=None, site=None,
-                               _filter_unique=None):
+                               tag=None, _filter_unique=None):
     """
     Generate pages that are in the recent changes list, including duplicates.
 
@@ -1138,7 +1147,8 @@
     @type excludeuser: basestring|list
     @param site: Site for generator results.
     @type site: L{pywikibot.site.BaseSite}
-
+    @param tag: a recent changes tag
+    @type tag: str
     """
     if site is None:
         site = pywikibot.Site()
@@ -1150,7 +1160,7 @@
                              showRedirects=showRedirects,
                              showPatrolled=showPatrolled,
                              topOnly=topOnly, total=total,
-                             user=user, excludeuser=excludeuser)
+                             user=user, excludeuser=excludeuser, tag=tag)
 
     gen.request['rcprop'] = 'title'
     gen = (pywikibot.Page(site, x['title'])
diff --git a/pywikibot/site.py b/pywikibot/site.py
index f997020..7bc8e0d 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -4463,7 +4463,7 @@
                       namespaces=None, pagelist=None, changetype=None,
                       showMinor=None, showBot=None, showAnon=None,
                       showRedirects=None, showPatrolled=None, topOnly=False,
-                      total=None, user=None, excludeuser=None):
+                      total=None, user=None, excludeuser=None, tag=None):
         """Iterate recent changes.
 
         @param start: Timestamp to start listing from
@@ -4504,6 +4504,8 @@
         @type user: basestring|list
         @param excludeuser: if not None, exclude edits by this user or users
         @type excludeuser: basestring|list
+        @param tag: a recent changes tag
+        @type tag: str
         @raises KeyError: a namespace identifier was not resolved
         @raises TypeError: a namespace identifier has an inappropriate
             type such as NoneType or bool
@@ -4513,7 +4515,7 @@
 
         rcgen = self._generator(api.ListGenerator, type_arg="recentchanges",
                                 rcprop="user|comment|timestamp|title|ids"
-                                       "|sizes|redirect|loginfo|flags",
+                                       '|sizes|redirect|loginfo|flags|tags',
                                 namespaces=namespaces,
                                 total=total, rctoponly=topOnly)
         if start is not None:
@@ -4548,7 +4550,7 @@
 
         if excludeuser:
             rcgen.request['rcexcludeuser'] = excludeuser
-
+        rcgen.request['rctag'] = tag
         return rcgen
 
     @deprecated_args(number='total', step=None, key='searchstring',
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 06380ef..b0710c2 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -865,6 +865,14 @@
         self.assertIsNotNone(gen)
         self.assertPagesInNamespacesAll(gen, set([0, 1, 2]), skip=True)
 
+    def test_recentchanges_rctag(self):
+        """Test recentchanges generator with recent changes tag."""
+        gf = pagegenerators.GeneratorFactory(site=self.site)
+        gf.handleArg('-recentchanges:visualeditor')
+        gen = gf.getCombinedGenerator()
+        self.assertIsNotNone(gen)
+        self.assertPagesInNamespacesAll(gen, set([0, 1, 2]), skip=True)
+
     def test_recentchanges_ns_default(self):
         """Test recentchanges generator."""
         gf = pagegenerators.GeneratorFactory(site=self.site)
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 2ddd451..55885fc 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1314,6 +1314,16 @@
             self.assertIsInstance(change, dict)
             self.assertNotIn("redirect", change)
 
+    def test_tag_filter(self):
+        """Test the site.recentchanges() with tag filter."""
+        mysite = self.site
+        for tag in ('visualeditor', 'mobile edit'):
+            for change in mysite.recentchanges(tag=tag, total=5):
+                self.assertIsInstance(change, dict)
+                self.assertIn('tags', change)
+                self.assertIsInstance(change['tags'], list)
+                self.assertIn(tag, change['tags'])
+
 
 class TestUserRecentChanges(DefaultSiteTestCase):
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia636aef46dd36b937a78cb71c9b98819753be2ff
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <i...@gno.de>

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

Reply via email to