Revision: 4390
Author: btongminh
Date: 2007-09-29 19:49:10 +0000 (Sat, 29 Sep 2007)
Log Message:
-----------
Plugins!
Modified Paths:
--------------
trunk/pywikipedia/commonsdelinker/delinker.py
trunk/pywikipedia/commonsdelinker/delinker.txt
Added Paths:
-----------
trunk/pywikipedia/commonsdelinker/plugins.txt
Modified: trunk/pywikipedia/commonsdelinker/delinker.py
===================================================================
--- trunk/pywikipedia/commonsdelinker/delinker.py 2007-09-29 19:09:58 UTC (rev 4389)
+++ trunk/pywikipedia/commonsdelinker/delinker.py 2007-09-29 19:49:10 UTC (rev 4390)
@@ -181,8 +181,10 @@
m_replacement = ImmutableByReference(replacement)
groups = list(match.groups())
if hook:
- self.CommonsDelinker.exec_hook('%s_replace' % hook,
- (page, summary, image, m_replacement, match, groups))
+ if False is self.CommonsDelinker.exec_hook('%s_replace' % hook,
+ (page, summary, image, m_replacement, match, groups)):
+ return u''.join(groups)
+
if m_replacement.get() is None:
return u''
else:
@@ -262,7 +264,8 @@
try:
new_text = ImmutableByReference(new_text)
m_summary = ImmutableByReference(summary)
- if self.exec_hook('before_save', (page, text, new_text)) is False:
+ if False is self.exec_hook('before_save',
+ (page, text, new_text, m_summary)):
return 'skipped'
if self.CommonsDelinker.config.get('edit', True) and not \
Modified: trunk/pywikipedia/commonsdelinker/delinker.txt
===================================================================
--- trunk/pywikipedia/commonsdelinker/delinker.txt 2007-09-29 19:09:58 UTC (rev 4389)
+++ trunk/pywikipedia/commonsdelinker/delinker.txt 2007-09-29 19:49:10 UTC (rev 4390)
@@ -44,6 +44,10 @@
Both bots allow the use of on-wiki summary templates. Refer to
[[m:User:CommonsDelinker]] for information on the syntax.
+=== Plugins ===
+CommonsDelinker has a basic plugin framework. More information can be found
+in plugins.txt.
+
== Requirements ==
* A recent SVN checkout of the pywikipedia framework
* Python 2.4 or higher
@@ -88,6 +92,7 @@
GLOBALLY WITHOUT CONSULTING BRYAN AND SIEBRAND. Thank you.
* ''no_sysop = True'': Disable delinking as sysop.
* ''enable_logging = True'': Enable logging actions to database.
+* ''plugins'' = []: Enabled plugins. See plugins.txt for more
information.
=== Delinker settings ===
Those variables only need to be set if the delinker is enabled.
@@ -131,6 +136,13 @@
* ''replacer_table = "database_name.replacer_table"'': The
database.table for the
replacer. Only required if the replacer is activated.
+=== Edit and debugging settings ===
+* ''edit = True'': Actually edit to the wiki.
+* ''enable_delinker = True'': Enable the delinker.
+* ''enable_replacer = True'': Enable the replacer.
+* ''single_process_replacer = False'': Start the replacer-reader and the
+ replacer in one process. This is currently not yet supported.
+
==== SQL table layout ====
<code lang="sql">
CREATE TABLE delinker (
@@ -172,16 +184,7 @@
newimg VARBINARY(255)
);
</code>
-
-=== Edit and debugging settings ===
-* ''save_diff = False'': Save all changes to a diff. Create a directory
diff/
- before running.
-* ''edit = True'': Actually edit to the wiki.
-* ''enable_delinker = True'': Enable the delinker.
-* ''enable_replacer = True'': Enable the replacer.
-* ''single_process_replacer = False'': Start the replacer-reader and the
- replacer in one process. This is currently not yet supported.
-
+
== Licensing ==
The file ''delinker.py'' is copyrighted © 2006 - 2007 Orgullomoore,
© 2007 Siebrand Mazeland, © 2007 Bryan Tong Minh. The file
''replacer.py''
@@ -211,11 +214,11 @@
OTHER DEALINGS IN THE SOFTWARE.
The most recent version of this documentation can be found in the
-pywikipedia CVS, on <http://pywikipediabot.cvs.sourceforge.net/
-pywikipediabot/pywikipedia/delinker.txt?view=markup>. Copies
-maybe found on meta <http://meta.wikimedia.org/wiki/
-CommonsDelinker/For_operators> and BotWiki
-<http://botwiki.sno.cc/wiki/Python:CommonsDelinker/For_operators>.
+pywikipedia SVN, on <http://svn.wikimedia.org/svnroot/pywikipedia/
+trunk/pywikipedia/> and browsable on <http://svn.wikimedia.org/viewvc/
+pywikipedia/>. Copies maybe found on meta <http://meta.wikimedia.org/
+wiki/CommonsDelinker/For_operators> and BotWiki <http://botwiki.sno.cc/
+wiki/Python:CommonsDelinker/For_operators>.
== Example configuration file ==
Added: trunk/pywikipedia/commonsdelinker/plugins.txt
===================================================================
--- trunk/pywikipedia/commonsdelinker/plugins.txt (rev 0)
+++ trunk/pywikipedia/commonsdelinker/plugins.txt 2007-09-29 19:49:10 UTC (rev 4390)
@@ -0,0 +1,53 @@
+CommonsDelinker supports a plugin system, which allows modifying the delink and
+replace parameters on a case by case basis.
+
+Plugins should be registered in the configuration file. CommonsDelinker expects
+the configuration value CommonsDelinker['plugins'] to be an iterable object.
+The items of this iterable should be module.object strings of the plugin. The
+plugin is expected to reside as module.py in commonsdelinker/plugins. The
+object should exist and should be a callable object or type with an attribute
+'hook' being a string indicating the hook name.
+
+Some parameters are modyfiable by the plugin. Those include the mutable objects
+and some immutable object wrapped in an ImmutableByReference object. The value
+of such an object can be get/set by the get and set method. Modyfiable
+parameters are preceded by an ampersand & in this documentation.
+
+A hook that gives False as return value will terminate the hook chain and for
+most hooks also terminate the caller.
+
+== List of hooks and their parameters ==
+
+before_delink(image, usage, timestamp, admin, reason, replacement)
+ Called once per image. Returing False will cancel delinking this image.
+
+simple_replace(page, summary, image, &replacement, match, groups)
+gallery_replace(page, summary, image, &replacement, match, groups)
+complex_replace(page, summary, image, &replacement, match, groups)
+ Called each time an occerence is to be replaced. Returning False will not
+ replace this occerence.
+
+before_save(page, text, &new_text, &summary)
+ Called before the page is saved. Returning False will not save the page.
+
+after_delink(image, usage, timestamp, admin, reason, replacement)
+ Called once per image after delink.
+
+== Example ==
+# Saves a diff for every delink.
+import difflib
+
+class Diff(object):
+ hook = 'before_save'
+ def __init__(self, CommonsDelinker):
+ self.CommonsDelinker = CommonsDelinker
+ def __call__(self, page, text, new_text, summary):
+ 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