Ejemplo n.º 1
0
    def get_sd_template(self, site=None) -> Optional[str]:
        """Look for speedy deletion template and return it.

        @param site: site for which the template has to be given
        @type site: pywikibot.BaseSite
        @return: A valid speedy deletion template.
        """
        title = None
        if site:
            sd = self.opt.sdtemplate
            if not sd and i18n.twhas_key(site,
                                         'redirect-broken-redirect-template'):
                sd = i18n.twtranslate(site,
                                      'redirect-broken-redirect-template')

            # check whether template exists for this site
            if sd:
                template = extract_templates_and_params_regex_simple(sd)
                if template:
                    title = template[0][0]
                    page = pywikibot.Page(site, title, ns=10)
                    if page.exists():
                        return sd

        pywikibot.warning('No speedy deletion template {}available.'.format(
            '"{}" '.format(title) if title else ''))
        return None
Ejemplo n.º 2
0
            def test_template(self):
                """Test validity of template."""
                lang = site.lang
                if lang not in keys:
                    return

                if not i18n.twhas_key(lang, package):
                    return

                msg = i18n.twtranslate(lang, package, fallback=False)

                # check whether the message contains a template
                templates = extract_templates_and_params_regex_simple(msg)
                self.assertIsInstance(templates, list)
                self.assertIsNotEmpty(templates)

                # known problems
                if (package == PACKAGES[0]
                        and site.code in ['simple', 'test2']
                        or package == PACKAGES[1] and site.code == 'test'):
                    raise unittest.SkipTest(
                        "{site} wiki has '{site.lang}' language code but "
                        "missing template for package '{package}'. Must be "
                        'solved by the corresponding script.'.format(
                            site=site, package=package))

                # check whether template exists
                title = templates[0][0]
                page = pywikibot.Page(site, title, ns=10)
                self.assertTrue(page.exists(),
                                msg='Invalid L10N in package "{package}"\n'
                                'template "{title}" does not exist for lang '
                                '"{site.lang}" on site "{site}"'.format(
                                    package=package, title=title, site=site))
Ejemplo n.º 3
0
    def get_sd_template(self):
        """Look for speedy deletion template and return it.

        @return: A valid speedy deletion template.
        @rtype: str or None
        """
        if self.getOption('delete') and not self.site.logged_in(sysop=True):
            sd = self.getOption('sdtemplate')
            if not sd and i18n.twhas_key(self.site,
                                         'redirect-broken-redirect-template'):
                sd = i18n.twtranslate(self.site,
                                      'redirect-broken-redirect-template')
            # TODO: Add bot's signature if needed (Bug: T131517)

            # check whether template exists for this site
            title = None
            if sd:
                template = extract_templates_and_params_regex_simple(sd)
                if template:
                    title = template[0][0]
                    page = pywikibot.Page(self.site, title, ns=10)
                    if page.exists():
                        return sd
            pywikibot.warning(
                'No speedy deletion template {0}available.'
                ''.format('"{0}" '.format(title) if title else ''))
        return None
Ejemplo n.º 4
0
    def get_sd_template(self):
        """Look for speedy deletion template and return it.

        @return: A valid speedy deletion template.
        @rtype: str or None
        """
        if self.getOption('delete') and not self.site.logged_in(sysop=True):
            sd = self.getOption('sdtemplate')
            if not sd and i18n.twhas_key(self.site,
                                         'redirect-broken-redirect-template'):
                sd = i18n.twtranslate(self.site,
                                      'redirect-broken-redirect-template')
            # TODO: Add bot's signature if needed (Bug: T131517)

            # check whether template exists for this site
            title = None
            if sd:
                template = extract_templates_and_params_regex_simple(sd)
                if template:
                    title = template[0][0]
                    page = pywikibot.Page(self.site, title, ns=10)
                    if page.exists():
                        return sd
            pywikibot.warning(
                'No speedy deletion template {0}available.'
                ''.format('"{0}" '.format(title) if title else ''))
        return None
Ejemplo n.º 5
0
            def test_template(self):
                """Test validity of template."""
                lang = site.lang
                if lang not in keys:
                    return
                msg = i18n.twtranslate(lang, package, fallback=False)
                if msg:
                    # check whether the message contains a template
                    templates = extract_templates_and_params_regex_simple(msg)
                    self.assertIsInstance(templates, list)
                    self.assertIsNotEmpty(templates)

                    # known problem
                    if site.code == 'simple':
                        raise unittest.SkipTest(
                            "'simple' wiki has 'en' language code but "
                            'missing template. Must be solved by the '
                            'corresponding script.')
                    # check whether template exists
                    title = templates[0][0]
                    page = pywikibot.Page(site, title, ns=10)
                    self.assertTrue(
                        page.exists(),
                        msg='Invalid L10N in package "{package}"\n'
                        'template "{title}" does not exist for lang '
                        '"{site.lang}" on site "{site}"'
                        .format(package=package, title=title, site=site))
Ejemplo n.º 6
0
    def has_valid_content(self):
        """Test page only contains a single call to the index template."""
        if (not self.text.startswith('{{' + self.INDEX_TEMPLATE)
                or not self.text.endswith('}}')):
            return False

        # Discard all inner templates as only top-level ones matter
        templates = textlib.extract_templates_and_params_regex_simple(
            self.text)
        if len(templates) != 1 or templates[0][0] != self.INDEX_TEMPLATE:
            # Only a single call to the INDEX_TEMPLATE is allowed
            return False

        return True
Ejemplo n.º 7
0
            def test_template(self):
                """Test validity of template."""
                lang = site.lang
                if lang not in keys:
                    return
                msg = i18n.twtranslate(lang, package, fallback=False)
                if msg:
                    # check whether the message contains a template
                    templates = extract_templates_and_params_regex_simple(msg)
                    self.assertIsInstance(templates, list)
                    self.assertGreater(len(templates), 0)

                    # known problem
                    if site.code == 'simple':
                        raise unittest.SkipTest(
                            "'simple' wiki has 'en' language code but "
                            "missing template. Must be solved by the "
                            "corresponding script.")
                    # check whether template exists
                    title = templates[0][0]
                    page = pywikibot.Page(site, title, ns=10)
                    self.assertTrue(page.exists())
Ejemplo n.º 8
0
            def test_template(self):
                """Test validity of template."""
                lang = site.lang
                if lang not in keys:
                    return
                msg = i18n.twtranslate(lang, package, fallback=False)
                if msg:
                    # check whether the message contains a template
                    templates = extract_templates_and_params_regex_simple(msg)
                    self.assertIsInstance(templates, list)
                    self.assertGreater(len(templates), 0)

                    # known problem
                    if site.code == 'simple':
                        raise unittest.SkipTest(
                            "'simple' wiki has 'en' language code but "
                            "missing template. Must be solved by the "
                            "corresponding script.")
                    # check whether template exists
                    title = templates[0][0]
                    page = pywikibot.Page(site, title, ns=10)
                    self.assertTrue(page.exists())
Ejemplo n.º 9
0
    def has_valid_content(self) -> bool:
        """Test page only contains a single call to the index template."""
        text = self.text

        if not text.startswith('{{' + self.INDEX_TEMPLATE):
            return False

        # Discard possible categories after INDEX_TEMPLATE
        categories = textlib.getCategoryLinks(text, self.site)
        for cat in categories:
            text = text.replace('\n' + cat.title(as_link=True), '')

        if not text.endswith('}}'):
            return False

        # Discard all inner templates as only top-level ones matter
        templates = textlib.extract_templates_and_params_regex_simple(text)
        if len(templates) != 1 or templates[0][0] != self.INDEX_TEMPLATE:
            # Only a single call to the INDEX_TEMPLATE is allowed
            return False

        return True