Rewrite get_disc_link to handle special cases
Use methods of pywikibot site-object and mwparser to get rid of any special elements like templates or links in headings for construction of our disc link. Replace by hand as it otherwise will occur as normal space and wont work Related Task: [FS#147](https://fs.golderweb.de/index.php?do=details&task_id=147)
This commit is contained in:
@@ -611,22 +611,22 @@ class RedFamWorker( RedFam ):
|
|||||||
@rtype str
|
@rtype str
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# We need to Replace Links with their linktext
|
# Expand templates using pwb site object
|
||||||
anchor_code = mwparser.parse( self.heading.strip() )
|
site = pywikibot.Site()
|
||||||
for link in anchor_code.ifilter_wikilinks():
|
anchor_code = site.expand_text(self.heading.strip())
|
||||||
if link.text:
|
|
||||||
text = link.text
|
|
||||||
else:
|
|
||||||
text = link.title
|
|
||||||
|
|
||||||
anchor_code.replace( link, text )
|
# Remove possibly embbeded files
|
||||||
|
anchor_code = re.sub( r"\[\[\w+:[^\|]+(?:\|.+){2,}\]\]", "",
|
||||||
|
anchor_code )
|
||||||
|
|
||||||
# Whitespace is replaced with underscores
|
# Replace non-breaking-space by correct urlencoded value
|
||||||
anchor_code.replace( " ", "_" )
|
anchor_code = anchor_code.replace( " ", ".C2.A0" )
|
||||||
|
|
||||||
# We try it with out any more parsing as mw will do while parsing page
|
# Use mwparser to strip and normalize
|
||||||
return ( self.redpage.pagetitle + "#" +
|
anchor_code = mwparser.parse( anchor_code ).strip_code()
|
||||||
str(anchor_code).strip() )
|
|
||||||
|
# We try it without any more parsing as mw will do while parsing page
|
||||||
|
return ( self.redpage.pagetitle + "#" + anchor_code.strip() )
|
||||||
|
|
||||||
def generate_disc_notice_template( self ):
|
def generate_disc_notice_template( self ):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user