jenkins-bot has submitted this change and it was merged.
Change subject: Use page properties to find if a category is hidden ......................................................................
Use page properties to find if a category is hidden
Bug: 65149
Added also: @pywikibot.site.need_version("1.13") def isEmptyCategory(self):
@pywikibot.site.need_version("1.11") def isHiddenCategory(self):
New method Page.version() defined in order to use such decorator.
Change-Id: I349559ee93fae1c6f8832581ed774da965740539 --- M pywikibot/page.py M tests/page_tests.py 2 files changed, 19 insertions(+), 6 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 9a865a8..1f1390b 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -120,6 +120,15 @@ """Return the Site object for the wiki on which this Page resides.""" return self._link.site
+ def version(self): + """Return MediaWiki version number of the Site object for the wiki + on which this Page resides. + + This is needed to use @need_version() decorator for methods of + Page objects. + """ + return self.site.version() + @property def image_repository(self): """Return the Site object for the image repository.""" @@ -2119,19 +2128,16 @@ if total == 0: return
+ @pywikibot.site.need_version("1.13") def isEmptyCategory(self): """Return True if category has no members (including subcategories).""" ci = self.categoryinfo return sum(ci[k] for k in ['files', 'pages', 'subcats']) == 0
+ @pywikibot.site.need_version("1.11") def isHiddenCategory(self): """Return True if the category is hidden.""" - # FIXME - # This should use action=query&list=allcategories - # setting acfrom and acto to the category title and adding - # acprop=hidden but currently fails in some cases - # (see bug 48824) - return '__HIDDENCAT__' in self.expand_text() + return u'hiddencat' in self.properties()
def copyTo(self, cat, message): """ diff --git a/tests/page_tests.py b/tests/page_tests.py index 4383cb1..d8590c9 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -410,6 +410,13 @@ self.assertTrue(cat_empty.isEmptyCategory()) self.assertFalse(cat_not_empty.isEmptyCategory())
+ def test_isHiddenCategory(self): + site = pywikibot.Site('en', 'wikipedia') + cat_hidden = pywikibot.Category(site, u'Category:Hidden categories') + cat_not_hidden = pywikibot.Category(site, u'Category:Wikipedia categories') + self.assertTrue(cat_hidden.isHiddenCategory()) + self.assertFalse(cat_not_hidden.isHiddenCategory()) +
if __name__ == '__main__': try:
pywikibot-commits@lists.wikimedia.org