5 def title(prefix, new_format):
7 return prefix + 'title'
12 def userinfo(data, new_format=None):
13 if new_format is None:
14 # Unknown version; trying to guess
15 if 'userinfo' in data:
16 return data['userinfo']
17 elif 'userinfo' in data.get('query', ()):
18 return data['query']['userinfo']
22 return data['query']['userinfo']
24 return data['userinfo']
28 if version[:2] >= (1, 13):
29 return 'timestamp|user|comment|url|size|sha1|metadata|archivename'
30 if version[:2] >= (1, 12):
31 return 'timestamp|user|comment|url|size|sha1|metadata'
33 return 'timestamp|user|comment|url|size|sha1'
36 def cmtitle(page, new_format, prefix=''):
38 return prefix + 'title', page.name
40 return prefix + 'category', page.strip_namespace(page.name)
43 def protectright(version):
44 if version[:2] >= (1, 13):
45 return 'editprotected'
49 from cStringIO import StringIO
52 def old_upload(self, file, filename, description, license='', ignore=False, file_size=None):
53 image = self.Images[filename]
54 if not image.can('upload'):
55 raise errors.InsufficientPermission(filename)
56 if image.exists and not ignore:
57 raise errors.FileExists(filename)
64 file_size = file.tell()
68 # Do this thing later so that an incomplete upload won't work
69 # predata['wpDestFile'] = filename
70 predata['wpUploadDescription'] = description
71 predata['wpLicense'] = license
73 predata['wpIgnoreWarning'] = 'true'
74 predata['wpUpload'] = 'Upload file'
75 predata['wpSourceType'] = 'file'
76 predata['wpDestFile'] = filename
77 predata['wpEditToken'] = image.get_token('edit')
79 postdata = upload.UploadFile('wpUploadFile', filename, file_size, file, predata)
81 wait_token = self.wait_token()
84 self.connection.post(self.host,
85 self.path + 'index.php?title=Special:Upload&maxlag='
86 + self.max_lag, data=postdata).read()
87 except errors.HTTPStatusError, e:
88 if e[0] == 503 and e[1].getheader('X-Database-Lag'):
89 self.wait(wait_token, int(e[1].getheader('Retry-After')))
90 elif e[0] < 500 or e[0] > 599:
94 except errors.HTTPError: