Paste this code below into file: models/plugin_wiki_extra.py
class PluginWikiWidgets(PluginWikiWidgets): @staticmethod def encode_text(text='',mailto=''): """ Purpose: To foil most superficial harvesters Input: any text Output: the text encoded as either a decimal or hex entity, optionally with a mailto link widget inspired from python implementation of Markdown (MIT license) """ def _xml_encode_text_char_at_random(ch): from random import random r = random() # Roughly 20% raw, 40% hex, 40% dec. # '@' and '_' are always encoded. if r > 0.8 and ch not in "@_": return ch elif r < 0.4: # [1:] drops leading '0': 0x63 -> x63 return '&#%s;' % hex(ord(ch))[1:] else: return '&#%s;' % ord(ch) def _encode_text(text,mailto): if mailto.lower()=='true': chars = [_xml_encode_text_char_at_random(ch) for ch in "mailto:" + text] # make link and strip mailto: from the visible email address text = '<a href="%s">%s</a>' \ % (''.join(chars), ''.join(chars[7:])) else: chars = [_xml_encode_text_char_at_random(ch) for ch in text] text = ''.join(chars) return text return _encode_text(text, mailto)
Now in your wiki page enter something like these following examples:
Example 1 - Text
`` name:encode_text text:My private telephone number 01 234567 ``:widget
Example 2 - Email Address
`` name:encode_text text:foo@bar.com mailto:true ``:widget
If you look at the HTML source produced, you will see something like the text below, which isn't very nice for the average bot to parse::
My private telephone number: 01 234567
Note that apart from the text, there is just one other optional parameter mailto:true which makes an email address into a mailto: link.
Hope you find it useful or interesting as a simple example of adding an extra plugin_wiki widget.
Comments (0)