http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10269
Revision: 10269
Author: xqt
Date: 2012-06-02 22:33:14 +0000 (Sat, 02 Jun 2012)
Log Message:
-----------
isAllowed('sendemail') exists since 1.16, bugfix for bug #3526073
Modified Paths:
--------------
trunk/pywikipedia/userlib.py
Modified: trunk/pywikipedia/userlib.py
===================================================================
--- trunk/pywikipedia/userlib.py 2012-06-02 20:07:26 UTC (rev 10268)
+++ trunk/pywikipedia/userlib.py 2012-06-02 22:33:14 UTC (rev 10269)
@@ -179,7 +179,7 @@
return pywikibot.Page(self.site(), self.name() + subpage,
defaultNamespace=3)
- def sendMail(self, subject=u'', text=u'', ccMe = False):
+ def sendMail(self, subject=u'', text=u'', ccMe=False):
""" Send an email to this user via mediawiki's email interface.
Return True on success, False otherwise.
This method can raise an UserActionRefuse exception in case this user
@@ -192,10 +192,12 @@
@type text: unicode
@param ccme: if True, sends a copy of this email to the bot
@type ccme: bool
+
"""
if not self.isEmailable():
raise UserActionRefuse('This user is not mailable')
- if not self.site().isAllowed('sendemail'):
+ if self.site().versionnumber() >= 16 and \
+ not self.site().isAllowed('sendemail'):
raise UserActionRefuse('You don\'t have permission to send mail')
if not self.site().has_api() or self.site().versionnumber() < 14:
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10268
Revision: 10268
Author: xqt
Date: 2012-06-02 20:07:26 +0000 (Sat, 02 Jun 2012)
Log Message:
-----------
-pagesonly option for not to remove subcategories from its main, update from rewrite 10267
Modified Paths:
--------------
trunk/pywikipedia/category.py
Modified: trunk/pywikipedia/category.py
===================================================================
--- trunk/pywikipedia/category.py 2012-06-02 19:47:54 UTC (rev 10267)
+++ trunk/pywikipedia/category.py 2012-06-02 20:07:26 UTC (rev 10268)
@@ -57,6 +57,8 @@
* -inplace - Use this flag to change categories in place rather than
rearranging them.
* -recurse - Recurse through all subcategories of categories.
+ * -pagesonly - While removing pages from a category, keep the subpage links
+ and do not remove them
* -match - Only work on pages whose titles match the given regex (for
move and remove actions).
@@ -249,7 +251,7 @@
'''
page_name = pagelink.title()
- site = pagelink.site()
+ site = pagelink.site
# regular expression that matches a name followed by a space and
# disambiguation brackets. Group 1 is the name without the rest.
bracketsR = re.compile('(.*) \(.+?\)')
@@ -536,12 +538,16 @@
class CategoryRemoveRobot:
'''Removes the category tag from all pages in a given category
- and from the category pages of all subcategories, without prompting.
- Does not remove category tags pointing at subcategories.
+ and if pagesonly parameter is False also from the category pages of all
+ subcategories, without prompting. If the category is empty, it will be
+ tagged for deleting. Does not remove category tags pointing at
+ subcategories.
'''
- def __init__(self, catTitle, batchMode = False, editSummary = '', useSummaryForDeletion = True, titleRegex = None, inPlace = False):
+ def __init__(self, catTitle, batchMode=False, editSummary='',
+ useSummaryForDeletion=True, titleRegex=None, inPlace=False,
+ pagesonly=False):
self.editSummary = editSummary
self.site = pywikibot.getSite()
self.cat = catlib.Category(self.site, 'Category:'+ catTitle)
@@ -550,6 +556,7 @@
self.batchMode = batchMode
self.titleRegex = titleRegex
self.inPlace = inPlace
+ self.pagesonly = pagesonly
if not self.editSummary:
self.editSummary = i18n.twtranslate(self.site, 'category-removing',
{'oldcat': self.cat.title()})
@@ -562,6 +569,9 @@
for article in articles:
if not self.titleRegex or re.search(self.titleRegex,article.title()):
catlib.change_category(article, self.cat, None, comment = self.editSummary, inPlace = self.inPlace)
+ if self.pagesonly:
+ return
+
# Also removes the category tag from subcategories' pages
subcategories = self.cat.subcategoriesList(recurse = 0)
if len(subcategories) == 0:
@@ -857,6 +867,7 @@
recurse = False
withHistory = False
titleRegex = None
+ pagesonly = False
# This factory is responsible for processing command line arguments
# that are also used by other scripts and that determine on which pages
@@ -918,6 +929,8 @@
talkPages = True
elif arg == '-recurse':
recurse = True
+ elif arg == '-pagesonly':
+ pagesonly = True
elif arg == '-create':
create_pages = True
elif arg == '-hist':
@@ -946,7 +959,8 @@
oldCatTitle = pywikibot.input(
u'Please enter the name of the category that should be removed:')
bot = CategoryRemoveRobot(oldCatTitle, batchMode, editSummary,
- useSummaryForDeletion, inPlace=inPlace)
+ useSummaryForDeletion, inPlace=inPlace,
+ pagesonly=pagesonly)
bot.run()
elif action == 'move':
if (fromGiven == False):
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10267
Revision: 10267
Author: xqt
Date: 2012-06-02 19:47:54 +0000 (Sat, 02 Jun 2012)
Log Message:
-----------
-pagesonly option for not to remove subcategories from its main
Modified Paths:
--------------
branches/rewrite/scripts/category.py
Modified: branches/rewrite/scripts/category.py
===================================================================
--- branches/rewrite/scripts/category.py 2012-06-01 22:42:43 UTC (rev 10266)
+++ branches/rewrite/scripts/category.py 2012-06-02 19:47:54 UTC (rev 10267)
@@ -53,6 +53,8 @@
* -inplace - Use this flag to change categories in place rather than
rearranging them.
* -recurse - Recurse through all subcategories of categories.
+ * -pagesonly - While removing pages from a category, keep the subpage links
+ and do not remove them
* -match - Only work on pages whose titles match the given regex (for
move and remove actions).
@@ -505,12 +507,16 @@
class CategoryRemoveRobot:
'''Removes the category tag from all pages in a given category
- and from the category pages of all subcategories, without prompting.
- Does not remove category tags pointing at subcategories.
+ and if pagesonly parameter is False also from the category pages of all
+ subcategories, without prompting. If the category is empty, it will be
+ tagged for deleting. Does not remove category tags pointing at
+ subcategories.
'''
- def __init__(self, catTitle, batchMode = False, editSummary = '', useSummaryForDeletion = True, titleRegex = None, inPlace = False):
+ def __init__(self, catTitle, batchMode=False, editSummary='',
+ useSummaryForDeletion=True, titleRegex=None, inPlace=False,
+ pagesonly=False):
self.editSummary = editSummary
self.site = pywikibot.getSite()
self.cat = catlib.Category(pywikibot.Link('Category:' + catTitle))
@@ -519,6 +525,7 @@
self.batchMode = batchMode
self.titleRegex = titleRegex
self.inPlace = inPlace
+ self.pagesonly = pagesonly
if not self.editSummary:
self.editSummary = i18n.twtranslate(self.site, 'category-removing',
{'oldcat': self.cat.title()})
@@ -531,6 +538,9 @@
for article in articles:
if not self.titleRegex or re.search(self.titleRegex,article.title()):
catlib.change_category(article, self.cat, None, comment = self.editSummary, inPlace = self.inPlace)
+ if self.pagesonly:
+ return
+
# Also removes the category tag from subcategories' pages
subcategories = set(self.cat.subcategories())
if len(subcategories) == 0:
@@ -806,6 +816,7 @@
talkPages = False
recurse = False
titleRegex = None
+ pagesonly = False
# This factory is responsible for processing command line arguments
# that are also used by other scripts and that determine on which pages
@@ -867,6 +878,8 @@
talkPages = True
elif arg == '-recurse':
recurse = True
+ elif arg == '-pagesonly':
+ pagesonly = True
elif arg == '-create':
create_pages = True
else:
@@ -888,7 +901,8 @@
oldCatTitle = pywikibot.input(
u'Please enter the name of the category that should be removed:')
bot = CategoryRemoveRobot(oldCatTitle, batchMode, editSummary,
- useSummaryForDeletion, inPlace=inPlace)
+ useSummaryForDeletion, inPlace=inPlace,
+ pagesonly=pagesonly)
bot.run()
elif action == 'move':
if (fromGiven == False):