User:WindBOT/Filters: Difference between revisions
From the Portal Wiki
More actions
→Implement {{tl|Dictionary}}: + Portal Pinball achievements |
m →Common misspellings: fix SyntaxError |
||
| (12 intermediate revisions by the same user not shown) | |||
| Line 19: | Line 19: | ||
== Semantic filters == | == Semantic filters == | ||
=== Capitalized words === | |||
enforceCapitalization('Aperture Science', 'P-body', 'GLaDOS') | |||
enforceCapitalization('Portal Gun', 'Weighted Storage Cube') | |||
enforceCapitalization('Steam', 'Nintendo Switch', 'PlayStation', 'Xbox') | |||
=== Common misspellings === | |||
addSafeFilter( | |||
wordFilter(u'Rattmann', u'(?<!Ghost of )Rattman', u'Ratmann'), | |||
wordFilter(u'Rat Man', u'Ratman', u'Rat-Man'), | |||
wordFilter('screenshot', 'screen shot'), | |||
wordFilter('screenshots', 'screen shots'), | |||
wordFilter('in-game', 'ingame') | |||
) | |||
=== Section headers === | |||
addSafeFilter( | |||
wordFilter(u'== Update history ==', u'==+ ?(?:Update history|Previous changes) ?==+'), | |||
wordFilter(u'== See also ==', u'==+ ?See also ?==+'), | |||
wordFilter(u'== External links ==', u'==+ ?External links ?==+'), | |||
wordFilter(u'== Unused content ==', u'==+ ?Unused content ?==+'), | |||
wordFilter(u'== Related achievements ==', u'==+ ?Related achievements ?==+'), | |||
wordFilter(u'=== Undocumented changes ===', u'==+ ?Undocumented changes ?==+') | |||
) | |||
== Language-specific filters == | == Language-specific filters == | ||
| Line 72: | Line 94: | ||
return link | return link | ||
addLinkFilter(hlwikiLinks) | addLinkFilter(hlwikiLinks) | ||
=== Convert [[:Category:Patches|patch]] links to {{tl|Patch name}} === | |||
def patchNameLinkFilter(l, **kwargs): | |||
if l.getType() != u'internal': | |||
return l | |||
regPatchName = compileRegex(u'(January|February|March|April|May|June|July|August|September|October|November|December)\\s+(\\d+),\\s+(\\d{4,})\\s+Patch(?:/\\w+)?') | |||
result = regPatchName.match(l.getLink()) | |||
if result is None or l.getLabel().find(result.group(2)) == -1 or l.getLabel().find(result.group(3)) == -1: | |||
return l | |||
monthNames = ('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december') | |||
patchType = u'' | |||
if l.getLink().lower().find(u'portal') != -1: | |||
patchType = u'|portal' | |||
elif l.getLink().lower().find(u'tools') != -1: | |||
patchType = u'|tools' | |||
return template(u'<nowiki>{{Patch name|' + u(monthNames.index(result.group(1).lower()) + 1) + u'|' + u(result.group(2)) + u'|' + u(result.group(3)) + patchType + u'}}</nowiki>') | |||
addLinkFilter(patchNameLinkFilter) | |||
== Template filters == | == Template filters == | ||
| Line 80: | Line 119: | ||
#'Good template name': ['Bad template lowercase name 1', 'Bad template lowercase name 2', 'Bad template lowercase name 3'], | #'Good template name': ['Bad template lowercase name 1', 'Bad template lowercase name 2', 'Bad template lowercase name 3'], | ||
# Last line has no comma at the end | # Last line has no comma at the end | ||
'Crush': ['pngcrush'] | 'Crush': ['pngcrush'], | ||
'Chamber infobox': ['test chamber infobox'] | |||
} | } | ||
for n in templateMap: | for n in templateMap: | ||
| Line 87: | Line 127: | ||
return t | return t | ||
addTemplateFilter(templateRenameMapping) | addTemplateFilter(templateRenameMapping) | ||
=== Reindent all infoboxes === | |||
def infoboxIndentFilter(t, **kwargs): | |||
itemInfoboxes = ('game infobox', 'website infobox', 'item infobox', 'company infobox', 'chamber infobox', 'old aperture infobox', 'twtm chamber infobox', 'mel old aperture infobox') | |||
tName = t.getName().lower() | |||
if 'infobox' in tName and tName not in itemInfoboxes: | |||
t.indentationMatters(True) | |||
t.setDefaultIndentation(2) | |||
return t | |||
addTemplateFilter(infoboxIndentFilter, lowPriority=True) | |||
=== Remove useless templates === | === Remove useless templates === | ||
| Line 124: | Line 175: | ||
return t | return t | ||
addTemplateFilter(obsoleteParameterFilter) | addTemplateFilter(obsoleteParameterFilter) | ||
=== Add <code>day</code>/<code>month</code>/<code>year</code> to {{tl|Patch layout}} === | |||
def patchLayoutFilter(t, **kwargs): | |||
if t.getName().lower() != 'patch layout' or 'article' not in kwargs: | |||
return t | |||
t.setPreferedOrder(['game', 'before', 'day', 'month', 'year', 'after', 'source-title', 'source', 'source-lang'] + [['source-' + str(n) + '-title', 'source-' + str(n), 'source-' + str(n) + '-lang'] for n in xrange(10)] + ['updatelink', 'update', 'update-link', 'update-lang', 'hide-diff'] + [['diff-' + str(n)] for n in xrange(10)] + ['notes']) | |||
t.delParam('current') | |||
regPatchName = compileRegex(u'^(January|February|March|April|May|June|July|August|September|October|November|December)\\s+(\\d+),\\s+(\\d{4,})\\s+Patch(?:/\\w+)?') | |||
result = regPatchName.match(u(kwargs['article'].title)) | |||
if result is not None: | |||
t.setParam('day', result.group(2)) | |||
t.setParam('month', result.group(1).lower()) | |||
t.setParam('year', result.group(3)) | |||
return t | |||
addTemplateFilter(patchLayoutFilter) | |||
=== Implement {{tl|Dictionary}} === | === Implement {{tl|Dictionary}} === | ||
| Line 150: | Line 216: | ||
'name': 'mechanics', | 'name': 'mechanics', | ||
'sync': 'Template:Dictionary/mechanics/Special:SyncData' | 'sync': 'Template:Dictionary/mechanics/Special:SyncData' | ||
}, | |||
u'Template:Dictionary/merchandise': { | |||
'name': 'merchandise', | |||
'sync': 'Template:Dictionary/merchandise/Special:SyncData' | |||
}, | }, | ||
u'Template:Dictionary/characters': { | u'Template:Dictionary/characters': { | ||
| Line 186: | Line 256: | ||
'name': 'portal pinball achievements', | 'name': 'portal pinball achievements', | ||
'sync': 'Template:Dictionary/portal pinball achievements/Special:SyncData' | 'sync': 'Template:Dictionary/portal pinball achievements/Special:SyncData' | ||
}, | |||
u'Template:Dictionary/bridge constructor portal achievements': { | |||
'name': 'bridge constructor portal achievements', | |||
'sync': 'Template:Dictionary/bridge constructor portal achievements/Special:SyncData' | |||
}, | }, | ||
u'Template:Dictionary/audio': { | u'Template:Dictionary/audio': { | ||
| Line 202: | Line 276: | ||
'name': 'voice lines/Ap-Sap', | 'name': 'voice lines/Ap-Sap', | ||
'sync': 'Template:Dictionary/voice lines/Ap-Sap/Special:SyncData' | 'sync': 'Template:Dictionary/voice lines/Ap-Sap/Special:SyncData' | ||
}, | |||
u'Template:Dictionary/voice lines/Caroline': { | |||
'name': 'voice lines/Caroline', | |||
'sync': 'Template:Dictionary/voice lines/Caroline/Special:SyncData' | |||
}, | }, | ||
u'Template:Dictionary/voice lines/Cave Johnson': { | u'Template:Dictionary/voice lines/Cave Johnson': { | ||
| Line 214: | Line 292: | ||
'name': 'voice lines/Fact core', | 'name': 'voice lines/Fact core', | ||
'sync': 'Template:Dictionary/voice lines/Fact core/Special:SyncData' | 'sync': 'Template:Dictionary/voice lines/Fact core/Special:SyncData' | ||
}, | }, | ||
u'Template:Dictionary/voice lines/GLaDOS': { | u'Template:Dictionary/voice lines/GLaDOS': { | ||
| Line 226: | Line 300: | ||
'name': 'voice lines/Space core', | 'name': 'voice lines/Space core', | ||
'sync': 'Template:Dictionary/voice lines/Space core/Special:SyncData' | 'sync': 'Template:Dictionary/voice lines/Space core/Special:SyncData' | ||
}, | |||
u'Template:Dictionary/voice lines/Turret': { | |||
'name': 'voice lines/Turret', | |||
'sync': 'Template:Dictionary/voice lines/Turret/Special:SyncData' | |||
}, | }, | ||
u'Template:Dictionary/voice lines/Wheatley': { | u'Template:Dictionary/voice lines/Wheatley': { | ||
'name': 'voice lines/Wheatley', | 'name': 'voice lines/Wheatley', | ||
'sync': 'Template:Dictionary/voice lines/Wheatley/Special:SyncData' | 'sync': 'Template:Dictionary/voice lines/Wheatley/Special:SyncData' | ||
} | }, | ||
u'Template:Dictionary/voice lines/Grady': { | |||
'name': 'voice lines/Grady', | |||
'sync': 'Template:Dictionary/voice lines/Grady/Special:SyncData' | |||
}, | |||
u'Template:Dictionary/voice lines/Desk Job': { | |||
'name': 'voice lines/Desk Job', | |||
'sync': 'Template:Dictionary/voice lines/Desk Job/Special:SyncData' | |||
}, | |||
u'Template:Dictionary/defindex': { | |||
'name': 'defindex', | |||
'sync': 'Template:Dictionary/defindex/Special:SyncData' | |||
} | |||
} | } | ||
self.subpageSeparator = u'/' | self.subpageSeparator = u'/' | ||