Revision: 4505 Author: btongminh Date: 2007-11-05 10:08:28 +0000 (Mon, 05 Nov 2007)
Log Message: ----------- New plugins: FrWikibooks
Modified Paths: -------------- trunk/pywikipedia/commonsdelinker/delinker.py
Added Paths: ----------- trunk/pywikipedia/commonsdelinker/plugins/books.py
Modified: trunk/pywikipedia/commonsdelinker/delinker.py =================================================================== --- trunk/pywikipedia/commonsdelinker/delinker.py 2007-11-05 07:00:05 UTC (rev 4504) +++ trunk/pywikipedia/commonsdelinker/delinker.py 2007-11-05 10:08:28 UTC (rev 4505) @@ -173,6 +173,13 @@ return 'failed' new_text = text + m_image = ImmutableByReference(image) + m_replacement = ImmutableByReference(replacement) + self.CommonsDelinker.exec_hook('before_replace', + (page, summary, m_image, m_replacement)) + image = m_image.get() + replacement = m_replacement.get() + def create_regex(s): s = re.escape(s) return ur'(?:[%s%s]%s)' % (s[0].upper(), s[0].lower(), s[1:]) @@ -190,7 +197,7 @@ if hook: if False is self.CommonsDelinker.exec_hook('%s_replace' % hook, (page, summary, image, m_replacement, match, groups)): - return u''.join(groups) + return u''.join(groups) if m_replacement.get() is None: return u'' @@ -246,7 +253,7 @@ hook = 'gallery' r_galleries = ur'(?s)(<%s>)(.*?)(</%s>)' % (create_regex_i('gallery'), create_regex_i('gallery')) - r_gallery = ur'(?m)^((?:%s)?)%s(\s*(?:|.*?)?\s*)$' % (r_namespace, r_image) + r_gallery = ur'(?m)^((?:%s)?)%s(\s*(?:|.*?)?\s*$)' % (r_namespace, r_image) def gallery_replacer(match): return ur'%s%s%s' % (match.group(1), re.sub(r_gallery, simple_replacer, match.group(2)), match.group(3))
Added: trunk/pywikipedia/commonsdelinker/plugins/books.py =================================================================== --- trunk/pywikipedia/commonsdelinker/plugins/books.py (rev 0) +++ trunk/pywikipedia/commonsdelinker/plugins/books.py 2007-11-05 10:08:28 UTC (rev 4505) @@ -0,0 +1,15 @@ +__version__ = '$Id: $' + +import re + +class FrPhotographie(object): + hook = 'before_replace' + def __init__(self, CommonsDelinker): + self.CommonsDelinker = CommonsDelinker + def __call__(self, page, summary, image, replacement): + site = page.site() + if (site.lang, site.family.name) == ('fr', 'wikibooks') and replacement.get() is None: + if page.title().startswith('Photographie/') or page.title().startswith('Tribologie/'): + replacement.set('IMG.svg') + self.CommonsDelinker.output(u'%s Replaced %s by IMG.svg on %s.' % \ + (self, image.get(), replacement.get()))