Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys, os
if len(sys.argv) > 3:
sys.path.append(os.path.abspath(sys.argv[3]))
if len(sys.argv) < 3:
print 'python basic_edit_test.py <config> <prefix> [<include path>]'
print
sys.exit()
## Create a config file containing:
# host = 'test.wikipedia.org'
# path = '/w/'
# ext = '.php'
# username = 'Bryan'
# password = 'xyz'
prefix = sys.argv[2]
#import cgitb; cgitb.enable(format = 'text')
try:
import apiedit as mwclient
except ImportError:
import mwclient
site = mwclient.ex.ConfiguredSite(sys.argv[1])
site.compress = False
print 'Running configured site', sys.argv[1]
print 'Site has writeapi:', getattr(site, 'writeapi', False)
page = site.Pages[prefix + '/text1']
print 'Editting page1'
page.edit()
text1 = u"""== [[Test page]] ==
This is a [[test]] page generated by [http://mwclient.sourceforge.org/ mwclient].
This test is done using the [[w:mw:API]]."""
comment1 = 'Test page1'
page.save(text1, comment1)
rev = page.revisions(limit = 1, prop = 'timestamp|comment|content').next()
assert rev['comment'] == comment1, rev
assert rev['*'] == rev['*'], rev
print 'Page editted on', rev['timestamp']
print 'Links:', list(page.links(generator = False))
print 'External links:', list(page.extlinks())
print 'Uploading image'
site.upload(open('test-image.png', 'rb'), prefix + '-test-image.png', 'desc', ignore = True)
print 'Uploading image for the second time'
site.upload(open('test-image.png', 'rb'), prefix + '-test-image.png', 'desc', ignore = True)
image = site.Images[prefix + '-test-image.png']
print 'Imageinfo:', image.imageinfo
history = list(image.imagehistory())
print 'History:', history
if site.writeapi:
print 'Deleting old version'
archivename = history[1]['archivename']
image.delete('Testing history deletion', oldimage = archivename)
print 'History:', list(image.imagehistory())
text = page.edit()
text += u'\n[[Image:%s-test-image.png]]' % prefix
page.save(text, 'Adding image')
print 'Images:', list(page.images(generator = False))
print 'Cleaning up'
image.delete('Cleanup')
page.delete('Cleanup')
print 'Done'