http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9827
Revision: 9827
Author: xqt
Date: 2012-01-15 19:33:33 +0000 (Sun, 15 Jan 2012)
Log Message:
-----------
always catlib.change_category() inplace for templates due to bug #3474195
Modified Paths:
--------------
trunk/pywikipedia/catlib.py
Modified: trunk/pywikipedia/catlib.py
===================================================================
--- trunk/pywikipedia/catlib.py 2012-01-14 21:07:29 UTC (rev 9826)
+++ trunk/pywikipedia/catlib.py 2012-01-15 19:33:33 UTC (rev 9827)
@@ -557,7 +557,8 @@
# # Prepend it
# return Category(code, "%s:%s" % (ns, name))
-def change_category(article, oldCat, newCat, comment=None, sortKey=None, inPlace=False):
+def change_category(article, oldCat, newCat, comment=None, sortKey=None,
+ inPlace=False):
"""
Given an article which is in category oldCat, moves it to
category newCat. Moves subcategories of oldCat as well.
@@ -569,9 +570,10 @@
changesMade = False
if not article.canBeEdited():
- wikipedia.output("Can't edit %s, skipping it..." %
article.title(asLink=True))
+ wikipedia.output("Can't edit %s, skipping it..."
+ % article.title(asLink=True))
return False
- if inPlace == True:
+ if inPlace or article.namespace() == 10:
oldtext = article.get(get_redirect=True)
newtext = wikipedia.replaceCategoryInPlace(oldtext, oldCat, newCat)
if newtext == oldtext:
@@ -582,20 +584,19 @@
article.put(newtext, comment)
return True
except wikipedia.EditConflict:
- wikipedia.output(
- u'Skipping %s because of edit conflict' %
article.title(asLink=True))
+ wikipedia.output(u'Skipping %s because of edit conflict'
+ % article.title(asLink=True))
except wikipedia.LockedPage:
- wikipedia.output(u'Skipping locked page %s' %
article.title(asLink=True))
+ wikipedia.output(u'Skipping locked page %s'
+ % article.title(asLink=True))
except wikipedia.SpamfilterError, error:
- wikipedia.output(
- u'Changing page %s blocked by spam filter (URL=%s)'
+ wikipedia.output(u'Changing page %s blocked by spam filter (URL=%s)'
% (article.title(asLink=True), error.url))
except wikipedia.NoUsername:
- wikipedia.output(
- u"Page %s not saved; sysop privileges required."
+ wikipedia.output(u'Page %s not saved; sysop privileges required.'
% article.title(asLink=True))
except wikipedia.PageNotSaved, error:
- wikipedia.output(u"Saving page %s failed: %s"
+ wikipedia.output(u'Saving page %s failed: %s'
% (article.title(asLink=True), error.message))
return False
@@ -620,7 +621,8 @@
newCatList.append(cat)
if not changesMade:
- wikipedia.output(u'ERROR: %s is not in category %s!' % (article.aslink(),
oldCat.title()))
+ wikipedia.output(u'ERROR: %s is not in category %s!'
+ % (article.title(asLink=True), oldCat.title()))
else:
text = article.get(get_redirect=True)
try:
@@ -644,7 +646,7 @@
u'Skipping %s because page is locked' % article.title())
except wikipedia.PageNotSaved, error:
wikipedia.output(u"Saving page %s failed: %s"
- % (article.aslink(), error.message))
+ % (article.title(asLink=True), error.message))
def categoryAllElementsAPI(CatName, cmlimit = 5000, categories_parsed = [], site =
None):
#action=query&list=categorymembers&cmlimit=500&cmtitle=Category:License_tags