Mpaa has uploaded a new change for review.

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

Change subject: Pagegenerators.py: ns handling for titleregex option
......................................................................

Pagegenerators.py: ns handling for titleregex option

Workaround for Bug T85389.

If namespace is given before -titleregex, it can be handled.
With argparse support, it will be possible possible to handle
the full support.

Bug T85389

Change-Id: I69bf8b9782b97426c0b67ef97b3892f152fe0fb1
---
M pywikibot/pagegenerators.py
M tests/pagegenerators_tests.py
2 files changed, 18 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/93/181993/1

diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 2294b46..eb1adab 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -111,6 +111,8 @@
                   before -newpages.
                   If used with -recentchanges, efficiency is improved if
                   -namepace/ns is provided before -recentchanges.
+                  If used with -titleregex, -namepace/ns must be provided
+                  before -titleregex and shall contain only one value.
 
 -interwiki        Work on the given page and all equivalent pages in other
                   languages. This can, for example, be used to fight
@@ -615,7 +617,17 @@
                 regex = pywikibot.input(u'What page names are you looking 
for?')
             else:
                 regex = arg[12:]
-            gen = RegexFilterPageGenerator(self.site.allpages(), regex)
+            # partial workaround for bug T85389
+            # to use -namespace/ns with -newpages, -ns must be given
+            # before -titleregex
+            # otherwise default namespace is 0
+            try:
+                namespace = self.namespaces[0]
+            except IndexError:
+                namespace = 0
+            gen = RegexFilterPageGenerator(
+                self.site.allpages(namespace=namespace),
+                regex)
         elif arg.startswith('-grep'):
             if len(arg) == 5:
                 self.articlefilter_list.append(pywikibot.input(
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 31d0ec3..e9b33c4 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -390,17 +390,16 @@
             self.assertRegex(page.title().lower(), '^(.)\\1+')
 
     def test_regexfilter_ns(self):
-        raise unittest.SkipTest
         gf = pagegenerators.GeneratorFactory()
+        # Workaround for Bug: T85389
+        # Give -ns before -titleregex (as for -newpages)
+        gf.handleArg('-ns:1')
         self.assertTrue(gf.handleArg('-titleregex:.*'))
         gf.handleArg('-limit:10')
-        gf.handleArg('-ns:1')
         gen = gf.getCombinedGenerator()
-        # The code below takes due to bug T85389
+        # If ns is given after -titleregex, the code below would take long
+        # due to bug T85389
         pages = list(gen)
-        # TODO: Fix RegexFilterPageGenerator to handle namespaces other than 0
-        # Bug: T85389
-        # Below should fail
         self.assertGreater(len(pages), 0)
         self.assertLessEqual(len(pages), 10)
         self.assertPagesInNamespaces(gen, 1)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I69bf8b9782b97426c0b67ef97b3892f152fe0fb1
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to