jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/321089 )
Change subject: [IMPR] Add new page generators ......................................................................
[IMPR] Add new page generators
Added/enabled following page generators: -wantedpages -wantedfiles -wantedcategories -wantedtemplates
Also add some tests.
Signed-off-by: xqt info@gno.de Bug: T56557 Bug: T150222 Change-Id: I7d5cba11c2534b8ff90d10205cc399a06ce83590 --- M pywikibot/pagegenerators.py M pywikibot/site.py M tests/pagegenerators_tests.py 3 files changed, 100 insertions(+), 2 deletions(-)
Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 7be9948..b8aea84 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -252,6 +252,22 @@ is the string to look for, or "-searchitem:lang:text", where lang is the langauge to search items in.
+-wantedpages Work on pages that are linked, but do not exist; + may be given as "-wantedpages:n" where n is the maximum + number of articles to work on. + +-wantedcategories Work on categories that are used, but do not exist; + may be given as "-wantedcategories:n" where n is the + maximum number of categories to work on. + +-wantedfiles Work on files that are used, but do not exist; + may be given as "-wantedfiles:n" where n is the maximum + number of files to work on. + +-wantedtemplates Work on templates that are used, but do not exist; + may be given as "-wantedtemplates:n" where n is the + maximum number of templates to work on. + -random Work on random pages returned by [[Special:Random]]. Can also be given as "-random:n" where n is the number of pages to be returned. @@ -737,6 +753,22 @@ return UnwatchedPagesPageGenerator( total=_int_none(value), site=self.site)
+ def _handle_wantedpages(self, value): + """Handle `-wantedpages` argument.""" + return self.site.wantedpages(total=_int_none(value)) + + def _handle_wantedfiles(self, value): + """Handle `-wantedfiles` argument.""" + return self.site.wantedfiles(total=_int_none(value)) + + def _handle_wantedtemplates(self, value): + """Handle `-wantedtemplates` argument.""" + return self.site.wantedtemplates(total=_int_none(value)) + + def _handle_wantedcategories(self, value): + """Handle `-wantedcategories` argument.""" + return self.site.wantedcategories(total=_int_none(value)) + def _handle_property(self, value): """Handle `-property` argument.""" if not value: @@ -2427,6 +2459,7 @@ return site.pages_with_property(name, total=total)
+@deprecated('Site.wantedpages', since='20180803') def WantedPagesPageGenerator(total=100, site=None): """ Wanted page generator. @@ -2438,8 +2471,7 @@ """ if site is None: site = pywikibot.Site() - for page in site.wantedpages(total=total): - yield page + return site.wantedpages(total=total)
@deprecated_args(number="total", repeat=None) diff --git a/pywikibot/site.py b/pywikibot/site.py index 304dcdc..29f3799 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -6653,6 +6653,7 @@ type_arg='querypage', gqppage='Unwatchedpages', total=total)
+ @need_version('1.18') @deprecated_args(step=None) def wantedpages(self, total=None): """Yield Pages from Special:Wantedpages. @@ -6663,6 +6664,27 @@ type_arg='querypage', gqppage='Wantedpages', total=total)
+ @need_version('1.18') + def wantedfiles(self, total=None): + """Yield Pages from Special:Wantedfiles. + + @param total: number of pages to return + """ + return self._generator(api.PageGenerator, + type_arg='querypage', gqppage='Wantedfiles', + total=total) + + @need_version('1.18') + def wantedtemplates(self, total=None): + """Yield Pages from Special:Wantedtemplates. + + @param total: number of pages to return + """ + return self._generator(api.PageGenerator, + type_arg='querypage', gqppage='Wantedtemplates', + total=total) + + @need_version('1.18') @deprecated_args(number='total', step=None, repeat=None) def wantedcategories(self, total=None): """Yield Pages from Special:Wantedcategories. diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index e846b3c..fa6b956 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -1256,6 +1256,50 @@ self.assertPagesInNamespaces(gen, 1)
+class TestWantedFactoryGenerator(DefaultSiteTestCase): + + """Test pagegenerators.GeneratorFactory for wanted pages.""" + + def setUp(self): + """Setup tests.""" + super(TestWantedFactoryGenerator, self).setUp() + self.gf = pagegenerators.GeneratorFactory(site=self.site) + + def _generator_with_tests(self): + """Test generator.""" + gen = self.gf.getCombinedGenerator() + self.assertIsNotNone(gen) + pages = list(gen) + self.assertLessEqual(len(pages), 5) + for page in pages: + yield page + + def test_wanted_pages(self): + """Test wantedpages generator.""" + self.gf.handleArg('-wantedpages:5') + for page in self._generator_with_tests(): + self.assertIsInstance(page, pywikibot.Page) + + def test_wanted_files(self): + """Test wantedfiles generator.""" + self.gf.handleArg('-wantedfiles:5') + for page in self._generator_with_tests(): + self.assertIsInstance(page, pywikibot.FilePage) + + def test_wanted_templates(self): + """Test wantedtemplates generator.""" + self.gf.handleArg('-wantedtemplates:5') + for page in self._generator_with_tests(): + self.assertIsInstance(page, pywikibot.Page) + self.assertEqual(page.namespace(), 10) + + def test_wanted_categories(self): + """Test wantedcategories generator.""" + self.gf.handleArg('-wantedcategories:5') + for page in self._generator_with_tests(): + self.assertIsInstance(page, pywikibot.Category) + + class TestFactoryGeneratorWikibase(WikidataTestCase):
"""Test pagegenerators.GeneratorFactory on Wikibase site."""
pywikibot-commits@lists.wikimedia.org