Merge branch 'fs#78-redfam-section-false-positives' into fs#70-refactoring

This commit is contained in:
2016-08-24 20:05:04 +02:00
2 changed files with 19 additions and 2 deletions

View File

@@ -341,6 +341,22 @@ class RedFamParser( RedFam ):
else: else:
return False return False
@classmethod
def is_section_redfam_cb( cls, heading ):
"""
Used as callback for wikicode.get_sections in redpage.parse to
select sections which are redfams
"""
# Because of strange behavior in some cases, parse heading again
# (Task FS#77)
heading = mwparser.parse( str( heading ) )
# Make sure we have min. two wikilinks in heading to assume a redfam
if len( heading.filter_wikilinks() ) >= 2:
return True
else:
return False
@classmethod @classmethod
def parser( cls, text, page, isarchive=False ): def parser( cls, text, page, isarchive=False ):
""" """

View File

@@ -28,9 +28,10 @@ Provides a class for handling redundance discussion pages and archives
import pywikibot # noqa import pywikibot # noqa
import mwparserfromhell as mwparser import mwparserfromhell as mwparser
import jogobot import jogobot # noqa
from mysqlred import MysqlRedPage from mysqlred import MysqlRedPage
from redfam import RedFamParser
class RedPage: class RedPage:
@@ -116,7 +117,7 @@ class RedPage:
# include_lead = if true include first section (intro) # include_lead = if true include first section (intro)
# include_heading = if true include heading # include_heading = if true include heading
fams = self.wikicode.get_sections( fams = self.wikicode.get_sections(
matches=jogobot.config["redundances"]["section_heading_regex"], matches=RedFamParser.is_section_redfam_cb,
include_lead=False, include_headings=True ) include_lead=False, include_headings=True )
# Iterate over RedFam # Iterate over RedFam