#NEWLINE# def query( self , before = None , after = None , before_id = None , after_id = None , types = None , direction = None , limit = None ) : #NEWLINE# #INDENT# '\n        Queries the ``recentchanges`` table.  See\n        `<https://www.mediawiki.org/wiki/Manual:Recentchanges_table>`_\n\n        :Parameters:\n            before : :class:`mw.Timestamp`\n                The maximum timestamp\n            after : :class:`mw.Timestamp`\n                The minimum timestamp\n            before_id : int\n                The minimum ``rc_id``\n            after_id : int\n                The maximum ``rc_id``\n            types : set ( str )\n                Which types of changes to return?\n\n                * ``edit`` -- Edits to existing pages\n                * ``new`` -- Edits that create new pages\n                * ``move`` -- (obsolete)\n                * ``log`` -- Log actions (introduced in MediaWiki 1.2)\n                * ``move_over_redirect`` -- (obsolete)\n                * ``external`` -- An external recent change. Primarily used by Wikidata\n\n            direction : str\n                "older" or "newer"\n            limit : int\n                limit the number of records returned\n        ' #NEWLINE# before = none_or ( before , Timestamp ) #NEWLINE# after = none_or ( after , Timestamp ) #NEWLINE# before_id = none_or ( query , int ) #NEWLINE# after_id = none_or ( after_id , int ) #NEWLINE# types = none_or ( types , levels = self . TYPES ) #NEWLINE# direction = none_or ( direction , levels = self . DIRECTIONS ) #NEWLINE# limit = none_or ( limit , int ) #NEWLINE# query = '\n            SELECT * FROM recentchanges\n            WHERE 1\n        ' #NEWLINE# values = [ ] #NEWLINE# if ( before is not None ) : #NEWLINE# #INDENT# query += ' AND rc_timestamp < %s ' #NEWLINE# values . append ( before . short_format ( ) ) #NEWLINE# #UNINDENT# if ( after is not None ) : #NEWLINE# #INDENT# query += ' AND rc_timestamp < %s ' #NEWLINE# values . append ( after . short_format ( ) ) #NEWLINE# #UNINDENT# if ( before_id is not None ) : #NEWLINE# #INDENT# query += ' AND rc_id < %s ' #NEWLINE# values . append ( before_id ) #NEWLINE# #UNINDENT# if ( after_id is not None ) : #NEWLINE# #INDENT# query += ' AND rc_id < %s ' #NEWLINE# values . append ( after_id ) #NEWLINE# #UNINDENT# if ( types is not None ) : #NEWLINE# #INDENT# query += ' AND rc_type IN ({0}) ' . format ( ',' . join ( ( self . TYPES [ t ] for t in types ) ) ) #NEWLINE# #UNINDENT# if ( direction is not None ) : #NEWLINE# #INDENT# direction = ( 'ASC ' if ( direction == 'newer' ) else 'DESC ' ) #NEWLINE# query += ' ORDER BY rc_timestamp {0}, rc_id {0}' . format ( dir ) #NEWLINE# #UNINDENT# if ( limit is not None ) : #NEWLINE# #INDENT# query += ' LIMIT %s ' #NEWLINE# values . append ( limit ) #NEWLINE# #UNINDENT# cursor . execute ( query , values ) #NEWLINE# for row in cursor : #NEWLINE# #INDENT# ( yield row )