]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/mw/api/collections/site_info.py
Initial commit
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / mw / api / collections / site_info.py
1 import logging
2
3 from ..errors import MalformedResponse
4 from .collection import Collection
5
6 logger = logging.getLogger("mw.api.collections.site_info")
7
8
9 class SiteInfo(Collection):
10     """
11     General information about the site.
12     """
13
14     PROPERTIES = {'general', 'namespaces', 'namespacealiases',
15                   'specialpagealiases', 'magicwords', 'interwikimap',
16                   'dbrepllag', 'statistics', 'usergroups', 'extensions',
17                   'fileextensions', 'rightsinfo', 'languages', 'skins',
18                   'extensiontags', 'functionhooks', 'showhooks',
19                   'variables', 'protocols'}
20
21     FILTERIW = {'local', '!local'}
22
23     def query(self, properties=None, filteriw=None, showalldb=None,
24               numberinggroup=None, inlanguagecode=None):
25         """
26         General information about the site.
27         See `<https://www.mediawiki.org/wiki/API:Meta#siteinfo_.2F_si>`_
28
29         :Parameters:
30             properties: set(str)
31                 Which sysinfo properties to get:
32
33                 * general               - Overall system information
34                 * namespaces            - List of registered namespaces and their canonical names
35                 * namespacealiases      - List of registered namespace aliases
36                 * specialpagealiases    - List of special page aliases
37                 * magicwords            - List of magic words and their aliases
38                 * statistics            - Returns site statistics
39                 * interwikimap          - Returns interwiki map (optionally filtered, (optionally localised by using siinlanguagecode))
40                 * dbrepllag             - Returns database server with the highest replication lag
41                 * usergroups            - Returns user groups and the associated permissions
42                 * extensions            - Returns extensions installed on the wiki
43                 * fileextensions        - Returns list of file extensions allowed to be uploaded
44                 * rightsinfo            - Returns wiki rights (license) information if available
45                 * restrictions          - Returns information on available restriction (protection) types
46                 * languages             - Returns a list of languages MediaWiki supports(optionally localised by using siinlanguagecode)
47                 * skins                 - Returns a list of all enabled skins
48                 * extensiontags         - Returns a list of parser extension tags
49                 * functionhooks         - Returns a list of parser function hooks
50                 * showhooks             - Returns a list of all subscribed hooks (contents of $wgHooks)
51                 * variables             - Returns a list of variable IDs
52                 * protocols             - Returns a list of protocols that are allowed in external links.
53                 * defaultoptions        - Returns the default values for user preferences.
54             filteriw : str
55                 "local" or "!local" Return only local or only nonlocal entries of the interwiki map
56             showalldb : bool
57                 List all database servers, not just the one lagging the most
58             numberingroup : bool
59                 Lists the number of users in user groups
60             inlanguagecode : bool
61                 Language code for localised language names (best effort, use CLDR extension)
62   """
63
64         siprop = self._items(properties, levels=self.PROPERTIES)
65
66         doc = self.session.get(
67             {
68                 'action': "query",
69                 'meta': "siteinfo",
70                 'siprop': siprop,
71                 'sifilteriw': filteriw,
72                 'sishowalldb': showalldb,
73                 'sinumberinggroup': numberinggroup,
74                 'siinlanguagecode': inlanguagecode
75             }
76         )
77
78         try:
79             return doc['query']
80         except KeyError as e:
81             raise MalformedResponse(str(e), doc)

Community Data Science Collective || Want to submit a patch?