1"""Objects representing obsolete MediaWiki sites."""
2#
3# (C) Pywikibot team, 2019-2021
4#
5# Distributed under the terms of the MIT license.
6#
7import pywikibot
8from pywikibot.exceptions import NoPageError
9from pywikibot.site._apisite import APISite
10from pywikibot.site._basesite import BaseSite
11from pywikibot.tools import remove_last_args
12
13
14class RemovedSite(BaseSite):
15
16    """Site removed from a family."""
17
18    pass
19
20
21class ClosedSite(APISite):
22    """Site closed to read-only mode."""
23
24    @remove_last_args(['sysop'])
25    def __init__(self, code, fam, user=None):
26        """Initializer."""
27        super().__init__(code, fam, user)
28
29    def _closed_error(self, notice=''):
30        """An error instead of pointless API call."""
31        pywikibot.error('Site {} has been closed. {}'.format(self.sitename,
32                                                             notice))
33
34    def page_restrictions(self, page):
35        """Return a dictionary reflecting page protections."""
36        if not self.page_exists(page):
37            raise NoPageError(page)
38        if not hasattr(page, '_protection'):
39            page._protection = {'edit': ('steward', 'infinity'),
40                                'move': ('steward', 'infinity'),
41                                'delete': ('steward', 'infinity'),
42                                'upload': ('steward', 'infinity'),
43                                'create': ('steward', 'infinity')}
44        return page._protection
45
46    def recentchanges(self, **kwargs):
47        """An error instead of pointless API call."""
48        self._closed_error('No recent changes can be returned.')
49
50    def is_uploaddisabled(self):
51        """Return True if upload is disabled on site."""
52        if not hasattr(self, '_uploaddisabled'):
53            self._uploaddisabled = True
54        return self._uploaddisabled
55
56    def newpages(self, **kwargs):
57        """An error instead of pointless API call."""
58        self._closed_error('No new pages can be returned.')
59
60    def newfiles(self, **kwargs):
61        """An error instead of pointless API call."""
62        self._closed_error('No new files can be returned.')
63