Skip to content
Snippets Groups Projects
Commit 7f1ff5b5 authored by Dan Michael O. Heggø's avatar Dan Michael O. Heggø
Browse files

Code cleanup

Remove more version checks that are no longer needed
parent 71e3a05a
No related branches found
No related tags found
No related merge requests found
......@@ -143,7 +143,7 @@ class Site(object):
else:
raise errors.MediaWikiVersionError('Unknown generator %s' % self.site['generator'])
# Require 1.16
# Require MediaWiki version >= 1.16
self.require(1, 16)
# User info
......@@ -330,8 +330,6 @@ class Site(object):
def login(self, username=None, password=None, cookies=None, domain=None):
"""Login to the wiki."""
if self.initialized:
self.require(1, 10)
if username and password:
self.credentials = (username, password, domain)
......@@ -474,17 +472,16 @@ class Site(object):
result = self.api('parse', **kwargs)
return result['parse']
# def block: requires 1.12
# def unblock: requires 1.12
# def patrol: requires 1.14
# def import: requires 1.15
# def block(self): TODO?
# def unblock: TODO?
# def patrol: TODO?
# def import: TODO?
# Lists
def allpages(self, start=None, prefix=None, namespace='0', filterredir='all',
minsize=None, maxsize=None, prtype=None, prlevel=None,
limit=None, dir='ascending', filterlanglinks='all', generator=True):
"""Retrieve all pages on the wiki as a generator."""
self.require(1, 9)
pfx = listing.List.get_prefix('ap', generator)
kwargs = dict(listing.List.generate_kwargs(pfx, ('from', start), prefix=prefix,
......@@ -492,13 +489,13 @@ class Site(object):
namespace=namespace, filterredir=filterredir, dir=dir,
filterlanglinks=filterlanglinks))
return listing.List.get_list(generator)(self, 'allpages', 'ap', limit=limit, return_values='title', **kwargs)
# def allimages(self): requires 1.12
# def allimages(self):
# TODO!
def alllinks(self, start=None, prefix=None, unique=False, prop='title',
namespace='0', limit=None, generator=True):
"""Retrieve a list of all links on the wiki as a generator."""
self.require(1, 11)
pfx = listing.List.get_prefix('al', generator)
kwargs = dict(listing.List.generate_kwargs(pfx, ('from', start), prefix=prefix,
......@@ -509,7 +506,6 @@ class Site(object):
def allcategories(self, start=None, prefix=None, dir='ascending', limit=None, generator=True):
"""Retrieve all categories on the wiki as a generator."""
self.require(1, 12)
pfx = listing.List.get_prefix('ac', generator)
kwargs = dict(listing.List.generate_kwargs(pfx, ('from', start), prefix=prefix, dir=dir))
......@@ -518,7 +514,6 @@ class Site(object):
def allusers(self, start=None, prefix=None, group=None, prop=None, limit=None,
witheditsonly=False, activeusers=False, rights=None):
"""Retrieve all users on the wiki as a generator."""
self.require(1, 11)
kwargs = dict(listing.List.generate_kwargs('au', ('from', start), prefix=prefix,
group=group, prop=prop,
......@@ -544,7 +539,6 @@ class Site(object):
"""
self.require(1, 12)
# TODO: Fix. Fix what?
kwargs = dict(listing.List.generate_kwargs('bk', start=start, end=end, dir=dir,
users=users, prop=prop))
......@@ -553,7 +547,6 @@ class Site(object):
def deletedrevisions(self, start=None, end=None, dir='older', namespace=None,
limit=None, prop='user|comment'):
# TODO: Fix
self.require(1, 12)
kwargs = dict(listing.List.generate_kwargs('dr', start=start, end=end, dir=dir,
namespace=namespace, prop=prop))
......@@ -577,7 +570,6 @@ class Site(object):
- title: the page title.
"""
self.require(1, 11)
kwargs = dict(listing.List.generate_kwargs('eu', query=query, prop=prop,
protocol=protocol, namespace=namespace))
......@@ -585,7 +577,6 @@ class Site(object):
def logevents(self, type=None, prop=None, start=None, end=None,
dir='older', user=None, title=None, limit=None, action=None):
self.require(1, 10)
kwargs = dict(listing.List.generate_kwargs('le', prop=prop, type=type, start=start,
end=end, dir=dir, user=user, title=title, action=action))
......@@ -601,21 +592,18 @@ class Site(object):
Generator contains dictionary with namespace, page ID and title.
"""
self.require(1, 12)
kwargs = dict(listing.List.generate_kwargs('rn', namespace=namespace))
return listing.List(self, 'random', 'rn', limit=limit, **kwargs)
def recentchanges(self, start=None, end=None, dir='older', namespace=None,
prop=None, show=None, limit=None, type=None):
self.require(1, 9)
kwargs = dict(listing.List.generate_kwargs('rc', start=start, end=end, dir=dir,
namespace=namespace, prop=prop, show=show, type=type))
return listing.List(self, 'recentchanges', 'rc', limit=limit, **kwargs)
def search(self, search, namespace='0', what='title', redirects=False, limit=None):
self.require(1, 11)
kwargs = dict(listing.List.generate_kwargs('sr', search=search, namespace=namespace, what=what))
if redirects:
......@@ -624,20 +612,17 @@ class Site(object):
def usercontributions(self, user, start=None, end=None, dir='older', namespace=None,
prop=None, show=None, limit=None):
self.require(1, 9)
kwargs = dict(listing.List.generate_kwargs('uc', user=user, start=start, end=end,
dir=dir, namespace=namespace, prop=prop, show=show))
return listing.List(self, 'usercontribs', 'uc', limit=limit, **kwargs)
def users(self, users, prop='blockinfo|groups|editcount'):
self.require(1, 12)
return listing.List(self, 'users', 'us', ususers='|'.join(users), usprop=prop)
def watchlist(self, allrev=False, start=None, end=None, namespace=None, dir='older',
prop=None, show=None, limit=None):
self.require(1, 9)
kwargs = dict(listing.List.generate_kwargs('wl', start=start, end=end,
namespace=namespace, dir=dir, prop=prop, show=show))
......@@ -647,7 +632,6 @@ class Site(object):
def expandtemplates(self, text, title=None, generatexml=False):
"""Takes wikitext (text) and expands templates."""
self.require(1, 11)
kwargs = {}
if title is None:
......
......@@ -101,7 +101,6 @@ class Page(object):
return level in self.site.rights
def get_token(self, type, force=False):
self.site.require(1, 11)
if type not in self.site.tokens:
self.site.tokens[type] = '0'
......@@ -114,7 +113,6 @@ class Page(object):
return self.site.tokens[type]
def get_expanded(self):
self.site.require(1, 12)
revs = self.revisions(prop='content', limit=1, expandtemplates=True)
try:
......@@ -223,7 +221,6 @@ class Page(object):
raise
def get_expanded(self):
self.site.require(1, 12)
revs = self.revisions(prop='content', limit=1, expandtemplates=True)
try:
......@@ -292,8 +289,6 @@ class Page(object):
# Properties
def backlinks(self, namespace=None, filterredir='all', redirect=False, limit=None, generator=True):
self.site.require(1, 9)
# Fix title for < 1.11 !!
prefix = listing.List.get_prefix('bl', generator)
kwargs = dict(listing.List.generate_kwargs(prefix,
namespace=namespace, filterredir=filterredir))
......@@ -304,7 +299,6 @@ class Page(object):
return listing.List.get_list(generator)(self.site, 'backlinks', 'bl', limit=limit, return_values='title', **kwargs)
def categories(self, generator=True):
self.site.require(1, 11)
if generator:
return listing.PagePropertyGenerator(self, 'categories', 'cl')
else:
......@@ -312,8 +306,6 @@ class Page(object):
return listing.PageProperty(self, 'categories', 'cl', return_values='title')
def embeddedin(self, namespace=None, filterredir='all', redirect=False, limit=None, generator=True):
self.site.require(1, 9)
# Fix title for < 1.11 !!
prefix = listing.List.get_prefix('ei', generator)
kwargs = dict(listing.List.generate_kwargs(prefix,
namespace=namespace, filterredir=filterredir))
......@@ -324,26 +316,21 @@ class Page(object):
return listing.List.get_list(generator)(self.site, 'embeddedin', 'ei', limit=limit, return_values='title', **kwargs)
def extlinks(self):
self.site.require(1, 11)
return listing.PageProperty(self, 'extlinks', 'el', return_values='*')
def images(self, generator=True):
self.site.require(1, 9)
if generator:
return listing.PagePropertyGenerator(self, 'images', '')
else:
return listing.PageProperty(self, 'images', '', return_values='title')
def iwlinks(self):
self.site.require(1, 9) # guessing...
return listing.PageProperty(self, 'iwlinks', 'iw', return_values=('prefix', '*'))
def langlinks(self, **kwargs):
self.site.require(1, 9)
return listing.PageProperty(self, 'langlinks', 'll', return_values=('lang', '*'), **kwargs)
def links(self, namespace=None, generator=True, redirects=False):
self.site.require(1, 9)
kwargs = dict(listing.List.generate_kwargs('pl', namespace=namespace))
if redirects:
kwargs['redirects'] = '1'
......@@ -355,7 +342,6 @@ class Page(object):
def revisions(self, startid=None, endid=None, start=None, end=None,
dir='older', user=None, excludeuser=None, limit=50,
prop='ids|timestamp|flags|comment|user', expandtemplates=False, section=None):
self.site.require(1, 8)
kwargs = dict(listing.List.generate_kwargs('rv', startid=startid, endid=endid,
start=start, end=end, user=user, excludeuser=excludeuser))
kwargs['rvdir'] = dir
......@@ -368,7 +354,6 @@ class Page(object):
return listing.RevisionsIterator(self, 'revisions', 'rv', limit=limit, **kwargs)
def templates(self, namespace=None, generator=True):
self.site.require(1, 8)
kwargs = dict(listing.List.generate_kwargs('tl', namespace=namespace))
if generator:
return listing.PagePropertyGenerator(self, 'templates', 'tl')
......@@ -379,7 +364,6 @@ class Page(object):
class Image(Page):
def __init__(self, site, name, info=None):
site.require(1, 11)
Page.__init__(self, site, name, info,
extra_properties={'imageinfo':
(('iiprop', 'timestamp|user|comment|url|size|sha1|metadata|archivename'), )
......@@ -393,8 +377,6 @@ class Image(Page):
def imageusage(self, namespace=None, filterredir='all', redirect=False,
limit=None, generator=True):
self.site.require(1, 11)
# TODO: Fix for versions < 1.11
prefix = listing.List.get_prefix('iu', generator)
kwargs = dict(listing.List.generate_kwargs(prefix, title=self.name,
namespace=namespace, filterredir=filterredir))
......@@ -404,7 +386,6 @@ class Image(Page):
limit=limit, return_values='title', **kwargs)
def duplicatefiles(self, limit=None):
self.require(1, 14)
return listing.PageProperty(self, 'duplicatefiles', 'df',
dflimit=limit)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment