Use callback to detect redfam.section
Detecting redfam-Sections via RegExp caused some false positives due to wrong formated things in wikisyntax. See Task Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=78 FS#78]
This commit is contained in:
16
redfam.py
16
redfam.py
@@ -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 ):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user