diff --git a/wapiti/operations/__init__.py b/wapiti/operations/__init__.py index 33af04e..9659550 100644 --- a/wapiti/operations/__init__.py +++ b/wapiti/operations/__init__.py @@ -15,7 +15,7 @@ import revisions import templates import user - +import query_operations for op in OperationMeta._all_ops: globals()[op.__name__] = op diff --git a/wapiti/operations/misc.py b/wapiti/operations/misc.py index dbf7a57..45022c2 100644 --- a/wapiti/operations/misc.py +++ b/wapiti/operations/misc.py @@ -105,67 +105,6 @@ def extract_results(self, query_resp): ret.append(page_ident) return ret - -class GetQueryPage(QueryOperation): - field_prefix = 'qp' - input_field = SingleParam('page') - fields = [StaticParam('list', 'querypage')] - output_type = QueryPageInfo - known_qps = ['Ancientpages', - 'BrokenRedirects', - 'Deadendpages', - 'Disambiguations', - 'DoubleRedirects', - 'Listredirects', - 'Lonelypages', - 'Longpages', - 'Mostcategories', - 'Mostimages', - 'Mostinterwikis', - 'Mostlinkedcategories', - 'Mostlinkedtemplates', - 'Mostlinked', - 'Mostrevisions', - 'Fewestrevisions', - 'Shortpages', - 'Uncategorizedcategories', - 'Uncategorizedpages', - 'Uncategorizedimages', - 'Uncategorizedtemplates', - 'Unusedcategories', - 'Unusedimages', - 'Wantedcategories', - 'Wantedfiles', - 'Wantedpages', - 'Wantedtemplates', - # 'Unwatchedpages', # requires logging in - 'Unusedtemplates', - 'Withoutinterwiki'] - - def __init__(self, qp, *a, **kw): - if qp not in self.known_qps: - raise ValueError('Unrecognized query page: %r' % qp) - super(GetQueryPage, self).__init__(qp, *a, **kw) - - def extract_results(self, query_resp): - ret = [] - cached = query_resp['querypage'].get('cachedtimestamp') - name = query_resp['querypage'].get('name') - for p in query_resp['querypage']['results']: - page = QueryPageInfo(p['title'], - p['ns'], - p['value'], - name, - cached) - ret.append(page) - return ret - - def prepare_params(self, **kw): - params = super(GetQueryPage, self).prepare_params(**kw) - if params.get('qpcontinue'): - params['qpoffset'] = params.pop('qpcontinue') - return params - ''' If we are completionists (for action=query) @@ -212,8 +151,6 @@ def prepare_params(self, **kw): Perform a full text search * list=tags (tg) * List change tags -* list=usercontribs (uc) * - Get all edits by a user * list=users (us) * Get information about a list of users * list=abuselog (afl) * diff --git a/wapiti/operations/models.py b/wapiti/operations/models.py index 10920f7..d489925 100644 --- a/wapiti/operations/models.py +++ b/wapiti/operations/models.py @@ -477,3 +477,17 @@ def __init__(self, coord, page_ident=None): else: self.primary = False return + + +class QueryPageInfo(object): + def __init__(self, + title, + ns, + value, + querypage, + cache): + self.title = title + self.ns = ns + self.value = value + self.querypage = querypage + self.cache = cache diff --git a/wapiti/operations/query_operations.py b/wapiti/operations/query_operations.py new file mode 100644 index 0000000..4df6cd3 --- /dev/null +++ b/wapiti/operations/query_operations.py @@ -0,0 +1,181 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from base import QueryOperation +from params import SingleParam, StaticParam + +from models import PageInfo + + +class GetQueryPage(QueryOperation): + field_prefix = 'gqp' + input_field = SingleParam('page') + fields = [StaticParam('generator', 'querypage'), + StaticParam('prop', 'info'), + StaticParam('inprop', 'subjectid|talkid|protection')] + output_type = PageInfo + + def extract_results(self, query_resp): + ret = [] + for k, pid_dict in query_resp['pages'].iteritems(): + try: + page = PageInfo.from_query(pid_dict, + source=self.source) + except ValueError: + # no page_id? + continue + ret.append(page) + return ret + + def prepare_params(self, **kw): + params = super(GetQueryPage, self).prepare_params(**kw) + if params.get('gqpcontinue'): + params['gqpoffset'] = params.pop('ggqpcontinue') + return params + + +class GetAncientPages(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Ancientpages')] + + +class GetBrokenRedirects(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'BrokenRedirects')] + + +class GetDeadendPages(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Deadendpages')] + + +class GetDisambiguations(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Disambiguations')] + + +class GetDoubleRedirects(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Doulberedirects')] + + +class GetListRedirects(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Listredirects')] + + +class GetLonelyPages(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Lonelypages')] + + +class GetLongPages(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Longpages')] + + +class GetMostCategories(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Mostcategories')] + + +class GetMostImages(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Mostimages')] + + +class GetMostInterwikiLinks(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Mostinterwikis')] + + +class GetMostLinkedCategories(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Mostlinkedcategories')] + + +class GetMostLinkedTemplates(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Mostlinkedtemplates')] + + +class GetMostLinked(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Mostlinked')] + + +class GetMostRevisions(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Mostrevisions')] + + +class GetFewestRevisions(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Fewestrevisions')] + + +class GetShortPages(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Shortpages')] + + +class GetUncategorizedCategories(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Uncategorizedcategories')] + + +class GetUncategorizedPages(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Uncategorizedpages')] + + +class GetUncategorizedImages(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Uncategorizedimages')] + + +class GetUncategorizedTemplates(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Uncategorizedtemplates')] + + +class GetUnusedCategories(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Unusedcategories')] + + +class GetUnusedImages(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Unusedimages')] + + +class GetWantedCategories(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Wantedcategories')] + + +class GetWantedFiles(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Wantedfiles')] + + +class GetWantedPages(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Wantedpages')] + + +class GetWantedTemplates(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Wantedtemplates')] + + +class GetUnusedTemplates(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Unusedtemplates')] + + +class GetWithoutInterwikiLinks(GetQueryPage): + input_field = None + fields = GetQueryPage.fields + [StaticParam('gqppage', 'Withoutinterwiki')] + +# 'Unwatchedpages' requires being logged in