Esempio n. 1
0
def diff_patrol(rev_id):
    if not submitted_request_valid():
        return 'CSRF error', 400
    session = authenticated_session()
    ids.append(flask.session, 'acted_page_ids', ids.rev_id_to_page_id(rev_id, session))
    token = session.get(action='query',
                        meta='tokens',
                        type='patrol')['query']['tokens']['patroltoken']
    session.post(action='patrol',
                 revid=rev_id,
                 token=token)
    return flask.redirect(flask.url_for('any_diff'))
Esempio n. 2
0
def diff_skip(rev_id):
    if not submitted_request_valid():
        return 'CSRF error', 400

    ids.append(flask.session, 'skipped_rev_ids', rev_id)

    page_id = ids.rev_id_to_page_id(rev_id, any_session())
    if page_id in ids.get(flask.session, 'skipped_page_ids'):
        if page_id not in ids.get(flask.session, 'acted_page_ids'):
            ids.append(flask.session, 'ignored_page_ids', page_id)
    else:
        ids.append(flask.session, 'skipped_page_ids', page_id)

    return flask.redirect(flask.url_for('any_diff'))
Esempio n. 3
0
def any_diff():
    if not user_logged_in():
        return flask.redirect(flask.url_for('login'))
    skipped_rev_ids = ids.get(flask.session, 'skipped_rev_ids')
    ignored_page_ids = ids.get(flask.session, 'ignored_page_ids')
    ignored_user_fake_ids = ids.get(flask.session, 'ignored_user_fake_ids')
    supported_scripts = flask.session.get('supported_scripts')
    try:
        for rev_id in ids.unpatrolled_changes(authenticated_session()):
            if rev_id in skipped_rev_ids:
                continue
            if ids.rev_id_to_page_id(rev_id,
                                     any_session()) in ignored_page_ids:
                continue
            if ids.rev_id_to_user_fake_id(
                    rev_id, any_session()) in ignored_user_fake_ids:
                continue
            if ids.rev_id_to_show_patrol_footer(rev_id,
                                                authenticated_session()):
                continue
            if supported_scripts is not None:
                diff_body = any_session().get(
                    action='compare',
                    fromrev=rev_id,
                    torelative='prev',
                    prop=['diff'],
                    uselang='en',
                    formatversion=2)['compare']['body']
                script = scripts.primary_script_of_diff(diff_body)
                if script is not None and script not in supported_scripts:
                    continue
            return flask.redirect(flask.url_for('diff', rev_id=rev_id))
    except mwapi.errors.APIError as error:
        # TODO use errorformat='html' once mwapi supports it (mediawiki-utilities/python-mwapi#34)
        info_html = any_session().get(action='parse',
                                      text=error.info,
                                      prop=['text'],
                                      wrapoutputclass=None,
                                      disablelimitreport=True,
                                      contentmodel='wikitext',
                                      formatversion=2)['parse']['text']
        return flask.render_template('permission-error.html',
                                     info=fix_markup(info_html))
Esempio n. 4
0
def any_diff():
    if not user_logged_in():
        return flask.redirect(flask.url_for('login'))
    skipped_rev_ids = ids.get(flask.session, 'skipped_rev_ids')
    ignored_page_ids = ids.get(flask.session, 'ignored_page_ids')
    supported_scripts = flask.session.get('supported_scripts')
    for rev_id in ids.unpatrolled_changes(authenticated_session()):
        if rev_id in skipped_rev_ids:
            continue
        if ids.rev_id_to_page_id(rev_id, any_session()) in ignored_page_ids:
            continue
        if supported_scripts is not None:
            diff_body = any_session().get(action='compare',
                                          fromrev=rev_id,
                                          torelative='prev',
                                          prop=['diff'],
                                          formatversion=2)['compare']['body']
            script = scripts.primary_script_of_diff(diff_body)
            if script is not None and script not in supported_scripts:
                continue
        return flask.redirect(flask.url_for('diff', rev_id=rev_id))
Esempio n. 5
0
def diff_rollback(rev_id):
    if not submitted_request_valid():
        return 'CSRF error', 400
    session = authenticated_session()
    ids.append(flask.session, 'acted_page_ids', ids.rev_id_to_page_id(rev_id, session))
    results = session.get(action='query',
                          meta='tokens',
                          type='rollback',
                          revids=[str(rev_id)],
                          prop='revisions',
                          rvprop='user',
                          formatversion='2')
    token = results['query']['tokens']['rollbacktoken']
    page = results['query']['pages'][0]
    pageid = page['pageid']
    user = page['revisions'][0]['user']
    try:
        session.post(action='rollback',
                     pageid=pageid,
                     user=user,
                     token=token)
    except mwapi.errors.APIError as error:
        # TODO use errorformat='html' once mwapi supports it (mediawiki-utilities/python-mwapi#34)
        info_html = session.get(action='parse',
                                text=error.info,
                                prop=['text'],
                                wrapoutputclass=None,
                                disablelimitreport=True,
                                contentmodel='wikitext',
                                formatversion=2)['parse']['text']
        return flask.render_template('rollback-error.html',
                                     rev_id=rev_id,
                                     user=user,
                                     info=flask.Markup(info_html))
    else:
        return flask.redirect(flask.url_for('any_diff'))