def usercontributions(self, user, start=None, end=None, direc='older', namespace=None, prop=None, show=None, limit=None, uselang=None): """ List the contributions made by a given user to the wiki API doc: https://www.mediawiki.org/wiki/API:Usercontribs """ kwargs = dict( listing.List.generate_kwargs('uc', user=user, start=start, end=end, direc=direc, namespace=namespace, prop=prop, show=show)) return listing.List(self, 'usercontribs', 'uc', limit=limit, uselang=uselang, **kwargs)
def watchlist(self, allrev=False, start=None, end=None, namespace=None, direc='older', prop=None, show=None, limit=None): """ List the pages on the current user's watchlist. API doc: https://www.mediawiki.org/wiki/API:Watchlist """ kwargs = dict( listing.List.generate_kwargs('wl', start=start, end=end, namespace=namespace, direc=direc, prop=prop, show=show)) if allrev: kwargs['wlallrev'] = '1' return listing.List(self, 'watchlist', 'wl', limit=limit, **kwargs)
def users(self, users, prop='blockinfo|groups|editcount'): """ Get information about a list of users. API doc: https://www.mediawiki.org/wiki/API:Users """ return listing.List(self, 'users', 'us', ususers='|'.join(users), usprop=prop)
def random(self, namespace, limit=20): """Retrieve a generator of random pages from a particular namespace. limit specifies the number of random articles retrieved. namespace is a namespace identifier integer. Generator contains dictionary with namespace, page ID and title. """ kwargs = dict(listing.List.generate_kwargs('rn', namespace=namespace)) return listing.List(self, 'random', 'rn', limit=limit, **kwargs)
def deletedrevisions(self, start=None, end=None, direc='older', namespace=None, limit=None, prop='user|comment'): # TODO: Fix kwargs = dict( listing.List.generate_kwargs('dr', start=start, end=end, direc=direc, namespace=namespace, prop=prop)) return listing.List(self, 'deletedrevs', 'dr', limit=limit, **kwargs)
def allusers(self, start=None, prefix=None, group=None, prop=None, limit=None, witheditsonly=False, activeusers=False, rights=None, end=None): """Retrieve all users on the wiki as a generator.""" kwargs = dict( listing.List.generate_kwargs('au', ('from', start), ('to', end), prefix=prefix, group=group, prop=prop, rights=rights, witheditsonly=witheditsonly, activeusers=activeusers)) return listing.List(self, 'allusers', 'au', limit=limit, **kwargs)
def search(self, search, namespace='0', what=None, redirects=False, limit=None): """Perform a full text search. API doc: https://www.mediawiki.org/wiki/API:Search Example: >>> for result in site.search('prefix:Template:Citation/'): ... print(result.get('title')) Args: search (str): The query string namespace (int): The namespace to search (default: 0) what (str): Search scope: 'text' for fulltext, or 'title' for titles only. Depending on the search backend, both options may not be available. For instance `CirrusSearch <https://www.mediawiki.org/wiki/Help:CirrusSearch>`_ doesn't support 'title', but instead provides an "intitle:" query string filter. redirects (bool): Include redirect pages in the search (option removed in MediaWiki 1.23). Returns: mwklient.listings.List: Search results iterator """ kwargs = dict( listing.List.generate_kwargs('sr', search=search, namespace=namespace, what=what)) if redirects: kwargs['srredirects'] = '1' return listing.List(self, 'search', 'sr', limit=limit, **kwargs)
def logevents(self, type_t=None, prop=None, start=None, end=None, direc='older', user=None, title=None, limit=None, action=None): """Retrieve logevents as a generator.""" kwargs = dict( listing.List.generate_kwargs('le', prop=prop, type_t=type_t, start=start, end=end, direc=direc, user=user, title=title, action=action)) return listing.List(self, 'logevents', 'le', limit=limit, **kwargs)
def recentchanges(self, start=None, end=None, direc='older', namespace=None, prop=None, show=None, limit=None, type_t=None, toponly=None): """List recent changes to the wiki, à la Special:Recentchanges. """ kwargs = dict( listing.List.generate_kwargs('rc', start=start, end=end, direc=direc, namespace=namespace, prop=prop, show=show, type_t=type_t, toponly='1' if toponly else None)) return listing.List(self, 'recentchanges', 'rc', limit=limit, **kwargs)
def blocks(self, start=None, end=None, direc='older', ids=None, users=None, limit=None, prop='id|user|by|timestamp|expiry|reason|flags'): """Retrieve blocks as a generator. Returns: mwklient.listings.List: Generator yielding dicts, each dict containing: - user: The username or IP address of the user - id: The ID of the block - timestamp: When the block was added - expiry: When the block runs out (infinity for indefinite blocks) - reason: The reason they are blocked - allowusertalk: Key is present (empty string) if the user is allowed to edit their user talk page - by: the administrator who blocked the user - nocreate: key is present (empty string) if the user's ability to create accounts has been disabled. """ # TODO: Fix. Fix what? kwargs = dict( listing.List.generate_kwargs('bk', start=start, end=end, direc=direc, ids=ids, users=users, prop=prop)) return listing.List(self, 'blocks', 'bk', limit=limit, **kwargs)
def exturlusage(self, query, prop=None, protocol='http', namespace=None, limit=None): r"""Retrieve the list of pages that link to a particular domain or URL, as a generator. This API call mirrors the Special:LinkSearch function on-wiki. Query can be a domain like 'bbc.co.uk'. Wildcards can be used, e.g. '\*.bbc.co.uk'. Alternatively, a query can contain a full domain name and some or all of a URL: e.g. '\*.wikipedia.org/wiki/\*' See <https://meta.wikimedia.org/wiki/Help:Linksearch> for details. Returns: mwklient.listings.List: Generator yielding dicts, each dict containing: - url: The URL linked to. - ns: Namespace of the wiki page - pageid: The ID of the wiki page - title: The page title. """ kwargs = dict( listing.List.generate_kwargs('eu', query=query, prop=prop, protocol=protocol, namespace=namespace)) return listing.List(self, 'exturlusage', 'eu', limit=limit, **kwargs)