Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

User:WindBOT/CoreSource: Difference between revisions

From the Portal Wiki
mNo edit summary
Added new built-in filter: Simplify anchors
 
(One intermediate revision by the same user not shown)
Line 30: Line 30:
import wikiUpload
import wikiUpload
import feedparser
import feedparser
# Hax for Python < 2.7
try:
from collections import OrderedDict
except:
from backport_OrderedDict import OrderedDict
import collections
collections.OrderedDict = OrderedDict
try:
try:
import steam
import steam
Line 159: Line 152:
summary = getSummary(summary)
summary = getSummary(summary)
p = page(p)
p = page(p)
print 'Editing', p.title, 'with summary', summary
try:
print 'Editing', p.title, 'with summary', summary
except:
pass
try:
try:
if nocreate:
if nocreate:
Line 262: Line 258:
self.setLabel(None)
self.setLabel(None)
self.setLink(u'')
self.setLink(u'')
self.anchor = None
self.joined = False
self.joined = False
if len(content) > 2:
if len(content) > 2:
Line 271: Line 268:
if lnk.find(u':') == -1:
if lnk.find(u':') == -1:
lnk = lnk.replace(u'_', u' ')
lnk = lnk.replace(u'_', u' ')
anchor = None
if lnk.find(u'#') != -1:
lnk, anchor = lnk.split(u'#', 1)
self.setAnchor(anchor)
self.setLink(lnk)
self.setLink(lnk)
if len(split) == 2:
if len(split) == 2:
Line 276: Line 277:
else:
else:
self.setLabel(split[0])
self.setLabel(split[0])
self.joined = True
self.joined = anchor is None
elif content[0] == u'[' and content[-1] == u']':
elif content[0] == u'[' and content[-1] == u']':
split = content[1:-1].split(u' ', 1)
split = content[1:-1].split(u' ', 1)
Line 289: Line 290:
def getBody(self):
def getBody(self):
return u(self.body)
return u(self.body)
def getLink(self):
def getLink(self, withAnchor=False):
if withAnchor and self.getAnchor() is not None:
return u(self.link) + u'#' + self.getAnchor()
return u(self.link)
return u(self.link)
def getAnchor(self):
return self.anchor
def getLabel(self):
def getLabel(self):
if self.label is None:
if self.label is None:
Line 302: Line 307:
self.body = u(body)
self.body = u(body)
def setLink(self, link):
def setLink(self, link):
self.link = u(link)
link = u(link)
if self.getType() == u'internal' and link.find(u'#') != -1:
link, anchor = link.split(u'#', 1)
self.setAnchor(anchor)
self.link = link
if self.joined:
if self.joined:
self.label = u(link)
self.label = u(link)
replaceDots = compileRegex(r'(?:\.[a-f\d][a-f\d])+')
def _replaceDots(self, g):
s = ''
g = g.group(0)
for i in xrange(0, len(g), 3):
s += chr(int(g[i + 1:i + 3], 16))
return s.decode('utf8')
def setAnchor(self, anchor):
if self.getType() == u'internal':
u(anchor).replace(u'_', u' ')
try:
anchor = link.replaceDots.sub(self._replaceDots, anchor)
except:
pass
self.anchor = anchor
def setLabel(self, label):
def setLabel(self, label):
if label is None:
if label is None:
Line 318: Line 342:
def __unicode__(self):
def __unicode__(self):
label = self.getLabel()
label = self.getLabel()
tmpLink = self.getLink()
tmpLink = self.getLink(withAnchor=True)
if self.getType() == u'internal':
if self.getType() == u'internal':
tmpLink2 = tmpLink.replace(u'_', u' ')
tmpLink2 = tmpLink.replace(u'_', u' ')
Line 777: Line 801:
return setFilterName(curry(dumbReplacement, rs), u'DumbReplacements(' + u(rs) + u')')
return setFilterName(curry(dumbReplacement, rs), u'DumbReplacements(' + u(rs) + u')')
def dumbReplace(subject, replacement):
def dumbReplace(subject, replacement):
return setFilterName(dumbReplaces({subject: replacement}), u'DumbReplacement(' + u(subject) + u' -> ' + u(replacement) + u')')
return setFilterName(dumbReplaces({subject: replacement}), u'DumbReplacement(' + u(subject) + u' \u2192 ' + u(replacement) + u')')
def wordRegex(word, **kwargs):
def wordRegex(word, **kwargs):
flags = None
flags = None
Line 784: Line 808:
word = word[0]
word = word[0]
word = u(re.sub(r'[-_ ]+', r'[-_ ]', u(word)))
word = u(re.sub(r'[-_ ]+', r'[-_ ]', u(word)))
word = u(r"(?<![\u00E8-\u00F8\xe8-\xf8\w])(?<!'')(?<!" + r'"' + r")(?:\b|^)" + word + r"(?:\b(?![\u00E8-\u00F8\xe8-\xf8\w])(?!''|" + r'"' + r")|$)")
word = u(r"(?<![\u00E8-\u00F8\xe8-\xf8\w])(?<!'')(?<!" + r'"' + ")(?:\\b|(?<=[ \\[\\]\\(\\):;.,\"'*\\xab\\xbb])|^)" + word + r"(?:\b(?![\u00E8-\u00F8\xe8-\xf8\w])(?!''|" + r'"' + ")|(?=[ \\[\\]\(\\):;.,\"'*\\xab\\xbb])|$)")
if flags is None:
if flags is None:
return word
return word
Line 809: Line 833:
else:
else:
rs[wordRegex(w, **kwargs)] = correct
rs[wordRegex(w, **kwargs)] = correct
return setFilterName(regexes(rs), u'WordFilter(' + u'/'.join(badwords2) + u' -> ' + correct + u')')
return setFilterName(regexes(rs), u'WordFilter(' + u'/'.join(badwords2) + u' \u2192 ' + correct + u')')
def enforceCapitalization(*words, **kwargs):
def enforceCapitalization(*words, **kwargs):
for w in words:
for w in words: