def error_068_interwiki_link(text):
"""
Fix links to Special:BookSearch and direct links, written like interwiki
ones. For example, for ruwiki fixes [[:ru:Example|Something]].
Return (new_text, replacements_count) tuple.
"""
def _check_link(match_obj):
"""Check if founded link is a link to a file or a category and insert extra ":" if so."""
link = match_obj.group(2).lstrip().lower()
if re.search(r"^" + IMAGE, link) is None and re.search(r"^" + CATEGORY, link) is None:
return match_obj.group(1) + match_obj.group(2)
else:
return match_obj.group(1) + ":" + match_obj.group(2)
# bot will not fix links without a pipe: manual control needed
(text, direct) = re.subn(r"(\[\[):{}:([^|\[\]\n]+\|[^|\[\]\n]+\]\])".format(LANG_CODE),
_check_link, text, flags=re.I)
(text, books) = re.subn(r"\[\[:..:Special:BookSources/\d+X?\|(ISBN [0-9\-X]+)\]\]",
"\\1", text, flags=re.I)
return (text, direct + books)
评论列表
文章目录