Пример #1
0
def convert_redirect(r):
    before = r['revisions'][0]['*']
    redir = mwbot.parse_redirect(before)
    if redir and redir[0].startswith('http'):
        text = '{{#exturl:%s}}' % redir[0].strip()
        if redir[1] and redir[1] != r['title'].split('/')[-1].replace(
                '_', ' '):
            text += '\n[[Hat Linkbeschreibung::%s]]' % redir[1]
        mwbot.save(site, r['title'], before, text,
                   'verwende #exturl Parserfunktion')
Пример #2
0
def handle(site, page):
	result = site.complete(titles=page, generator='links', redirects=True, prop='revisions', rvprop='content', gpllimit='max')

	classes_per_title = {}

	for bsp in result['pages'].values():
		classes = []
		if not 'missing' in bsp:
			bspcode = mwbot.parse(bsp['revisions'][0]['*'])
			if bspcode.filter_templates(matches=lambda t: t.name.matches('ungelöst')):
				continue

			templates = bspcode.filter_templates(matches=lambda t: t.name.matches('Beispiel'))
			if len(templates):
				tpl = templates[0]

				if tpl.has('teils') and tpl.get('teils').value.strip() != '':
					classes.append('beispiel-teils')

				status = tpl.get('status').value.strip().lower() if tpl.has('status') else None

				if status in ('datei', 'extern'):
					classes.append('beispiel-{}'.format(status))
				elif tpl.has('1') and tpl.get('1').value.strip() != '':
					classes.append('beispiel-wikicode')
		if classes:
			classes_per_title[bsp['title']] = classes
			if 'redirects' in result:
				for r in result['redirects']:
					if r['to'] == bsp['title']:
						classes_per_title[r['from']] = classes
						if not bsp['title'].startswith(page):
							classes_per_title[r['from']].append('beispiel-redirect')

	idxpage = next(site.results(prop='revisions', titles=page, rvprop='content'))
	code = mwbot.parse(idxpage['revisions'][0]['*'])

	for table in code.filter_tags(matches=lambda t: t.tag.matches('table')):
		table.attributes.clear()
		table.attributes.append(' class=beispiel-table')
		for td in table.contents.filter_tags(matches=lambda t: t.tag.matches('td')):
			links = td.contents.filter_wikilinks()
			if len(links) == 1:
				if links[0].title.startswith('/'):
					td.attributes.clear()
					title = page + str(links[0].title)
					if title in classes_per_title:
						td.attributes.append('class="{}"'.format(' '.join(classes_per_title[title])))
				else:
					logging.info('found non-relative link')
			else:
				logging.info('found cell with {} links'.format(len(links)))

	mwbot.save(site, page, idxpage['revisions'][0]['*'], str(code), site.msg('update'))
Пример #3
0
def handle_page(page):
    before = page['revisions'][0]['*']
    code = mwbot.parse(before)
    templates = code.filter_templates(matches=lambda t: t.name.matches('Room'))
    rcode = page['title'].split(':')[-1]
    if templates and rcode in rooms:
        msg = handle_template(templates[0], rooms[rcode], page['ns'])
        mwbot.save(site,
                   page['title'],
                   before,
                   str(code),
                   site.msg(msg),
                   strip_consec_nl=True)
Пример #4
0
def handle_page(page):
    before = page['revisions'][0]['*']
    code = mwbot.parse(before)
    templates = code.filter_templates(
        matches=lambda t: t.name.matches('LVA-Daten'))
    if templates:
        msg = handle_template(templates[0], code, page['ns'])
        mwbot.save(site,
                   page['title'],
                   before,
                   str(code),
                   site.msg(msg),
                   strip_consec_nl=True)
Пример #5
0
def handle_page(page):
    before = page['revisions'][0]['*']
    code = mwbot.parse(before)
    templates = code.filter_templates(
        matches=lambda t: t.name.matches('RaumCode'))
    if templates:
        msg = handle_template(templates[0], code, page['ns'])
        mwbot.save(site,
                   page['title'],
                   before,
                   str(code).replace('[[Kategorie:Raumcode]]', ''),
                   site.msg(msg),
                   strip_consec_nl=True)
Пример #6
0
def handle_page(page):
    orig = page['revisions'][0]['*']
    code = mwbot.parse(orig)
    for div in code.ifilter_tags(matches=lambda x: x.tag == 'div'):
        code.replace(div, div.contents)
    new = str(code).strip()
    if not code.filter_templates(
            matches=lambda x: x.name.matches('Baustein footer')):
        new += '\n{{Baustein footer}}'
    if not code.filter_headings():
        new = '====== ' + page['title'].split(':')[1] + ' ======\n' + new
    mwbot.save(site, page['title'], orig, new,
               'fixe Textbaustein (bausteien_fixer.py)')
    if mwbot.santitle(page['title'].split(':')[1]) not in templates:
        undocumented_templates.append(page['title'].split(':')[1])
Пример #7
0
def convert_file(r):
    text = r['revisions'][0]['*']
    parts = text.split("<!-- Don't edit below this line! -->")
    after = parts[0]
    if len(parts) == 2:
        for line in parts[1].splitlines():
            match = re.match('\[\[([^]]+)\]\]', line)
            if match:
                title = match.group(1).strip().replace('_', ' ')
                if not title.startswith('Kategorie'):
                    after += '{{#attach:%s}}\n' % title
    else:
        print('cannot handle', r['title'])

    mwbot.save(site, r['title'], text, after,
               'verwende #attach Parserfunktion')
Пример #8
0
                        gcmlimit='max',
                        **kwargs)


def check_category(tplclass, *additional_classes):
    errors = collections.defaultdict(list)
    kwargs = {}
    if hasattr(tplclass, 'NAMESPACES'):
        kwargs['gcmnamespace'] = mwbot.join(tplclass.NAMESPACES)
    for page in catmembers_with_revs(tplclass.CATEGORY, **kwargs):
        code = mwbot.parse(page['revisions'][0]['*'])
        for error in check_template(code, tplclass):
            errors[page['title']].append(error)
        for ac in additional_classes:
            for error in check_template(code, ac):
                errors[page['title']].append(error)
    return generate_section(tplclass.CATEGORY, errors)


if __name__ == '__main__':
    parser = mwbot.get_argparser()
    args = parser.parse_args()

    site = mwbot.getsite('report.py', args)
    report = '{{Sonstiges Leiste}}\nGenerated by ~~~~\n'
    report += check_category(LVADaten, Zuordnung)
    report += check_category(AbteilungDaten)
    report += check_category(KatalogDaten)
    report += check_category(Beispiel)
    mwbot.save(site, 'VoWi:Report', None, report, 'update')
Пример #9
0
               'fixe Textbaustein (bausteien_fixer.py)')
    if mwbot.santitle(page['title'].split(':')[1]) not in templates:
        undocumented_templates.append(page['title'].split(':')[1])


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    overview = 'Hilfe:Vorlagen für Beispiele'
    mwbot.add_pagesel_args(parser,
                           categorydefault='Textbausteine für Beispiele')
    args = parser.parse_args()
    site = mwbot.getsite()

    page = next(
        site.query('pages',
                   prop='revisions',
                   titles=overview,
                   rvprop='content'))
    orig = page['revisions'][0]['*']
    code = mwbot.parse(orig)
    templates = [mwbot.santitle(t.name) for t in code.ifilter_templates()]
    undocumented_templates = []

    mwbot.handle_pagesel_args(site, args, (mwapi.NS_TEMPLATE, ), handle_page)
    undocumented_templates.sort()
    new = orig
    for t in undocumented_templates:
        new += '\n{{%s}}' % t
    mwbot.save(site, overview, orig, new,
               '+nichteingeordnete Vorlagen (baustein_fixer.py)')
Пример #10
0
                    if 'duplicatefiles' in page:
                        for dup in page['duplicatefiles']:
                            duplicates.append('Datei:' +
                                              dup['name'].replace('_', ' '))
                    break
                else:
                    excluded += 1

    for ns in vowi.UNI_NAMESPACES:
        for p in site.results(list='allpages',
                              apfilterredir='nonredirects',
                              apnamespace=ns,
                              aplimit='max'):
            if '/' in p['title']:
                if not p['title'].split('/', 1)[0] in current_lvas:
                    excluded += 1

    return excluded


if __name__ == '__main__':
    parser = mwbot.get_argparser()
    args = parser.parse_args()

    site = mwbot.getsite('excluded_mat_counter.py', args)

    count = count_excluded_resources()
    print(count)
    mwbot.save(site, 'Vorlage:!materialien anzahl/exkludiert', None, count,
               site.msg('update'))
Пример #11
0
def handle(site, index):
    src_ns = next(site.results(prop='info', titles=index))['ns']

    for page in site.results(generator='allpages',
                             gapprefix=index.split(':')[1] + '/Beispiel ',
                             gaplimit='max',
                             prop='revisions',
                             rvprop='content',
                             gapnamespace=src_ns):
        orig = page['revisions'][0]['*']
        if mwbot.parse_redirect(orig):
            continue

        code = mwbot.parse(orig)
        templates = code.filter_templates(
            matches=lambda x: x.name.matches('Beispiel'))
        if len(templates) > 0:
            template = templates[0]
        else:
            template = Template(Wikicode([Text('Beispiel')]))
            code.insert(0, template)
            code.insert(1, '\n')

        # legacy format handling
        template.name = 'Beispiel'
        if template.has('1') and not template.get('1').value.startswith('\n'):
            template.get('1').value.insert(0, '\n')
        if template.has('status'):
            if str(template.get('status').value).strip() not in ('extern',
                                                                 'Datei'):
                print('unknown status: {}'.format(k))

        if template.has('1'):
            if str(template.get('1').value).strip() == 'teils':
                template.add('teils', '')
                template.remove('1')
            elif str(template.get('1').value).strip() == 'falsch':
                template.add('falsch', '')
                template.remove('1')

        if not template.has('1'):
            angabe_div = code.filter_tags(
                matches=lambda x: x.tag.matches('blockquote') or len([
                    x for x in x.attributes
                    if '{{Angabe}}' in x or '#EFEFEF' in x
                ]))
            if angabe_div:
                template.add('1',
                             '\n' + str(angabe_div[0].contents).strip() + '\n',
                             showkey=True)
                code.remove(angabe_div[0])
            else:
                angabe_sec = code.get_sections(matches='Angabe|Aufgabe')
                if angabe_sec:
                    code.remove(angabe_sec[0].nodes[0])
                    template.add('1',
                                 '\n' + str(angabe_sec[0]).strip() + '\n',
                                 showkey=True)
                    code.replace(angabe_sec[0], '\n')

        mwbot.save(site,
                   page['title'],
                   orig,
                   str(code),
                   'beispiel_fixer.py',
                   strip_consec_nl=True)