Eflyjason (Code Review)
2017-12-27 01:51:27 UTC
Eflyjason has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/400264 )
Change subject: Add an add_only parameter to replaceCategoryInPlace in textlib
......................................................................
Add an add_only parameter to replaceCategoryInPlace in textlib
Bug: T183707
Change-Id: I67238337ee82e51ab6c876bbdfe32b05e7836cd2
---
M pywikibot/textlib.py
1 file changed, 11 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/64/400264/1
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index cedb30d..71abed2 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1164,13 +1164,16 @@
return removeCategoryLinks(text, site, marker)
-def replaceCategoryInPlace(oldtext, oldcat, newcat, site=None):
+def replaceCategoryInPlace(oldtext, oldcat, newcat, site=None,
+ add_only=False):
"""
Replace old category with new one and return the modified text.
@param oldtext: Content of the old category
@param oldcat: pywikibot.Category object of the old category
@param newcat: pywikibot.Category object of the new category
+ @param add_only: If add_only is True, the old category won't
+ be replaced and the category given will be added after it.
@return: the modified text
@rtype: unicode
"""
@@ -1203,6 +1206,13 @@
text = replaceExcept(text, categoryR, '',
['nowiki', 'comment', 'math', 'pre', 'source'],
site=site)
+ elif add_only:
+ text = replaceExcept(oldtext, categoryR,
+ '{0}\n{1}'.format(
+ oldcat.title(asLink=True),
+ newcat.title(asLink=True)),
+ ['nowiki', 'comment', 'math', 'pre', 'source'],
+ site=site)
else:
text = replaceExcept(oldtext, categoryR,
'[[%s:%s\\2' % (site.namespace(14),
--
To view, visit https://gerrit.wikimedia.org/r/400264
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I67238337ee82e51ab6c876bbdfe32b05e7836cd2
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Eflyjason <***@gmail.com>
Change subject: Add an add_only parameter to replaceCategoryInPlace in textlib
......................................................................
Add an add_only parameter to replaceCategoryInPlace in textlib
Bug: T183707
Change-Id: I67238337ee82e51ab6c876bbdfe32b05e7836cd2
---
M pywikibot/textlib.py
1 file changed, 11 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/64/400264/1
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index cedb30d..71abed2 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1164,13 +1164,16 @@
return removeCategoryLinks(text, site, marker)
-def replaceCategoryInPlace(oldtext, oldcat, newcat, site=None):
+def replaceCategoryInPlace(oldtext, oldcat, newcat, site=None,
+ add_only=False):
"""
Replace old category with new one and return the modified text.
@param oldtext: Content of the old category
@param oldcat: pywikibot.Category object of the old category
@param newcat: pywikibot.Category object of the new category
+ @param add_only: If add_only is True, the old category won't
+ be replaced and the category given will be added after it.
@return: the modified text
@rtype: unicode
"""
@@ -1203,6 +1206,13 @@
text = replaceExcept(text, categoryR, '',
['nowiki', 'comment', 'math', 'pre', 'source'],
site=site)
+ elif add_only:
+ text = replaceExcept(oldtext, categoryR,
+ '{0}\n{1}'.format(
+ oldcat.title(asLink=True),
+ newcat.title(asLink=True)),
+ ['nowiki', 'comment', 'math', 'pre', 'source'],
+ site=site)
else:
text = replaceExcept(oldtext, categoryR,
'[[%s:%s\\2' % (site.namespace(14),
--
To view, visit https://gerrit.wikimedia.org/r/400264
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I67238337ee82e51ab6c876bbdfe32b05e7836cd2
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Eflyjason <***@gmail.com>