Revision: 8806 Author: xqt Date: 2010-12-26 16:44:25 +0000 (Sun, 26 Dec 2010) Log Message: ----------- Some Russian and Ukrainian translations (r8805); some update from trunk
Modified Paths: -------------- branches/rewrite/scripts/basic.py branches/rewrite/scripts/blockpageschecker.py branches/rewrite/scripts/category.py branches/rewrite/scripts/category_redirect.py branches/rewrite/scripts/interwiki.py branches/rewrite/scripts/interwiki_graph.py branches/rewrite/scripts/replace.py
Modified: branches/rewrite/scripts/basic.py =================================================================== --- branches/rewrite/scripts/basic.py 2010-12-26 16:43:08 UTC (rev 8805) +++ branches/rewrite/scripts/basic.py 2010-12-26 16:44:25 UTC (rev 8806) @@ -43,12 +43,14 @@ 'fa': u'ربات: تغییر ...', 'fr': u'Robot: Changé ...', 'ja':u'ロボットによる:編集', - 'ksh': u'Bot: Ännern ...', - 'nds': u'Bot: Änderung ...', + 'ksh': u'Bot: Änderung ...', + 'nds': u'Bot: Ännern ...', 'nl': u'Bot: wijziging ...', 'pl': u'Bot: zmienia ...', 'pt': u'Bot: alterando...', + 'ru': u'Бот: изменил ...', 'sv': u'Bot: Ändrar ...', + 'uk': u'Бот: змінив ...', 'zh': u'機器人:編輯.....', }
@@ -56,10 +58,10 @@ """ Constructor. Parameters: @param generator: The page generator that determines on which pages - to work on. + to work on. @type generator: generator. @param dry: If True, doesn't do any real changes, but only shows - what would have been changed. + what would have been changed. @type dry: boolean. """ self.generator = generator @@ -88,7 +90,7 @@ text = 'Test ' + text
if not self.save(text, page, self.summary): - pywikibot.output(u'Page %s not saved.' % page.aslink()) + pywikibot.output(u'Page %s not saved.' % page.title(asLink=True))
def load(self, page): """ @@ -99,10 +101,10 @@ text = page.get() except pywikibot.NoPage: pywikibot.output(u"Page %s does not exist; skipping." - % page.title(asLink=True)) + % page.title(asLink=True)) except pywikibot.IsRedirectPage: pywikibot.output(u"Page %s is a redirect; skipping." - % page.title(asLink=True)) + % page.title(asLink=True)) else: return text return None @@ -119,8 +121,8 @@ pywikibot.output(u'Comment: %s' %comment) if not self.dry: choice = pywikibot.inputChoice( - u'Do you want to accept these changes?', - ['Yes', 'No'], ['y', 'N'], 'N') + u'Do you want to accept these changes?', + ['Yes', 'No'], ['y', 'N'], 'N') if choice == 'y': try: page.text = text @@ -130,11 +132,13 @@ pywikibot.output(u"Page %s is locked; skipping." % page.title(asLink=True)) except pywikibot.EditConflict: - pywikibot.output(u'Skipping %s because of edit conflict' - % (page.title())) + pywikibot.output( + u'Skipping %s because of edit conflict' + % (page.title())) except pywikibot.SpamfilterError, error: - pywikibot.output(u'Cannot change %s because of spam blacklist entry %s' - % (page.title(), error.url)) + pywikibot.output( +u'Cannot change %s because of spam blacklist entry %s' + % (page.title(), error.url)) else: return True return False
Modified: branches/rewrite/scripts/blockpageschecker.py =================================================================== --- branches/rewrite/scripts/blockpageschecker.py 2010-12-26 16:43:08 UTC (rev 8805) +++ branches/rewrite/scripts/blockpageschecker.py 2010-12-26 16:44:25 UTC (rev 8806) @@ -318,7 +318,10 @@ text, changes = re.subn('<noinclude>(%s)</noinclude>' % replaceToPerform, '', text) if changes == 0: text, changes = re.subn('(%s)' % replaceToPerform, '', text) - pywikibot.output(u'The page is editable for all, deleting the template...') + msg = u'The page is editable for all' + if not moveBlockCheck: + msg += u', deleting the template..' + pywikibot.output(u'%s.' % msg)
elif editRestr[0] == 'sysop': # total edit protection @@ -371,23 +374,27 @@ # move-total-protection if (TemplateInThePage[0] == 'sysop-move' and TTMP != None) or (TemplateInThePage[0] == 'unique' and TU != None): pywikibot.output(u'The page is protected from moving to the sysop, skipping...') + if TU != None: + text = oldtext # no changes needed, better to revert the old text. else: pywikibot.output(u'The page is protected from moving to the sysop, but the template seems not correct. Fixing...') - if TU != None: - text, changes = re.subn(TemplateInThePage[1], TNR[4], text) - else: - text, changes = re.subn(TemplateInThePage[1], TNR[3], text) + if TU != None: + text, changes = re.subn(TemplateInThePage[1], TNR[4], text) + else: + text, changes = re.subn(TemplateInThePage[1], TNR[3], text)
elif TSMP != None or TU != None: # implicitely moveRestr[0] = 'autoconfirmed', move-semi-protection if TemplateInThePage[0] == 'autoconfirmed-move' or TemplateInThePage[0] == 'unique': pywikibot.output(u'The page is movable only for the autoconfirmed users, skipping...') + if TU != None: + text = oldtext # no changes needed, better to revert the old text. else: pywikibot.output(u'The page is movable only for the autoconfirmed users, but the template seems not correct. Fixing...') - if TU != None: - text, changes = re.subn(TemplateInThePage[1], TNR[4], text) - else: - text, changes = re.subn(TemplateInThePage[1], TNR[2], text) + if TU != None: + text, changes = re.subn(TemplateInThePage[1], TNR[4], text) + else: + text, changes = re.subn(TemplateInThePage[1], TNR[2], text)
if changes == 0: # We tried to fix move-protection templates, but it did not work.
Modified: branches/rewrite/scripts/category.py =================================================================== --- branches/rewrite/scripts/category.py 2010-12-26 16:43:08 UTC (rev 8805) +++ branches/rewrite/scripts/category.py 2010-12-26 16:44:25 UTC (rev 8806) @@ -137,7 +137,7 @@ 'sr':u'Бот: Додаје [[Категорија:%s]]', 'sv':u'Robot: Lägger till [[Kategori:%s]]', 'szl':u'Bot dodowo: [[Kategoria:%s]]', - 'uk':u'Робот: додано [[Категорія:%s]]', + 'uk':u'Робот: додавання [[Категорія:%s]]', 'zh':u'機器人:新增目錄 [[Category:%s]]', }
@@ -176,7 +176,7 @@ 'sk':u'Robot zmenil [[%(oldcat)s]]→[[%(newcat)s]]', 'sr':u'Бот: Измена категорије %(oldcat)s', 'sv':u'Robot: Ändrar %(oldcat)s', - 'uk':u'Робот: змінено [[Категорія:%(oldcat)s]]', + 'uk':u'Робот: зміна %(oldcat)s', 'zh':u'機器人:變更目錄 [[%(oldcat)s]]→[[%(newcat)s]]', }
@@ -469,7 +469,7 @@ minorEdit=minorEdit, botflag=botflag) except pywikibot.LockedPage: pywikibot.output(u"Page %s is locked; skipping." - % page.aslink()) + % page.title(asLink=True)) except pywikibot.EditConflict: pywikibot.output( u'Skipping %s because of edit conflict' @@ -502,11 +502,12 @@ else: if self.sort: catpl = self.sorted_by_last_name(catpl, page) - pywikibot.output(u'Adding %s' % catpl.aslink()) + pywikibot.output(u'Adding %s' % catpl.title(asLink=True)) cats.append(catpl) text = pywikibot.replaceCategoryLinks(text, cats) if not self.save(text, page, self.editSummary): - pywikibot.output(u'Page %s not saved.' % page.aslink()) + pywikibot.output(u'Page %s not saved.' + % page.title(asLink=True))
class CategoryMoveRobot: @@ -982,6 +983,7 @@ 'pt': u'(também em %s)', 'ru': u'(также в %s)', 'sv': u'(också i %s)', + 'uk': u'(також у %s)', 'ср': u'(такође у %s)', 'zh': u'(也在 %s)', } @@ -1066,8 +1068,6 @@ restore = False create_pages = False for arg in pywikibot.handleArgs(*args): - if genFactory.handleArg(arg): - continue if arg == 'add': action = 'add' elif arg == 'remove': @@ -1118,6 +1118,8 @@ recurse = True elif arg == '-create': create_pages = True + else: + genFactory.handleArg(arg)
gen = genFactory.getCombinedGenerator() if action == 'add':
Modified: branches/rewrite/scripts/category_redirect.py =================================================================== --- branches/rewrite/scripts/category_redirect.py 2010-12-26 16:43:08 UTC (rev 8805) +++ branches/rewrite/scripts/category_redirect.py 2010-12-26 16:44:25 UTC (rev 8806) @@ -118,6 +118,8 @@ 'ksh': u"Bot: dubbel Ömleidung eruß jemaat.", 'pl': u"Robot: Poprawia podwójne przekierowanie", 'pt': u"Bot: Corrigindo redirecionamento duplo", + 'ru': u"Бот: исправление двойного перенаправления", + 'uk': u"Бот: виправлення подвійного перенаправлення", 'vi': u"Robot: sửa thể loại đổi hướng kép", 'zh': u"Bot: 修复双重重定向", } @@ -227,21 +229,16 @@ # an update due to changes in a transcluded template article.put(newtext, comment) if newtext == oldtext: - pywikibot.output( - u'No changes in made in page %s.' - % article.title(asLink=True) - ) + pywikibot.output(u'No changes in made in page %s.' + % article.title(asLink=True)) return False return True except pywikibot.EditConflict: - pywikibot.output( - u'Skipping %s because of edit conflict' - % article.title(asLink=True) - ) + pywikibot.output(u'Skipping %s because of edit conflict' + % article.title(asLink=True)) except pywikibot.LockedPage: pywikibot.output(u'Skipping locked page %s' - % article.title(asLink=True) - ) + % article.title(asLink=True)) self.edit_requests.append( (article.title(asLink=True, textlink=True), oldCat.title(asLink=True, textlink=True),
Modified: branches/rewrite/scripts/interwiki.py =================================================================== --- branches/rewrite/scripts/interwiki.py 2010-12-26 16:43:08 UTC (rev 8805) +++ branches/rewrite/scripts/interwiki.py 2010-12-26 16:44:25 UTC (rev 8806) @@ -96,13 +96,15 @@
These arguments control miscellanous bot behaviour:
- -quiet: Use this option to get less output + -quiet Use this option to get less output + (note: without ending colon)
- -async: Put page on queue to be saved to wiki asynchronously. This + -async Put page on queue to be saved to wiki asynchronously. This enables loading pages during saving throtteling and gives a better performance. NOTE: For post-processing it always assumes that saving the the pages was sucessful. + (note: without ending colon)
-summary: Set an additional action summary message for the edit. This could be used for further explainings of the bot action. @@ -120,15 +122,15 @@
There are some special hints, trying a number of languages at once: - * all: All languages with at least ca. 100 articles. - * 10: The 10 largest languages (sites with most - articles). Analogous for any other natural - number. - * arab: All languages using the Arabic alphabet. - * cyril: All languages that use the Cyrillic alphabet. - * chinese: All Chinese dialects. - * latin: All languages using the Latin script. - * scand: All Scandinavian languages. + * all: All languages with at least ca. 100 articles. + * 10: The 10 largest languages (sites with most + articles). Analogous for any other natural + number. + * arab: All languages using the Arabic alphabet. + * cyril: All languages that use the Cyrillic alphabet. + * chinese: All Chinese dialects. + * latin: All languages using the Latin script. + * scand: All Scandinavian languages.
-hintfile: similar to -hint, except that hints are taken from the given file, enclosed in [[]] each, instead of the command line. @@ -248,9 +250,10 @@ -limittwo only update two pages - one in the local wiki (if logged-in) and one in the top available one. For example, if the local page has links to de and fr, - this option will make sure that only local and de: (larger) - site is updated. This option is useful to quickly set two - way links without updating all of wiki's sites. + this option will make sure that only the local site and + the de: (larger) sites are updated. This option is useful + to quickly set two way links without updating all of + wiki families sites. (note: without ending colon)
-whenneeded works like limittwo, but other languages are changed in the @@ -298,8 +301,8 @@ to the interwiki-dumps subdirectory. The program will read it if invoked with the "-restore" or "-continue" option, and finish all the subjects in that list. After finishing the dump file will be deleted. To run the interwiki-bot on all -pages on a language, run it with option "-start:!", and if it takes so long that -you have to break it off, use "-continue" next time. +pages on a language, run it with option "-start:!", and if it takes so long +that you have to break it off, use "-continue" next time.
""" # @@ -1307,8 +1310,8 @@ elif not newhint: break else: - pages = titletranslate.translate(self.originPage, hints = [newhint], auto = globalvar.auto, removebrackets -= globalvar.hintnobracket) + pages = titletranslate.translate(self.originPage, hints=[newhint], + auto = globalvar.auto, removebrackets=globalvar.hintnobracket) for page in pages: self.addIfNew(page, counter, None) if globalvar.hintsareright: @@ -1597,6 +1600,7 @@ pywikibot.output(u" (%d) Found link to %s in:" % (i, page2)) self.whereReport(page2, indent = 8) while True: + #TODO: allow answer to repeat previous or go back after a mistake answer = pywikibot.input(u"Which variant should be used? (<number>, [n]one, [g]ive up) ").lower() if answer: if answer == 'g': @@ -1627,6 +1631,7 @@ if acceptall: answer = 'a' else: + #TODO: allow answer to repeat previous or go back after a mistake answer = pywikibot.inputChoice(u'What should be done?', ['accept', 'reject', 'give up', 'accept all'], ['a', 'r', 'g', 'l'], 'a') if answer == 'l': # accept all acceptall = True
Modified: branches/rewrite/scripts/interwiki_graph.py =================================================================== --- branches/rewrite/scripts/interwiki_graph.py 2010-12-26 16:43:08 UTC (rev 8805) +++ branches/rewrite/scripts/interwiki_graph.py 2010-12-26 16:44:25 UTC (rev 8806) @@ -14,10 +14,6 @@ import pywikibot from pywikibot import config2 as config
-# for speedyshare -import re -import httplib, urllib2, mimetypes - class GraphImpossible(Exception): "Drawing a graph is not possible on your system."
@@ -87,8 +83,12 @@ sourceLabel = self.getLabel(refPage) targetLabel = self.getLabel(page) edge = pydot.Edge(sourceLabel, targetLabel) + oppositeEdge = self.graph.get_edge(targetLabel, sourceLabel) if oppositeEdge: + if isinstance(oppositeEdge, list): + # bugfix for pydot >= 1.0.3 + oppositeEdge = oppositeEdge[0] #oppositeEdge.set_arrowtail('normal') oppositeEdge.set_dir('both') # workaround for bug [ 1722739 ]: prevent duplicate edges @@ -140,96 +140,6 @@ self.addDirectedEdge(page, refPage) self.saveGraphFile()
-class SpeedyShareUploader: - def __init__(self): - pass - - def getToken(self): - formR = re.compile( - '<form target=_top method="post" action="upload.php?(\d+)"') - - uploadPage = urllib2.urlopen( - 'http://www.speedyshare.com/index_upload.php') - text = uploadPage.read() - token = formR.search(text).group(1) - return token - - def post_multipart(self, host, selector, fields, files): - """ - Post fields and files to an http host as multipart/form-data. - fields is a sequence of (name, value) elements for regular form fields. - files is a sequence of (name, filename, value) elements for data to be - uploaded as files. Return the server's response page. - """ - content_type, body = self.encode_multipart_formdata(fields, files) - h = httplib.HTTP(host) - h.putrequest('POST', selector) - h.putheader('Content-Type', content_type) - h.putheader('Content-Length', str(len(body))) - h.putheader('User-Agent', - 'Mozilla/5.0 (X11; U; Linux i686; de; rv:1.8) Gecko/20051128 SUSE/1.5-0.1 Firefox/1.5') - h.putheader('Referer', 'http://www.speedyshare.com/index_upload.php') - h.putheader('Accept', - 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5') - h.putheader('Accept-Language', 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3') - h.putheader('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7') - h.putheader('Keep-Alive', '30') - h.putheader('Connection', 'keep-alive') - - h.endheaders() - h.send(body) - errcode, errmsg, headers = h.getreply() - return errcode, h.file.read() - - def encode_multipart_formdata(self, fields, files): - """ - fields is a sequence of (name, value) elements for regular form fields. - files is a sequence of (name, filename, value) elements for data to be - uploaded as files. Return (content_type, body) ready for httplib.HTTP - instance - """ - BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' - CRLF = '\r\n' - L = [] - for (key, value) in fields: - L.append('--' + BOUNDARY) - L.append('Content-Disposition: form-data; name="%s"' % key) - L.append('') - L.append(value) - for (key, filename, value) in files: - L.append('--' + BOUNDARY) - L.append( - 'Content-Disposition: form-data; name="%s"; filename="%s"' - % (key, filename)) - L.append('Content-Type: %s' % self.get_content_type(filename)) - L.append('') - L.append(value) - L.append('--' + BOUNDARY + '--') - L.append('') - body = CRLF.join(L) - content_type = 'multipart/form-data; boundary=%s' % BOUNDARY - return content_type, body - - def get_content_type(self, filename): - return mimetypes.guess_type(filename)[0] \ - or 'application/octet-stream' - - def upload(self, filename): - token = self.getToken() - - file = open(filename) - encodedFilename = filename#.encode('utf-8') - contents = file.read() - formdata = [] - - response, returned_html = self.post_multipart('www.speedyshare.com', - 'upload.php?' + token, - formdata, - [('fileup0', encodedFilename, contents)]) - print response - print returned_html - - def getFilename(page, extension = None): filename = '%s-%s-%s' % (page.site.family.name, page.site.language(), @@ -238,7 +148,3 @@ filename += '.%s' % extension return filename
-if __name__ == "__main__": - uploader = SpeedyShareUploader() - uploader.upload( - '/home/daniel/projekte/pywikipedia/interwiki-graphs/wikipedia-de-CEE.svg')
Modified: branches/rewrite/scripts/replace.py =================================================================== --- branches/rewrite/scripts/replace.py 2010-12-26 16:43:08 UTC (rev 8805) +++ branches/rewrite/scripts/replace.py 2010-12-26 16:44:25 UTC (rev 8806) @@ -122,8 +122,9 @@
import sys, re, time import pywikibot -from pywikibot import pagegenerators, catlib, config +from pywikibot import pagegenerators from scripts import editarticle +from pywikibot import catlib, config import webbrowser
# Imports predefined replacements tasks from fixes.py @@ -379,12 +380,12 @@ if self.isTextExcepted(new_text): pywikibot.output( u'Skipping %s because it contains text that is on the exceptions list.' - % page.title(asLink=True)) + % page.title(asLink=True)) break new_text = self.doReplacements(new_text) if new_text == original_text: pywikibot.output(u'No changes were necessary in %s' - % page.title(asLink=True)) + % page.title(asLink=True)) break if self.recursive: newest_text = self.doReplacements(new_text) @@ -406,7 +407,8 @@ break choice = pywikibot.inputChoice( u'Do you want to accept these changes?', - ['Yes', 'No', 'Edit', 'open in Browser', 'All', "Quit"], + ['Yes', 'No', 'Edit', 'open in Browser', 'All', + 'Quit'], ['y', 'N', 'e', 'b', 'a', 'q'], 'N') if choice == 'e': editor = editarticle.TextEditor()
pywikipedia-svn@lists.wikimedia.org