Пример #1
0
    def touch(self, cat):
        """
        Touch a single category.

        If a file isn't listed in the table, append it.
        """
        cattext = cat.get()
        table = {}
        change = False
        for image in cat.articles():
            if not image.isImage() or image.title() in cattext:
                continue
            pywikibot.output(u'File %s is not listed' % image.title())
            uploader = image.getFirstUploader()[0]
            if uploader not in table:
                table[uploader] = []
            table[uploader].append(image)
        for key in table:
            if textlib.does_text_contain_section(cattext, u'\[\[%s\]\]' % key):
                newcattext = re.sub('(== \[\[%s\]\] ==.*?)\r?\n\r?\n== \[\['
                                    % key,
                                    '\1' + '######', cattext)
                print(newcattext)
                pass  # TODO: Ergänze bei vorhandenem Uploader
            else:
                pywikibot.output(u'Uploader %s is not listed' % key)
                cattext = self.add_uploader_info(cattext, key, table[key])
                change = True
        if change:
            self.save(cat, cattext, u'Bot: Ergänze Dateien mit Aufschub')
        else:
            cat.put(cattext)
Пример #2
0
 def get_target(page):
     """Get the target page for a given page."""
     target = None
     if not page.exists():
         with suppress(pywikibot.NoMoveTarget,
                       pywikibot.CircularRedirect,
                       pywikibot.InvalidTitle):
             target = page.moved_target()
     elif page.isRedirectPage():
         try:
             target = page.getRedirectTarget()
         except (pywikibot.CircularRedirect,
                 pywikibot.InvalidTitle):
             pass
         except RuntimeError:
             pywikibot.exception()
         else:
             section = target.section()
             if section and not does_text_contain_section(target.text,
                                                          section):
                 pywikibot.warning(
                     'Section #{} not found on page {}'
                     .format(section, target.title(as_link=True,
                                                   with_section=False)))
                 target = None
     return target
Пример #3
0
    def get_target(self, page):
        """Get the target page for a given page."""
        target = None
        if not page.exists():
            if not self.opt.ignoremoves:
                with suppress(NoMoveTargetError, CircularRedirectError,
                              InvalidTitleError):
                    target = page.moved_target()
        elif page.isRedirectPage():
            try:
                target = page.getRedirectTarget()
            except (CircularRedirectError, InvalidTitleError,
                    InterwikiRedirectPageError):
                pass
            except RuntimeError:
                pywikibot.exception()
            else:
                section = target.section()
                if section and not does_text_contain_section(
                        target.text, section):
                    pywikibot.warning(
                        'Section #{} not found on page {}'.format(
                            section,
                            target.title(as_link=True, with_section=False)))
                    target = None

        if target is not None \
           and target.namespace() in [2, 3] and page.namespace() not in [2, 3]:
            target = None
        return page, target
Пример #4
0
    def treat_page(self):
        """Change all redirects from the current page to actual links."""
        links = self.current_page.linkedPages()
        newtext = self.current_page.text
        i = None
        for i, page in enumerate(links):
            if not page.exists():
                try:
                    target = page.moved_target()
                except (pywikibot.NoMoveTarget,
                        pywikibot.CircularRedirect,
                        pywikibot.InvalidTitle):
                    continue
            elif page.isRedirectPage():
                try:
                    target = page.getRedirectTarget()
                except (pywikibot.CircularRedirect,
                        pywikibot.InvalidTitle):
                    continue
                else:
                    section = target.section()
                    if section and not does_text_contain_section(target.text,
                                                                 section):
                        pywikibot.warning(
                            'Section #{0} not found on page {1}'.format(
                                section, target.title(asLink=True,
                                                      withSection=False)))
                        continue
            else:
                continue
            # no fix to user namespaces
            if target.namespace() in [2, 3] and page.namespace() not in [2, 3]:
                continue
            newtext = self.replace_links(newtext, page, target)

        if i is None:
            pywikibot.output('Nothing left to do.')
        else:
            self.put_current(newtext)
    def treat_page(self):
        """Change all redirects from the current page to actual links."""
        links = self.current_page.linkedPages()
        newtext = self.current_page.text
        i = None
        for i, page in enumerate(links):
            if not page.exists():
                try:
                    target = page.moved_target()
                except (pywikibot.NoMoveTarget,
                        pywikibot.CircularRedirect,
                        pywikibot.InvalidTitle):
                    continue
            elif page.isRedirectPage():
                try:
                    target = page.getRedirectTarget()
                except (pywikibot.CircularRedirect,
                        pywikibot.InvalidTitle):
                    continue
                else:
                    section = target.section()
                    if section and not does_text_contain_section(target.text,
                                                                 section):
                        pywikibot.warning(
                            'Section #{0} not found on page {1}'.format(
                                section, target.title(asLink=True,
                                                      withSection=False)))
                        continue
            else:
                continue
            # no fix to user namespaces
            if target.namespace() in [2, 3] and page.namespace() not in [2, 3]:
                continue
            newtext = self.replace_links(newtext, page, target)

        if i is None:
            pywikibot.output('Nothing left to do.')
        else:
            self.put_current(newtext)
Пример #6
0
    def inform(self, user, **param):
        """
        Inform user about deletion request.

        @param user: user to be informed
        @type user: pywikibot.User
        @keyword page: page title
        @type page: str
        @keyword action: action done by editor
        @type action: str
        """
        talk = user.getUserTalkPage()
        while talk.isRedirectPage():
            talk = talk.getRedirectTarget()
            if talk == user.getUserTalkPage():
                pywikibot.output(u'WARNING: %s forms a redirect loop. Skipping'
                                 % talk)
                return
        if not talk.isTalkPage():
            pywikibot.output(u'WARNING: %s is not a talk page. Skipping' % talk)
            return
        if talk.exists():
            text = talk.text + u'\n\n'
            if textlib.does_text_contain_section(text,
                                                 u'[[%(page)s]]' % param):
                pywikibot.output(u'NOTE: user %s was already informed'
                                 % user.name())
                return
        else:
            text = u''
        param['user'] = user.name()
        text += msg % param
        if not self.userPut(talk, talk.text, text, minor=False,
                            summary=self.summary % param,
                            ignore_save_related_errors=True,
                            ignore_server_errors=True):
            pywikibot.warning('Page %s not saved.' % talk)
Пример #7
0
 def contains(self, fn, sn):
     return textlib.does_text_contain_section(files[fn], sn)
Пример #8
0
 def contains(self, fn, sn):
     return textlib.does_text_contain_section(
         files[fn], sn)