Revision: 7128 Author: siebrand Date: 2009-08-07 17:15:59 +0000 (Fri, 07 Aug 2009)
Log Message: ----------- * rename flags.py to more generic replace_with_dummy.py. Requires reconfiguration if you are using this (f.e. CommonsDelinker['plugins'] = ['replace_with_dummy.DummyReplacement'] * add de.wikipedia to replace_with_dummy.py ([[User:CommonsDelinker/DummyReplacements]]) * rename configuration page for nl.wp to [[User:CommonsDelinker/DummyReplacements]] * change tags from "[begin|end]-flags" to "[begin|end]-flags" * added configuration documentation in replace_with_dummy.py * add svn keyword Id * remove trailing whitespace
Modified Paths: -------------- trunk/pywikipedia/commonsdelinker/plugins/__init__.py trunk/pywikipedia/commonsdelinker/plugins/books.py trunk/pywikipedia/commonsdelinker/plugins/debug.py trunk/pywikipedia/commonsdelinker/plugins/skipped_pages.py
Added Paths: ----------- trunk/pywikipedia/commonsdelinker/plugins/replace_with_dummy.py
Removed Paths: ------------- trunk/pywikipedia/commonsdelinker/plugins/flags.py
Property Changed: ---------------- trunk/pywikipedia/commonsdelinker/plugins/__init__.py trunk/pywikipedia/commonsdelinker/plugins/books.py trunk/pywikipedia/commonsdelinker/plugins/debug.py trunk/pywikipedia/commonsdelinker/plugins/skipped_pages.py
Modified: trunk/pywikipedia/commonsdelinker/plugins/__init__.py =================================================================== --- trunk/pywikipedia/commonsdelinker/plugins/__init__.py 2009-08-07 13:33:41 UTC (rev 7127) +++ trunk/pywikipedia/commonsdelinker/plugins/__init__.py 2009-08-07 17:15:59 UTC (rev 7128) @@ -1 +1 @@ -__version__ = '$Id: $' +__version__ = '$Id$'
Property changes on: trunk/pywikipedia/commonsdelinker/plugins/__init__.py ___________________________________________________________________ Added: svn:keywords + Id
Modified: trunk/pywikipedia/commonsdelinker/plugins/books.py =================================================================== --- trunk/pywikipedia/commonsdelinker/plugins/books.py 2009-08-07 13:33:41 UTC (rev 7127) +++ trunk/pywikipedia/commonsdelinker/plugins/books.py 2009-08-07 17:15:59 UTC (rev 7128) @@ -1,4 +1,4 @@ -__version__ = '$Id: $' +__version__ = '$Id$'
import re
Property changes on: trunk/pywikipedia/commonsdelinker/plugins/books.py ___________________________________________________________________ Added: svn:keywords + Id
Modified: trunk/pywikipedia/commonsdelinker/plugins/debug.py =================================================================== --- trunk/pywikipedia/commonsdelinker/plugins/debug.py 2009-08-07 13:33:41 UTC (rev 7127) +++ trunk/pywikipedia/commonsdelinker/plugins/debug.py 2009-08-07 17:15:59 UTC (rev 7128) @@ -1,5 +1,5 @@ import difflib -__version__ = '$Id: $' +__version__ = '$Id$'
class Diff(object): hook = 'before_save' @@ -9,9 +9,9 @@ diff = difflib.context_diff( text.encode('utf-8').splitlines(True), new_text.get().encode('utf-8').splitlines(True)) - + f = open((u'diff/%s-%s-%s.txt' % (page.urlname().replace('/', '-'), page.site().dbName(), page.editTime())).encode('utf-8', 'ignore'), 'w') - + f.writelines(diff) - f.close() \ No newline at end of file + f.close()
Property changes on: trunk/pywikipedia/commonsdelinker/plugins/debug.py ___________________________________________________________________ Added: svn:keywords + Id
Deleted: trunk/pywikipedia/commonsdelinker/plugins/flags.py =================================================================== --- trunk/pywikipedia/commonsdelinker/plugins/flags.py 2009-08-07 13:33:41 UTC (rev 7127) +++ trunk/pywikipedia/commonsdelinker/plugins/flags.py 2009-08-07 17:15:59 UTC (rev 7128) @@ -1,32 +0,0 @@ -__version__ = '$Id: $' - -import re - -class NlWiki(object): - hook = 'gallery_replace' - def __init__(self, CommonsDelinker): - self.CommonsDelinker = CommonsDelinker - def __call__(self, page, summary, image, replacement, match, groups): - site = page.site() - if (site.lang, site.family.name) == ('nl', 'wikipedia') and replacement.get() is None: - commands = self.CommonsDelinker.SummaryCache.get(site, 'Vlaggen', default = '') - - flags = re.findall(r'(?s)<!--begin-flags (.*?)-->(.*?)<!--end-flags-->', commands) - text = page.get() - - namespace = site.namespace(14) - r_namespace = r'(?:[Cc]ategory)|(?:[%s%s]%s)' % \ - (namespace[0], namespace[0].lower(), namespace[1:]) - - for new_image, categories in flags: - for category in categories.split('\n'): - if category.strip() == '': continue - - r_cat = r'[[\s*%s\s*:\s*%s\s*(?:|.*?)?\s*]]' % (r_namespace, - re.sub(r'\[ _]', '[ _]', re.escape(category.strip()))) - if re.search(r_cat, text): - self.CommonsDelinker.output( - u'%s %s replaced by %s in category %s' % \ - (self, image, new_image, category)) - replacement.set(new_image.replace(' ', '_')) - \ No newline at end of file
Copied: trunk/pywikipedia/commonsdelinker/plugins/replace_with_dummy.py (from rev 7123, trunk/pywikipedia/commonsdelinker/plugins/flags.py) =================================================================== --- trunk/pywikipedia/commonsdelinker/plugins/replace_with_dummy.py (rev 0) +++ trunk/pywikipedia/commonsdelinker/plugins/replace_with_dummy.py 2009-08-07 17:15:59 UTC (rev 7128) @@ -0,0 +1,62 @@ +__version__ = '$Id$' + +import re + +class DummyReplacement(object): + hook = 'gallery_replace' + def __init__(self, CommonsDelinker): + self.CommonsDelinker = CommonsDelinker + def __call__(self, page, summary, image, replacement, match, groups): + site = page.site() + if (site.lang, site.family.name) == ('nl', 'wikipedia') and replacement.get() is None: + # Do not delink from pages in categories mentioned in [[User:CommonsDelinker/DummyReplacements]] + # but replace the target file with another file (used in for example flag or coat of arms galleries). + # Format of the configuration page (see example on http://nl.wikipedia.org/wiki/Gebruiker:CommonsDelinker/DummyReplacements): + # <!--begin-dummyreplace Sin escudo.svg--> + # Amerikaans zegel + # <!--end-dummyreplace--> + # The above will not delink files in pages in the category "Amerikaans zegel" but replace + # them with the file "Sin escudo.svg" + + commands = self.CommonsDelinker.SummaryCache.get(site, 'DummyReplacements', default = '') + + dummyreplacements = re.findall(r'(?s)<!--begin-dummyreplace (.*?)-->(.*?)<!--end-dummyreplace-->', commands) + text = page.get() + + namespace = site.namespace(14) + r_namespace = r'(?:[Cc]ategory)|(?:[%s%s]%s)' % \ + (namespace[0], namespace[0].lower(), namespace[1:]) + + for new_image, categories in dummyreplacements: + for category in categories.split('\n'): + if category.strip() == '': continue + + r_cat = r'[[\s*%s\s*:\s*%s\s*(?:|.*?)?\s*]]' % (r_namespace, + re.sub(r'\[ _]', '[ _]', re.escape(category.strip()))) + if re.search(r_cat, text): + self.CommonsDelinker.output( + u'%s %s replaced by %s in category %s' % \ + (self, image, new_image, category)) + replacement.set(new_image.replace(' ', '_')) + + if (site.lang, site.family.name) == ('de', 'wikipedia') and replacement.get() is None: + commands = self.CommonsDelinker.SummaryCache.get(site, 'DummyReplacements', default = '') + + dummyreplacements = re.findall(r'(?s)<!--begin-dummyreplace (.*?)-->(.*?)<!--end-dummyreplace-->', commands) + text = page.get() + + namespace = site.namespace(14) + r_namespace = r'(?:[Cc]ategory)|(?:[%s%s]%s)' % \ + (namespace[0], namespace[0].lower(), namespace[1:]) + + for new_image, categories in dummyreplacements: + for category in categories.split('\n'): + if category.strip() == '': continue + + r_cat = r'[[\s*%s\s*:\s*%s\s*(?:|.*?)?\s*]]' % (r_namespace, + re.sub(r'\[ _]', '[ _]', re.escape(category.strip()))) + if re.search(r_cat, text): + self.CommonsDelinker.output( + u'%s %s replaced by %s in category %s' % \ + (self, image, new_image, category)) + replacement.set(new_image.replace(' ', '_'))
Property changes on: trunk/pywikipedia/commonsdelinker/plugins/replace_with_dummy.py ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native
Modified: trunk/pywikipedia/commonsdelinker/plugins/skipped_pages.py =================================================================== --- trunk/pywikipedia/commonsdelinker/plugins/skipped_pages.py 2009-08-07 13:33:41 UTC (rev 7127) +++ trunk/pywikipedia/commonsdelinker/plugins/skipped_pages.py 2009-08-07 17:15:59 UTC (rev 7128) @@ -1,4 +1,4 @@ -__version__ = '$Id: $' +__version__ = '$Id$'
class SkipPages(object): hook = 'before_save' @@ -9,4 +9,4 @@ if (site.lang, site.family.name) == ('en', 'wikipedia'): if page.title == 'Wikipedia:Sound/list': return False - return True \ No newline at end of file + return True
Property changes on: trunk/pywikipedia/commonsdelinker/plugins/skipped_pages.py ___________________________________________________________________ Added: svn:keywords + Id