Skip to content

Commit

Permalink
Fix for {{lang}} issues
Browse files Browse the repository at this point in the history
  • Loading branch information
HazardSJ committed Jun 2, 2013
1 parent bfb7d2a commit 04e7f89
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion citationstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def __init__(self):
]
self.doTaskPage = pywikibot.Page(self.site, 'User:Hazard-Bot/DoTask/21')
self.subscription = self.getAllTitles("Template:Subscription required")
self.lang = self.getAllTitles("Template:Lang")
self.lang.extend(self.getAllTitles("Template:Rtl-lang"))
self.loadLanguages("User:Hazard-Bot/Languages.css")

def checkDoTaskPage(self):
try:
Expand All @@ -42,6 +45,21 @@ def getAllTitles(self, template):
titles.append(redirect.title(withNamespace = False).lower())
return titles

def loadLanguages(self, title):
self.languages = {}
page = pywikibot.Page(self.site, title)
text = page.get()
lines = text.splitlines()
for line in lines:
code, name = line.split(":")
self.languages[code] = name

def getLanguage(self, code):
try:
return self.languages[code]
except KeyError:
return "{{#language:%s|en}}" % code

def removeWikilinks(self):
def replaceWikilinks(template, URL, title):
if not template.has_param(URL):
Expand All @@ -60,9 +78,20 @@ def replaceWikilinks(template, URL, title):
for temp in temps:
if (temp.name.lower().strip() in self.subscription) and temp.has_param("via"):
template.add("via", temp.get("via").value)
template.get(title).value.remove(temp)
elif temp.name.lower().strip() in self.lang:
if template.has_param("language"):
template.remove("language")
template.add("language", self.getLanguage(temp.get(1).value.lower().strip()))
template.get(title).value.replace(temp, temp.get(2).value)
elif temp.name.lower().strip().startswith("lang-"):
if template.has_param("language"):
template.remove("language")
template.add("language", self.getLanguage(temp.name.lower().strip()[5:]))
template.get(title).value.replace(temp, temp.get(1).value)
else:
self.code.insert_after(template, temp)
template.get("title").value.remove(temp)
template.get(title).value.remove(temp)
## @fixme: Use a function, and use {{Cite doi}} as well, just in case...
## ...or generate from [[Category:Citation Style 1 templates]]? (doesn't include {{citation}} though)
#template = pywikibot.Page(self.site, "Template:Cite web")
Expand Down

0 comments on commit 04e7f89

Please sign in to comment.