Ejemplo n.º 1
0
 def test_basic(self):
     """Test adding text."""
     (text, newtext, always) = add_text(self.page,
                                        'bar',
                                        putText=False,
                                        oldTextGiven='foo\n{{linkfa}}')
     self.assertEqual('foo\n{{linkfa}}\nbar', newtext)
Ejemplo n.º 2
0
 def test_with_category(self):
     """Test adding text before categories."""
     (_, newtext, _) = add_text(self.page,
                                'bar',
                                putText=False,
                                oldTextGiven='foo\n[[Category:Foo]]')
     self.assertEqual('foo\nbar\n\n[[Category:Foo]]', newtext)
Ejemplo n.º 3
0
    def addCommonscat(self, page):
        """
        Add CommonsCat template to page.

        Take a page. Go to all the interwiki page looking for a commonscat
        template. When all the interwiki's links are checked and a proper
        category is found add it to the page.

        """
        self.current_page = page
        # Get the right templates for this page
        primaryCommonscat, commonscatAlternatives = self.getCommonscatTemplate(
            page.site.code)
        commonscatLink = self.getCommonscatLink(page)
        if commonscatLink:
            pywikibot.output('Commonscat template is already on %s' %
                             page.title())
            (currentCommonscatTemplate, currentCommonscatTarget, LinkText,
             Note) = commonscatLink
            checkedCommonscatTarget = self.checkCommonscatLink(
                currentCommonscatTarget)
            if (currentCommonscatTarget == checkedCommonscatTarget):
                # The current commonscat link is good
                pywikibot.output('Commonscat link at %s to Category:%s is ok' %
                                 (page.title(), currentCommonscatTarget))
                return True
            elif checkedCommonscatTarget != '':
                # We have a new Commonscat link, replace the old one
                self.changeCommonscat(page, currentCommonscatTemplate,
                                      currentCommonscatTarget,
                                      primaryCommonscat,
                                      checkedCommonscatTarget, LinkText, Note)
                return True
            else:
                # Commonscat link is wrong
                commonscatLink = self.findCommonscatLink(page)
                if (commonscatLink != ''):
                    self.changeCommonscat(page, currentCommonscatTemplate,
                                          currentCommonscatTarget,
                                          primaryCommonscat, commonscatLink)
                # TODO: if the commonsLink == '', should it be removed?

        elif self.skipPage(page):
            pywikibot.output('Found a template in the skip list. Skipping %s' %
                             page.title())
        else:
            commonscatLink = self.findCommonscatLink(page)
            if (commonscatLink != ''):
                if commonscatLink == page.title():
                    textToAdd = '{{%s}}' % primaryCommonscat
                else:
                    textToAdd = '{{%s|%s}}' % (primaryCommonscat,
                                               commonscatLink)
                rv = add_text(page,
                              textToAdd,
                              self.getOption('summary'),
                              always=self.getOption('always'))
                self.options['always'] = rv[2]
                return True
        return True
Ejemplo n.º 4
0
    def addCommonscat(self, page):
        """
        Add CommonsCat template to page.

        Take a page. Go to all the interwiki page looking for a commonscat
        template. When all the interwiki's links are checked and a proper
        category is found add it to the page.

        """
        self.current_page = page
        # Get the right templates for this page
        primaryCommonscat, commonscatAlternatives = self.getCommonscatTemplate(
            page.site.code)
        commonscatLink = self.getCommonscatLink(page)
        if commonscatLink:
            pywikibot.output(u'Commonscat template is already on %s'
                             % page.title())
            (currentCommonscatTemplate,
             currentCommonscatTarget, LinkText, Note) = commonscatLink
            checkedCommonscatTarget = self.checkCommonscatLink(
                currentCommonscatTarget)
            if (currentCommonscatTarget == checkedCommonscatTarget):
                # The current commonscat link is good
                pywikibot.output(u'Commonscat link at %s to Category:%s is ok'
                                 % (page.title(), currentCommonscatTarget))
                return True
            elif checkedCommonscatTarget != u'':
                # We have a new Commonscat link, replace the old one
                self.changeCommonscat(page, currentCommonscatTemplate,
                                      currentCommonscatTarget,
                                      primaryCommonscat,
                                      checkedCommonscatTarget, LinkText, Note)
                return True
            else:
                # Commonscat link is wrong
                commonscatLink = self.findCommonscatLink(page)
                if (commonscatLink != u''):
                    self.changeCommonscat(page, currentCommonscatTemplate,
                                          currentCommonscatTarget,
                                          primaryCommonscat, commonscatLink)
                # TODO: if the commonsLink == u'', should it be removed?

        elif self.skipPage(page):
            pywikibot.output("Found a template in the skip list. Skipping %s"
                             % page.title())
        else:
            commonscatLink = self.findCommonscatLink(page)
            if (commonscatLink != u''):
                if commonscatLink == page.title():
                    textToAdd = u'{{%s}}' % primaryCommonscat
                else:
                    textToAdd = u'{{%s|%s}}' % (primaryCommonscat,
                                                commonscatLink)
                rv = add_text(page, textToAdd,
                              self.getOption('summary'),
                              always=self.getOption('always'))
                self.options['always'] = rv[2]
                return True
        return True
 def test_basic(self):
     """Test adding text."""
     page = pywikibot.Page(self.site, 'foo')
     (text, newtext, always) = add_text(page,
                                        'bar',
                                        putText=False,
                                        oldTextGiven='foo\n{{linkfa}}')
     self.assertEqual('foo\n{{linkfa}}\nbar', newtext)
 def test_with_params(self):
     """Test adding text before {{linkfa|...}}."""
     page = pywikibot.Page(self.site, 'foo')
     (text, newtext, always) = add_text(page,
                                        'bar',
                                        putText=False,
                                        oldTextGiven='foo\n{{linkfa|...}}')
     self.assertEqual('foo\nbar\n\n{{linkfa|...}}\n', newtext)
Ejemplo n.º 7
0
 def test_with_category(self):
     """Test adding text before categories."""
     page = pywikibot.Page(self.site, 'foo')
     (text, newtext, always) = add_text(
         page, 'bar', putText=False,
         oldTextGiven='foo\n[[Category:Foo]]')
     self.assertEqual(
         'foo\nbar\n\n[[Category:Foo]]',
         newtext)
Ejemplo n.º 8
0
 def test_basic(self):
     """Test adding text."""
     page = pywikibot.Page(self.site, 'foo')
     (text, newtext, always) = add_text(
         page, 'bar', putText=False,
         oldTextGiven='foo\n{{linkfa}}')
     self.assertEqual(
         'foo\n{{linkfa}}\nbar',
         newtext)
 def test_with_category(self):
     """Test adding text before categories."""
     page = pywikibot.Page(self.site, 'foo')
     (text, newtext,
      always) = add_text(page,
                         'bar',
                         putText=False,
                         oldTextGiven='foo\n[[Category:Foo]]')
     self.assertEqual('foo\nbar\n\n[[Category:Foo]]', newtext)
Ejemplo n.º 10
0
 def test_with_params(self):
     """Test adding text before {{linkfa|...}}."""
     page = pywikibot.Page(self.site, 'foo')
     (text, newtext, always) = add_text(
         page, 'bar', putText=False,
         oldTextGiven='foo\n{{linkfa|...}}')
     self.assertEqual(
         'foo\nbar\n\n{{linkfa|...}}\n',
         newtext)
Ejemplo n.º 11
0
    def treat_page(self):
        """
        Add CommonsCat template to page.

        Take a page. Go to all the interwiki page looking for a commonscat
        template. When all the interwiki's links are checked and a proper
        category is found add it to the page.
        """
        page = self.current_page
        # Get the right templates for this page
        primaryCommonscat, commonscatAlternatives = i18n.translate(
            page.site.code,
            commonscatTemplates,
            fallback=i18n.DEFAULT_FALLBACK)
        commonscatLink = self.getCommonscatLink(page)
        if commonscatLink:
            pywikibot.output('Commonscat template is already on ' +
                             page.title())
            (currentCommonscatTemplate, currentCommonscatTarget, LinkText,
             Note) = commonscatLink
            checkedCommonscatTarget = self.checkCommonscatLink(
                currentCommonscatTarget)

            if (currentCommonscatTarget == checkedCommonscatTarget):
                # The current commonscat link is good
                pywikibot.output(
                    'Commonscat link at {} to Category:{} is ok'.format(
                        page.title(), currentCommonscatTarget))
                return

            if checkedCommonscatTarget:
                # We have a new Commonscat link, replace the old one
                self.changeCommonscat(page, currentCommonscatTemplate,
                                      currentCommonscatTarget,
                                      primaryCommonscat,
                                      checkedCommonscatTarget, LinkText, Note)
                return

            # Commonscat link is wrong
            commonscatLink = self.find_commons_category(page)
            if commonscatLink:
                self.changeCommonscat(page, currentCommonscatTemplate,
                                      currentCommonscatTarget,
                                      primaryCommonscat, commonscatLink)
            # TODO: if the commonsLink == '', should it be removed?

        elif self.skipPage(page):
            pywikibot.output('Found a template in the skip list. Skipping ' +
                             page.title())
        else:
            commonscatLink = self.find_commons_category(page)
            if commonscatLink:
                if commonscatLink == page.title():
                    textToAdd = '{{%s}}' % primaryCommonscat
                else:
                    textToAdd = '{{%s|%s}}' % (primaryCommonscat,
                                               commonscatLink)
                result, _, always = add_text(page,
                                             textToAdd,
                                             self.opt.summary,
                                             always=self.opt.always)
                if result is True:
                    self._save_counter += 1
                self.opt.always = always