Contido eliminado Contido engadido
Gallaecio (conversa | contribucións)
Sen resumo de edición
Liña 10:
 
: {{Feito}} ─ [[Usuario:Gallaecio|Gallaecio]]<sup>[[Conversa_Usuario:Gallaecio|E logo?]]</sup> 5 de novembro de 2014 ás 07:21 (UTC)
 
<div class="mw-collapsible mw-collapsed">
<source lang="python">
import re
from pywikibot.page import Category
from pywikibot.pagegenerators import CategorizedPageGenerator, PreloadingGenerator, \
SubCategoriesPageGenerator
 
targetCategoryTemplateRe = re.compile(u"\{\{ *Redirección de categoría *\| *([^}]+) *\}\}")
categoryReTemplate = u"\[\[ *Categoría *: *{} *(?:\| *([^]|]+) *)?\]\]"
 
# Por cada categoría en «Categoría:Categorías pendentes de ser movidas»:
category = Category(self.site, u"Categorías pendentes de ser movidas")
generator = PreloadingGenerator(SubCategoriesPageGenerator(category))
for sourceCategory in generator:
 
sourceCategoryName = sourceCategory.title(withNamespace=False)
categoryRe = re.compile(categoryReTemplate.format(re.escape(sourceCategoryName)))
 
# Ler o contido da páxina da categoría.
sourceCategoryContent = sourceCategory.get()
 
# Obter a categoría de destino do uso do modelo «Redirección de categoría».
match = targetCategoryTemplateRe.search(sourceCategoryContent)
targetCategoryName = match.group(1)
 
# Se a categoría de destino non existe:
targetCategory = Category(self.site, targetCategoryName)
if not targetCategory.exists():
 
# Partir do contido da categoría actual.
# Eliminar o modelo «Redirección de categoría» e maila súa liña se queda baleira tras eliminar o modelo.
targetCategoryContent = u""
for line in sourceCategoryContent.splitlines():
match = targetCategoryTemplateRe.search(line)
if match:
line = line.replace(match.group(0), u"")
line = line.strip()
if not line:
continue
targetCategoryContent += line + u"\n"
 
# Crear a nova categoría co contido restante.
comment = u"Categoría creada a partir do contido de «{}».".format(sourceCategoryName)
self.userPut(page=targetCategory, oldtext=u"", newtext=targetCategoryContent,
comment=comment, show_diff=True)
 
# Por cada subcategoría na categoría vella:
subcategoryGenerator = PreloadingGenerator(SubCategoriesPageGenerator(sourceCategory))
for subcategory in subcategoryGenerator:
 
# Cambiar a categoría vella pola categoría nova.
subcategoryContent = subcategory.get()
match = categoryRe.search(subcategoryContent)
if match:
if len(match.groups()) > 1:
replacement = u"[[{}|{}]]".format(
targetCategory.title(withNamespace=True),
match.group(1))
else:
replacement = u"[[{}]]".format(targetCategory.title(withNamespace=True))
newSubcategoryContent = subcategoryContent.replace(match.group(0), replacement)
comment = u"Cambiouse a categoría «{}» pola categoría «{}».".format(
sourceCategoryName,
targetCategoryName)
self.userPut(page=subcategory, oldtext=subcategoryContent,
newtext=newSubcategoryContent, comment=comment, show_diff=True)
 
# Por cada artigo na categoría vella:
pageGenerator = PreloadingGenerator(CategorizedPageGenerator(sourceCategory))
for page in pageGenerator:
 
# Cambiar a categoría vella pola categoría nova.
pageContent = page.get()
match = categoryRe.search(pageContent)
if match:
if len(match.groups()) > 1:
replacement = u"[[{}|{}]]".format(
targetCategory.title(withNamespace=True),
match.group(1))
else:
replacement = u"[[{}]]".format(targetCategory.title(withNamespace=True))
newPageContent = pageContent.replace(match.group(0), replacement)
comment = u"Cambiouse a categoría «{}» pola categoría «{}».".format(
sourceCategoryName,
targetCategoryName)
self.userPut(page=page, oldtext=pageContent, newtext=newPageContent,
comment=comment, show_diff=True)
 
# Substituír o modelo «Redirección de categoría» polo modelo «Lixo» na categoría vella.
newCategoryLink = u"[[:{}|{}]]".format(targetCategory.title(withNamespace=True),
targetCategoryName)
comment = u"O contido desta categoría moveuse á categoría «{}».".format(newCategoryLink)
newSourceCategoryContent = u"{{{{Lixo|{}}}}}".format(comment)
self.userPut(page=sourceCategory, oldtext=sourceCategoryContent,
newtext=newSourceCategoryContent, comment=comment, show_diff=True)
</source>
</div>
 
== Retirar "Ligazón AB|xx" e "Link GA|xx" ==
Liña 22 ⟶ 120:
 
: {{Feito}} ─ [[Usuario:Gallaecio|Gallaecio]]<sup>[[Conversa_Usuario:Gallaecio|E logo?]]</sup> 5 de novembro de 2014 ás 21:48 (UTC)
 
<div class="mw-collapsible mw-collapsed">
<source lang="python">
import re
 
from pywikibot.page import Link, Page
from pywikibot.pagegenerators import PreloadingGenerator, \
ReferringPageGenerator
 
 
templateReModel = u"[ \r\n\t]*\r?\n\{{\{{ *{template} *(?:\| *[^}}|]+)?\}}\}}|\{{\{{ *{template} *(?:\| *[^}}|]+)?\}}\}}\r?\n[ \n\r\t]*"
 
for templateName in [u"Link GA", u"Ligazón AB"]:
 
templateRe = re.compile(templateReModel.format(template=re.escape(templateName)))
 
generator = ReferringPageGenerator(
Page(Link(
templateName,
defaultNamespace=10,
source=self.site)),
onlyTemplateInclusion=True)
generator = PreloadingGenerator(generator)
 
for page in generator:
oldPageContent = page.get()
newPageContent = templateRe.sub(u"", oldPageContent)
comment = u"Eliminouse o modelo «{}».".format(templateName)
self.userPut(page=page, oldtext=oldPageContent,
newtext=newPageContent, comment=comment,
show_diff=True)
</source>
</div>
 
== *minusválidos -> discapacitados ==
Liña 28 ⟶ 159:
 
Graaazas. --[[Usuario:HombreDHojalata|<span style="font-size:90%;color:maroon;text-shadow:peru 1px 1px 1px;">. '''''HombreDHojalata'''''</span>.]]<sup>[[Conversa usuario:HombreDHojalata|<span style="font-size:86%;color:brown;">conversa</span>]]</sup> 8 de novembro de 2014 ás 12:50 (UTC)
 
: {{Feito}} ─ [[Usuario:Gallaecio|Gallaecio]]<sup>[[Conversa_Usuario:Gallaecio|E logo?]]</sup> 9 de novembro de 2014 ás 05:45 (UTC)
 
<div class="mw-collapsible mw-collapsed">
Regra no ficheiro <code>user-fixes.py</code>:
<source lang="python">
fixes['discapacidade'] = {
'regex': True,
'msg': {
'_default':u'*minusválidos → discapacitados',
},
'replacements': [
(ur'\bMinusválid([ao]s?)\b', ur'Discapacitad\1'),
(ur'\bminusválid([ao]s?)\b', ur'discapacitad\1'),
(ur'\bMinusvalidez\b', ur'Discapacidade'),
(ur'\bminusvalidez\b', ur'discapacidade'),
]
}
</source>
 
Orde:
<source lang="bash">
python2 core/scripts/replace.py -transcludes:"Praia" -fix:discapacidade -always
</source>
</div>