Skip to content
Permalink
Browse files

+ Revocator

  • Loading branch information...
JackPotte committed Jun 1, 2019
1 parent 159f2c0 commit 811f25e7555ee68401793f2fd0e925d6fd079817
Showing with 63 additions and 4 deletions.
  1. +1 −1 JackBot.sh
  2. +24 −2 src/fr.wiktionary.format.py
  3. +38 −1 src/lib/pageFunctions.py
@@ -33,7 +33,7 @@
#python core/pwb.py src/fr.wiktionary.create-flexions
#python core/pwb.py src/fr.wiktionary.format
#python core/pwb.py src/fr.wiktionary.import-from-commons

#python core/pwb.py src/fr.wiktionary.format.py -u Escarbot revocation 1000

#*** Current global operation ***
#python core/pwb.py src/fr.wikibooks.format -cat
@@ -65,6 +65,7 @@
listHomophons = False
listFalseTranslations = False
testImport = False
cancelUser = {}
outputFile = ''
anagramsMaxLength = 4 # sinon trop long : 5 > 5 min, 8 > 1 h par page)

@@ -500,6 +501,7 @@
Modele.append(u'armes')
Modele.append(u'arthropodes')
Modele.append(u'artillerie')
Modele.append(u'artistes')
Modele.append(u'arts martiaux')
Modele.append(u'arts')
Modele.append(u'assurance')
@@ -835,6 +837,7 @@
Modele.append(u'humour')
Modele.append(u'hydraulique')
Modele.append(u'hydrobiologie')
Modele.append(u'hygiène')
Modele.append(u'hyperb')
Modele.append(u'hyperbole')
Modele.append(u'hérald')
@@ -1668,6 +1671,14 @@ def treatPageByName(pageName):
if currentPageContent == 'KO':
if debugLevel > 0: print u' Page vide'
return

if cancelUser != {}:
pageContent, summary = cancelEdition(page, cancelUser)
page = Page(site, pageName) # a page reset is needed to edit the last version
if pageContent != '' and pageContent != currentPageContent:
savePage(page, pageContent, summary)
return

pageContent = currentPageContent
finalPageContent = u''
rePageName = re.escape(pageName)
@@ -2940,7 +2951,7 @@ def treatPageByName(pageName):
setGlobalsWiktionary(debugLevel, site, username)
def main(*args):
global waitAfterHumans, fixOldTemplates, listHomophons, outputFile, siteLanguage, siteFamily, fixTags, \
listFalseTranslations, testImport
listFalseTranslations, testImport, cancelUser
if len(sys.argv) > 1:
if debugLevel > 1: print sys.argv
afterPage = u''
@@ -2978,7 +2989,18 @@ def main(*args):
else:
p.pagesByXML(dumpFile, regex = regex)
elif sys.argv[1] == str('-u'):
p.pagesByUser(u'User:' + username, numberOfPagesToTreat = 4000)
if len(sys.argv) > 2:
targetedUser = sys.argv[2]
else:
targetedUser = username
if len(sys.argv) > 3:
cancelUser['user'] = targetedUser
cancelUser['action'] = sys.argv[3]
if len(sys.argv) > 4:
number = sys.argv[4]
else:
number = 1000
p.pagesByUser(u'User:' + targetedUser, numberOfPagesToTreat = number)
elif sys.argv[1] == str('-search') or sys.argv[1] == str('-s') or sys.argv[1] == str('-r'):
if len(sys.argv) > 2:
p.pagesBySearch(sys.argv[2])
@@ -154,7 +154,7 @@ def getContentFromPage(page, allowedNamespaces = None, username = username):
if debugLevel > 0: print u' NoPage l 694'
return 'KO'
except pywikibot.exceptions.ServerError:
if debugLevel > 0: print u' NoPage l 697'
if debugLevel > 0: print u' ServerError l 697'
return 'KO'
else:
if debugLevel > 0: print u' Forbidden namespace l 700'
@@ -512,3 +512,40 @@ def getLineNumber():
from inspect import currentframe, getframeinfo
frameinfo = getframeinfo(currentframe())
return str(frameinfo.lineno)

def cancelEdition(page, cancelUser):
oldPageContent = u''
userName = cancelUser['user']
if debugLevel > 1: print page.userName() + u' trouvé'

if cancelUser['action'].lower() in ['revocation' , 'révocation']:
summary = u'Révocation de ' + userName
if page.getCreator() == userName:
page.delete(reason = summary, prompt = False)
return ''
else:
i = 0
while page.getVersionHistory()[i][2] == userName:
i = i + 1
if debugLevel > 1: print i
if i > 0:
oldPageContent = getOldPageContent(page, page.getVersionHistory()[i][0])
if debugLevel > 2: raw_input(oldPageContent.encode(config.console_encoding, 'replace'))
elif page.userName() == userName:
summary = u'Annulation de ' + userName
oldPageContent = getOldPageContent(page, page.previousRevision())

return oldPageContent, summary

def getOldPageContent(page, revision):
try:
return page.getOldVersion(revision, get_redirect = True)
except pywikibot.exceptions.BadTitle:
if debugLevel > 0: print u' IsRedirect l 548'
return ''
except pywikibot.exceptions.NoPage:
if debugLevel > 0: print u' NoPage l 551'
return ''
except pywikibot.exceptions.ServerError:
if debugLevel > 0: print u' ServerError l 554'
return ''

0 comments on commit 811f25e

Please sign in to comment.
You can’t perform that action at this time.