Skip to content

Commit

Permalink
updated CentralAuth scraping for MW1.16wmf4 overhaul; added globalOve…
Browse files Browse the repository at this point in the history
…rsight command; updated whitelist; removed unused global account deletion
  • Loading branch information
Pathoschild committed Apr 11, 2010
1 parent 48aac13 commit d6ab515
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 51 deletions.
84 changes: 40 additions & 44 deletions modules/Browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,70 +790,66 @@ def setRights( self, username, groups, reason, allowUnchanged = False ):
## CentralAuth actions
## required: setBaseUrl() to metawiki
###################
def centralAuth( self, user, reason = '', lock = None, hide = None, delete = None, blockMeta = False, ignoreUnchanged = False ):
def centralAuth( self, user, reason = '', lock = None, hide = None, oversightLocal = None, ignoreUnchanged = False ):
self.trace()
self.login()

##############
## CentralAuth action
##############
# validate
if delete:
raise self.Error, 'global account deletion is disabled'
if lock == None and hide == None:
if lock == None and hide == None and oversightLocal == None:
raise self.Error, 'no lock or hide preferences specified'
if lock not in (True, False, None) or hide not in (True, False, None):
if lock not in (True, False, None) or hide not in (True, False, None) or oversightLocal not in (True, False, None):
raise self.Error, 'hide and lock preferences must be one of (True, False, None)'

# load page
# load form
self.load( title = 'Special:CentralAuth', parameters = {'target':user}, GET = True, visit = True, parse_as = 'html' )

# find correct form
try:
self.browser.select_form( predicate = lambda form: 'wpMethod' in [item.name for item in form.controls] and form['wpMethod'] == 'set-status' )
except mechanize.FormNotFoundError:
raise self.Error, 'could not find set-status form from Special:CentralAuth'

# fetch elements
check_lock = self.browser.find_control( 'wpStatusLocked' ).items[0]
check_hide = self.browser.find_control( 'wpStatusHidden' ).items[0]

# redundant?
if (lock == None or check_lock.selected == bool(lock)) and (hide == None or check_hide.selected == bool(hide)):
# parse input
NAME_LOCK = 'wpStatusLocked'
NAME_HIDE = 'wpStatusHidden'

LOCK_IGNORE = None
LOCK_NO = "0"
LOCK_YES = "1"
HIDE_NO = ""
HIDE_IGNORE = None
HIDE_LISTS = "lists"
HIDE_SUPPRESSED = "suppressed"
set_lock = LOCK_YES if lock else LOCK_NO if lock != None else LOCK_IGNORE
set_hide = HIDE_SUPPRESSED if oversightLocal else HIDE_LISTS if hide else HIDE_NO if hide != None else HIDE_IGNORE

# constants are invalid?
if set_lock != LOCK_IGNORE and set_lock not in [k.name for k in self.browser.find_control(NAME_LOCK).items]:
raise self.Error, 'invalid lock constant "%s", valid types are [%s]' % (set_lock, ', '.join([k.name for k in self.browser.find_control(NAME_LOCK).items]))
if set_hide != HIDE_IGNORE and set_hide not in [k.name for k in self.browser.find_control(NAME_HIDE).items]:
raise self.Error, 'invalid hide constant "%s", valid types are [%s]' % (set_hide, ', '.join([k.name for k in self.browser.find_control(NAME_HIDE).items]))

# command is redundant?
if set_lock in [LOCK_IGNORE, self.browser[NAME_LOCK][0]] and set_hide in [HIDE_IGNORE, self.browser[NAME_HIDE][0]]:
if ignoreUnchanged:
return False

error = 'The global account "%s" is already ' % user
if lock != None:
error += 'locked' if lock else 'unlocked'
if hide != None:
if lock != None:
if set_lock != None:
error += 'locked' if set_lock == LOCK_YES else 'unlocked'
if set_hide != None:
if set_lock != None:
error += ' and '
error += 'hidden' if hide else 'unhidden'
error += 'hidden' if set_hide == HIDE_LISTS else 'globally oversighted' if set_hide == HIDE_SUPPRESSED else 'unhidden'
raise self.Error, error

# set values
if lock != None:
check_lock.selected = lock
if hide != None:
check_hide.selected = hide
self.browser.form['wpReason'] = reason

# modify form
if set_lock != LOCK_IGNORE:
control = self.browser.find_control(NAME_LOCK).get(set_lock).selected = True
if set_hide != HIDE_IGNORE:
control = self.browser.find_control(NAME_HIDE).get(set_hide).selected = True
self.browser["wpReason"] = reason
self.submit()
return True

##############
## Lock IP on Meta
##############
#if blockMeta && re_ip_address.match(user):
# self.block(
# user = user,
# expiry = 'never',
# reason = 'globally locked: "%s"' % reason,
# anononly = True,
# nocreate = True
# )


###################
## Get global rights
Expand Down
13 changes: 8 additions & 5 deletions stewardbot/Stewardbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ def handle_unhide( self, data ):
self.handleCentralAuthCommand( data )
def handle_lockhide( self, data ):
self.handleCentralAuthCommand( data )
def handle_globaloversight( self, data ):
self.handleCentralAuthCommand( data )
def handleCentralAuthCommand( self, data ):
self.trace()

Expand All @@ -339,13 +341,13 @@ def handleCentralAuthCommand( self, data ):
return

# prepare centralauth values
lock = True if command in ['lock', 'lockhide'] else False if command=='unlock' else None
lock = True if command in ['lock', 'hide', 'lockhide', 'globaloversight'] else False if command=='unlock' else None
hide = True if command in ['hide', 'lockhide'] else False if command=='unhide' else None
delete = True if command=='delete' else None
globalOversight = True if command == 'globaloversight' else None

# prepare reason
if len(args) <= REASON:
if lock or hide or delete:
if lock or hide:
args.append( config['web']['default_ca_reason'] )
else:
args.append('')
Expand All @@ -356,7 +358,8 @@ def handleCentralAuthCommand( self, data ):
user = args[USER],
reason = args[REASON],
lock = lock,
hide = hide
hide = hide,
oversightLocal = globalOversight
)
if self.options['confirm_all']:
self.respond( data, 'done' )
Expand Down Expand Up @@ -1295,4 +1298,4 @@ def handleAt( self, identifier ):
###################
def unhandleAt( self ):
self.trace()
self.browser.resetBaseUrl()
self.browser.resetBaseUrl()
6 changes: 4 additions & 2 deletions stewardbot/__config__.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
'wikimedia/GrooveDog':'GrooveDog',
'wikimedia/Innv':'Innv',
'wikimedia/Jamesofur':'Jamesofur',
'wikia/vstf/countervandalism.user.Grunny':'Grunny',
'Wikimedia/Kanonkas':'Kanonkas',
'wikimedia/Kylu':'Kylu',
'wikimedia/Maximillion-Pegasus':'Maximillion Pegasus',
Expand All @@ -108,7 +109,7 @@
'commands_by_level':{
_INDEX_OPEN:['help', 'activity', 'links', 'lookup', 'scanedits', 'showrights', 'translate', 'bash', 'debug', 'queue'],
_INDEX_USERS:['config', 'exit', 'reset'],
_INDEX_OPERATORS:['block', 'blockhide', 'checkuser', 'delete', 'lock', 'hide', 'lockhide', 'unlock', 'unhide', 'gblock', 'gunblock', 'setrights', 'stab', 'stabhide', 'unblock', 'wikiset', 'withlist', 'commit', 'cancel']
_INDEX_OPERATORS:['block', 'blockhide', 'checkuser', 'delete', 'lock', 'globaloversight', 'hide', 'lockhide', 'unlock', 'unhide', 'gblock', 'gunblock', 'setrights', 'stab', 'stabhide', 'unblock', 'wikiset', 'withlist', 'commit', 'cancel']
},
'commands_nocommit':['commit', 'cancel', 'checkuser', 'queue']
},
Expand Down Expand Up @@ -196,6 +197,7 @@
'lock':'lock a global account; syntax is \'!lock name\' or \'!lock name > reason\'',
'hide':'hide a global account; syntax is \'!hide name\' or \'!hide name > reason\'',
'lockhide':'lock and hide a global account; syntax is \'!lockhide name\' or \'!lockhide name > reason\'',
'globaloversight':'Lock and hide a global account, and oversight its local name on all local wikis (this will oversight them in edit histories, which may violate the oversight policy; use with care); syntax is \'!globalOversight name\'',
'unlock':'unlock a global account; syntax is \'!unlock name\' or \'!unlock name > reason\'',
'unhide':'unhide a global account; syntax is \'!unhide name\' or \'!unhide name > reason\'',

Expand All @@ -220,4 +222,4 @@
#'nuke':'revert all edits and moves by a user, and delete page creations',
'reset':'clear web sessions, reset base URL, disconnect from IRC and reconnect; syntax is \'!reset\' or \'!reset quit reason\'',
'setrights':'add or remove a user\'s right-groups. Groups are listed with commas, and by default each group is added. Add \'+\' or \'-\' before a name to switch between addition and removal for subsequent groups. Syntax is \'!setrights user > +right1,right2,-right3\' or \'!setrights user > +right1,-right2,+right3 > reason\'',
}
}

0 comments on commit d6ab515

Please sign in to comment.