コード例 #1
0
    def treat(self, page: pywikibot.Page) -> None:
        change = page._rcinfo
        if not (change["type"] == "edit" or change["type"] == "new"):
            return

        username = change["user"]
        greetedUserInfo = self.redisDb.getGreetedUserInfo(username)
        if greetedUserInfo:
            title = change["title"]
            newRevision = change["revision"]["new"]
            if change["timestamp"] < float(greetedUserInfo["time"]):
                # event before greeting
                pywikibot.warn(
                    f"Received event before greeting for user '{username}', rev id {newRevision}"
                )
                return
            if page.namespace() == 3 and title[title.index(":") +
                                               1:] == username:
                # user edited his own talk page for the first time after being greeted
                self.redisDb.removeGreetedUser(username)
                self.notifyGreeter(greetedUserInfo["greeter"], username,
                                   newRevision, True)
            elif greetedUserInfo["normalEditSeen"] == "0":
                # user edited somewhere else for the first time after being greeted
                greetedUserInfo["normalEditSeen"] = "1"
                self.redisDb.setGreetedUserInfo(username, greetedUserInfo)
                self.notifyGreeter(greetedUserInfo["greeter"], username,
                                   newRevision, False)
コード例 #2
0
 def skip_page(self, page: pywikibot.Page) -> bool:
     """Skip special/media pages"""
     if page.namespace() < 0:
         return True
     elif not page.exists():
         return True
     elif page.isRedirectPage():
         return True
     return super().skip_page(page)
コード例 #3
0
 def skip_page(self, page: pywikibot.Page) -> bool:
     """Skip non-drafts and drafts with the template."""
     if page.namespace() != 118:
         pywikibot.warning('{} is not a draft.'.format(page))
         return True
     if has_template(page, self.opt.template):
         pywikibot.warning('{} already has the template.'.format(page))
         return True
     return super().skip_page(page)
コード例 #4
0
ファイル: archivebot.py プロジェクト: CCXXXI/pywikibot
def template_title_regex(tpl_page: pywikibot.Page) -> Pattern:
    """
    Return a regex that matches to variations of the template title.

    It supports the transcluding variant as well as localized namespaces and
    case-insensitivity depending on the namespace.

    :param tpl_page: The template page
    :type tpl_page: pywikibot.page.Page
    """
    ns = tpl_page.site.namespaces[tpl_page.namespace()]
    marker = '?' if ns.id == 10 else ''
    title = tpl_page.title(with_ns=False)
    title = case_escape(ns.case, title)

    return re.compile(r'(?:(?:%s):)%s%s' % ('|'.join(ns), marker, title))
コード例 #5
0
ファイル: archivebot.py プロジェクト: xqt/pywikibot
def template_title_regex(tpl_page: pywikibot.Page) -> Pattern:
    """
    Return a regex that matches to variations of the template title.

    It supports the transcluding variant as well as localized namespaces and
    case-insensitivity depending on the namespace.

    @param tpl_page: The template page
    @type tpl_page: pywikibot.page.Page
    """
    ns = tpl_page.site.namespaces[tpl_page.namespace()]
    marker = '?' if ns.id == 10 else ''
    title = tpl_page.title(with_ns=False)
    if ns.case != 'case-sensitive':
        title = '[{}{}]{}'.format(re.escape(title[0].upper()),
                                  re.escape(title[0].lower()),
                                  re.escape(title[1:]))
    else:
        title = re.escape(title)

    return re.compile(r'(?:(?:%s):)%s%s' % ('|'.join(ns), marker, title))
コード例 #6
0
ファイル: wikimedia_sync.py プロジェクト: florentk/wikifundi
def getPageSrcDstFromTitle(src, dst, pageTitle):
    p = Page(src, pageTitle)
    ns = p.namespace()

    # specific case for "Project pages"
    # TODO : use an option !
    if (ns.id == 4 or ns.id == 102):
        if (ns.subpages):
            subPage = pageTitle.split("/", 1)
            if (len(subPage) > 1):
                title = subPage[1]
            else:
                title = pageTitle
    else:
        title = pageTitle

    newPage = Page(dst, title)

    if (newPage.site != dst):
        newPage = Page(dst, newPage.titleWithoutNamespace(), ns.id)

    return (p, newPage, ns)
コード例 #7
0
 def skip_page(self, page: pywikibot.Page) -> bool:
     if page.namespace() < 0:
         return True
     if not page.exists():
         return True
     return super().skip_page(page)
コード例 #8
0
def process_list(type, formatter_class):
    """
    Post notifications about a certain type of deletions

    @param type: Deletion type
    @type type: str
    @param formatter_class: Class to be used for formatting messages
    @type formatter_class: commonsbot.formatters.Formatter
    """
    filename = 'lists/%s.txt' % type
    if not os.path.isfile(filename) or not os.path.exists(filename):
        return
    file = open(filename, 'r', encoding='utf8')
    lines = [s.strip() for s in file.readlines()]
    file.close()

    file_states = {}

    def load(store):
        nonlocal file_states
        (file_states, _) = store.load_state(lines, type)

    with_store(load)
    mapper = PerWikiMapper(NOTIFS_PER_WIKI)
    notified_files = set()

    for filename in lines:
        file = FilePage(commons, filename)
        if filename in file_states:
            state = file_states[filename]
        else:
            print('No deletion state found for %s, stubbing' % filename,
                  file=sys.stderr)
            state = DeletionState(filename, type, 'new')
            file_states[filename] = state
        state.file_page = file
        if type == 'discussion':
            state.load_discussion_info(commons)
            page = Page(commons, state.discussion_page)
            if not page.exists():
                print(
                    "Discussion page %s doesn't exist, not notifying about this file"
                    % page,
                    file=sys.stderr)
                continue

        pageset = file.globalusage(MAX_GLOBALUSAGE)
        for page in pageset:
            wiki = page.site.dbName()
            if wiki not in config.wikis:
                continue
            if page.namespace() != Namespace.MAIN:
                continue

            talk_page = page.toggleTalkPage()
            if talk_page.isRedirectPage():
                continue
            if not talk_page.botMayEdit():
                continue
            if talk_page.exists() and not talk_page.canBeEdited():
                continue
            mapper.add(filename, page)

    for page, files in mapper.files_per_page():
        states = []
        for filename in files:
            state = file_states[filename]
            states.append(state)

        try:
            spam_notifications(type, formatter_class, page.toggleTalkPage(),
                               states)
        except:
            # Error - save state to avoid reposting and then rethrow
            failed = set(states)
            failed_only = failed - notified_files

            def save(store):
                store.set_failure(type, list(failed_only))
                store.set_state(type, list(notified_files), 'notified')

            with_store(save)
            raise

        notified_files.update(states)

    with_store(lambda store: store.set_state(type, list(file_states.values()),
                                             'notified'))
コード例 #9
0
 def skip_page(self, page: pywikibot.Page) -> bool:
     """Sikp the page if it is in userspace."""
     if page.namespace().id in {2, 3}:
         pywikibot.warning(f"{page!r} is in userspace.")
         return True
     return super().skip_page(page)