Revision: 5249
Author: nicdumz
Date: 2008-04-22 07:54:01 +0000 (Tue, 22 Apr 2008)
Log Message:
-----------
If we tried to modify the page, but without effect on the text, warn the user, for both
edit and move protection templates
Modified Paths:
--------------
trunk/pywikipedia/blockpageschecker.py
Modified: trunk/pywikipedia/blockpageschecker.py
===================================================================
--- trunk/pywikipedia/blockpageschecker.py 2008-04-21 23:48:01 UTC (rev 5248)
+++ trunk/pywikipedia/blockpageschecker.py 2008-04-22 07:54:01 UTC (rev 5249)
@@ -292,17 +292,18 @@
# Only to see if the text is the same or not...
oldtext = text
editRestr = restrictions['edit']
+ # keep track of the changes for each step (edit then move)
+ changes = -1
if not editRestr:
+ # page is not edit-protected
# Deleting the template because the page doesn't need it.
replaceToPerform = u'|'.join(TTP + TSP)
- text = re.sub('(?:<noinclude>|)(%s)(?:</noinclude>|)' %
replaceToPerform, '', text)
- if text != oldtext:
- wikipedia.output(u'The page is editable for all, deleting the
template...')
- elif not moveBlockCheck:
- wikipedia.output('Warning : This page is in a protection category,
and is not edition-protected; yet no edit-protection templates could be found')
+ texti, changes =
re.subn('(?:<noinclude>|)(%s)(?:</noinclude>|)' % replaceToPerform,
'', text)
+ wikipedia.output(u'The page is editable for all, deleting the
template...')
- elif editRestr[0] == 'sysop':
+ elif editRestr[0] == 'sysop':
+ # total edit protection
if TemplateInThePage[0] == 'sysop-total' and TTP != None:
msg = 'The page is protected to the sysop'
if not moveBlockCheck:
@@ -310,9 +311,10 @@
wikipedia.output(msg)
else:
wikipedia.output(u'The page is protected to the sysop, but the
template seems not correct. Fixing...')
- text = re.sub(TemplateInThePage[1], TNR[1], text)
+ text, changes = re.subn(TemplateInThePage[1], TNR[1], text)
- elif TSP != None: # implicitely editRestr[0] = 'autoconfirmed'
+ elif TSP != None:
+ # implicitely editRestr[0] = 'autoconfirmed', edit-Semi-protection
if TemplateInThePage[0] == 'autoconfirmed-total':
msg = 'The page is editable only for the autoconfirmed users'
if not moveBlockCheck:
@@ -320,32 +322,44 @@
wikipedia.output(msg)
else:
wikipedia.output(u'The page is editable only for the autoconfirmed
users, but the template seems not correct. Fixing...')
- text = re.sub(TemplateInThePage[1], TNR[0], text)
+ text, changes = re.subn(TemplateInThePage[1], TNR[0], text)
+ if changes == 0:
+ # We tried to fix edit-protection templates, but it did not work.
+ wikipedia.output('Warning : No edit-protection template could be
found')
if moveBlockCheck:
+ # checking move protection now
moveRestr = restrictions['move']
+ changes = -1
+
if not moveRestr:
wikipedia.output(u'The page is movable for all, deleting the
template...')
# Deleting the template because the page doesn't need it.
replaceToPerform = u'|'.join(TSMP + TTMP)
- text = re.sub('(?:<noinclude>|)(%s)(?:</noinclude>|)'
% replaceToPerform, '', text)
+ text, changes =
re.subn('(?:<noinclude>|)(%s)(?:</noinclude>|)' % replaceToPerform,
'', text)
elif moveRestr[0] == 'sysop':
+ # move-total-protection
if TemplateInThePage[0] == 'sysop-move' and TTMP != None:
wikipedia.output(u'The page is protected from moving to the
sysop, skipping...')
else:
wikipedia.output(u'The page is protected from moving to the
sysop, but the template seems not correct. Fixing...')
- text = re.sub(TemplateInThePage[1], TNR[3], text)
+ text, changes = re.subn(TemplateInThePage[1], TNR[3], text)
- elif TSMP != None: #implicitely moveRestr[0] = 'autoconfirmed'
+ elif TSMP != None:
+ # implicitely moveRestr[0] = 'autoconfirmed',
move-semi-protection
if TemplateInThePage[0] == 'autoconfirmed-move':
wikipedia.output(u'The page is movable only for the autoconfirmed
users, skipping...')
else:
wikipedia.output(u'The page is movable only for the autoconfirmed
users, but the template seems not correct. Fixing...')
- text = re.sub(TemplateInThePage[1], TNR[2], text)
+ text, changes = re.subn(TemplateInThePage[1], TNR[2], text)
+ if changes == 0:
+ # We tried to fix move-protection templates, but it did not work.
+ wikipedia.output('Warning : No move-protection template could be
found')
+
if oldtext != text:
# Ok, asking if the change has to be performed and do it if yes.
wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default}
<<<" % page.title())