User:Pfctdayelise/Special:Translations
From MediaWiki.org
page parameters:
- masterpage
- langcode
extn parameters:
- translationssubpagename = 'i18n'
- revregexp = re.compile("r([\d]+)") # r + string of digits
if masterpage: showchunk(masterpage) else if langcode: //not allowing for combination of masterpage *and* langcode, is it needed? showall(langcode) else: getchoice()? showall()?
Contents |
[edit] def linkparsed(page):
# some extract link targets and link text *pairs* for all wikilinks in page.
# if no link text then should be ('link target', )
# ignore external links
[edit] def showchunk(masterpage):
if not masterpage:
raise error(badmasterpage)
translationspage = masterpage + r'/' + translationssubpagename
if not translationspage:
raise error(badtranslationspage)
translationsarray = [(linktext,linktarget) for (linktarget, linktext) in linkparsed(translationspage)]
translationsprinted = 0
printstarttranslations() #boring formatty stuff
for (lc, linkname) in translationsarray:
if not lc:
# silently ignore bad links
continue
else:
printtranslationline(masterpage, lc, linkname)
translationsprinted += 1
if translationsprinted == 0:
printerror(novalidtranslations)
printendtranslations() #boring formatty stuff
return
[edit] def printtranslationline(masterpage, lc, translationpage):
if not linkname:
printnotyetcreated(lc, translationpage)
# ok, so masterpage exists, translationpage exists.
# now comes the interesting part - figuiring out how up to date
# this translation is.
# these come back in reverse chron order
masterrevs = getrevisions(masterpage)
translationrevs = getrevisions(translationpage)
revmatch = NULL
for rev in translationrevs:
possiblerevmatch = revregexp.find(rev)
if possiblerevmatch and possiblerevmatch in masterrevs: #superfluous condition?
revmatch = possiblerevmatch
break
# if there's a rev there, but it's not in the masterrevs, just ignore it
# need to separate cases ?
# * never had a valid rev ref
# * has a valid rev ref, not most recent
# * has a valid rev ref, most recent (up to date page)
if not revmatch:
printtranslationline(...)
return
[edit] def showall(langcode=None):
translations = getalldefinedtranslations() # regexp with translationssubpagename
if langcode:
results = [page for page in translations if haslangtranslation(page, langcode)]
else:
results = translations
for page in translations:
printtranslationline(masterpage, langcode, translationpage)
...