diff --git a/scripts/add_text.py b/scripts/add_text.py index ece394bcbb..acbf3214a6 100644 --- a/scripts/add_text.py +++ b/scripts/add_text.py @@ -77,9 +77,7 @@ import time import pywikibot -from pywikibot import config -from pywikibot import i18n -from pywikibot import pagegenerators +from pywikibot import config, i18n, pagegenerators, textlib docuReplacements = { '¶ms;': pagegenerators.parameterHelp, @@ -173,23 +171,23 @@ def add_text(page, addText, summary=None, regexSkip=None, addText = addText.replace('\\n', config.line_separator) if (reorderEnabled): # Getting the categories - categoriesInside = pywikibot.getCategoryLinks(newtext, site) + categoriesInside = textlib.getCategoryLinks(newtext, site) # Deleting the categories - newtext = pywikibot.removeCategoryLinks(newtext, site) + newtext = textlib.removeCategoryLinks(newtext, site) # Getting the interwiki - interwikiInside = pywikibot.getLanguageLinks(newtext, site) + interwikiInside = textlib.getLanguageLinks(newtext, site) # Removing the interwiki - newtext = pywikibot.removeLanguageLinks(newtext, site) + newtext = textlib.removeLanguageLinks(newtext, site) # Adding the text newtext += u"%s%s" % (config.line_separator, addText) # Reputting the categories - newtext = pywikibot.replaceCategoryLinks(newtext, - categoriesInside, site, - True) + newtext = textlib.replaceCategoryLinks(newtext, + categoriesInside, site, + True) # Dealing the stars' issue allstars = [] - starstext = pywikibot.removeDisabledParts(text) + starstext = textlib.removeDisabledParts(text) for star in starsList: regex = re.compile('(\{\{(?:template:|)%s\|.*?\}\}[\s]*)' % star, re.I) @@ -203,8 +201,8 @@ def add_text(page, addText, summary=None, regexSkip=None, for element in allstars: newtext += '%s%s' % (element.strip(), config.LS) # Adding the interwiki - newtext = pywikibot.replaceLanguageLinks(newtext, interwikiInside, - site) + newtext = textlib.replaceLanguageLinks(newtext, interwikiInside, + site) else: newtext += u"%s%s" % (config.line_separator, addText) else: diff --git a/scripts/catall.py b/scripts/catall.py index 1e61f1165f..780e52d8eb 100755 --- a/scripts/catall.py +++ b/scripts/catall.py @@ -23,7 +23,7 @@ import sys import pywikibot -from pywikibot import i18n +from pywikibot import i18n, textlib def choosecats(pagetext): @@ -69,8 +69,8 @@ def make_categories(page, list, site=None): for p in list: cattitle = "%s:%s" % (site.category_namespace(), p) pllist.append(pywikibot.Page(site, cattitle)) - page.put_async(pywikibot.replaceCategoryLinks(page.get(), pllist, - site=page.site), + page.put_async(textlib.replaceCategoryLinks(page.get(), pllist, + site=page.site), comment=i18n.twtranslate(site.code, 'catall-changing')) diff --git a/scripts/category.py b/scripts/category.py index d5f54925f5..c511759da7 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -105,7 +105,7 @@ import bz2 import pywikibot from pywikibot import config, pagegenerators -from pywikibot import i18n +from pywikibot import i18n, textlib from pywikibot import deprecate_arg, deprecated # This is required for the text that is shown when you run this script @@ -397,7 +397,7 @@ def treat(self, page): catpl = self.sorted_by_last_name(catpl, page) pywikibot.output(u'Adding %s' % catpl.title(asLink=True)) cats.append(catpl) - text = pywikibot.replaceCategoryLinks(text, cats, site=page.site) + text = textlib.replaceCategoryLinks(text, cats, site=page.site) if not self.save(text, page, newcatTitle, old_text=old_text): pywikibot.output(u'Page %s not saved.' % page.title(asLink=True)) diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py index a69c35d018..aad7bf875a 100755 --- a/scripts/cosmetic_changes.py +++ b/scripts/cosmetic_changes.py @@ -74,7 +74,7 @@ from distutils.version import LooseVersion as LV import pywikibot import isbn -from pywikibot import config, i18n, pagegenerators, Bot +from pywikibot import config, i18n, textlib, pagegenerators, Bot from pywikibot.page import url2unicode warning = """ @@ -259,7 +259,7 @@ def standardizePageFooter(self, text): if not self.template and '{{Personendaten' not in text and \ '{{SORTIERUNG' not in text and '{{DEFAULTSORT' not in text and \ self.site.code not in ('et', 'it', 'bg', 'ru'): - categories = pywikibot.getCategoryLinks(text, site=self.site) + categories = textlib.getCategoryLinks(text, site=self.site) if not self.talkpage: # and pywikibot.calledModuleName() <> 'interwiki': subpage = False @@ -272,13 +272,13 @@ def standardizePageFooter(self, text): pass if loc is not None and loc in self.title: subpage = True - interwikiLinks = pywikibot.getLanguageLinks( + interwikiLinks = textlib.getLanguageLinks( text, insite=self.site, template_subpage=subpage) # Removing the interwiki - text = pywikibot.removeLanguageLinks(text, site=self.site) + text = textlib.removeLanguageLinks(text, site=self.site) # Removing the stars' issue - starstext = pywikibot.removeDisabledParts(text) + starstext = textlib.removeDisabledParts(text) for star in starsList: regex = re.compile('(\{\{(?:template:|)%s\|.*?\}\}[\s]*)' % star, re.I) @@ -297,8 +297,8 @@ def standardizePageFooter(self, text): # if re.search(u"(.+?)\|(.{,1}?)",name.title()) or name.title()==name.title().split(":")[0]+title: # categories.remove(name) # categories.insert(0, name) - text = pywikibot.replaceCategoryLinks(text, categories, - site=self.site) + text = textlib.replaceCategoryLinks(text, categories, + site=self.site) # Adding stars templates if allstars: text = text.strip() + self.site.family.interwiki_text_separator @@ -308,10 +308,10 @@ def standardizePageFooter(self, text): pywikibot.log(u'%s' % element.strip()) # Adding the interwiki if interwikiLinks: - text = pywikibot.replaceLanguageLinks(text, interwikiLinks, - site=self.site, - template=self.template, - template_subpage=subpage) + text = textlib.replaceLanguageLinks(text, interwikiLinks, + site=self.site, + template=self.template, + template_subpage=subpage) return text def translateAndCapitalizeNamespaces(self, text): @@ -353,7 +353,7 @@ def translateAndCapitalizeNamespaces(self, text): namespaces[i] = item namespaces.append(thisNs[0].lower() + thisNs[1:]) if thisNs and namespaces: - text = pywikibot.replaceExcept( + text = textlib.replaceExcept( text, r'\[\[\s*(%s) *:(?P.*?)\]\]' % '|'.join(namespaces), @@ -375,7 +375,7 @@ def translateMagicWords(self, text): aliases = self.site.getmagicwords(magicWord) if not aliases: continue - text = pywikibot.replaceExcept( + text = textlib.replaceExcept( text, r'\[\[(?P.+?:.+?\..+?\|) *(' + '|'.join(aliases) + ') *(?P(\|.*?)?\]\])', @@ -503,9 +503,9 @@ def handleOneLink(match): r'(?P[\n]*)\[\[(?P[^\]\|]+)(\|(?P