Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Wiki API Access Notes

Some Eclipse projects require documentation in multiple formats, a few of which are not standard within the Eclipse community such as LaTeX. Writing the same documentation in multiple formats is not sustainable, so ideally some solution could be developed where one canonical format is used and other formats are translations. Then, after the necessary translations are made, any wiki documents could be uploaded by using the MediaWiki api.

Accessing the MediaWiki API

The MediaWiki API for Eclipse.org is available at https://wiki.eclipse.org/api.php. Standard Eclipse.org wiki credentials are required to access the API.

Example with Eclipse ICE

Eclipse ICE uses LaTeX as its base documentation format and Pandoc to translate between LaTeX, MediaWiki and other formats. The Eclipse ICE team uses mwclient to connect to the Eclipse.org MediaWiki API.

Here is an example from the mwclient Github page showing how the wiki is manipulated programmatically:

# Get username and password from args
...<insert such code here>...

# Initialize Site object
import mwclient
site = mwclient.Site('commons.wikimedia.org')
site.login(username, password)

# Edit page
page = site.Pages['Commons:Sandbox']
text = page.text()
print 'Text in sandbox:', text.encode('utf-8')
page.save(text + u'\nExtra data', summary = 'Test edit')

# Printing imageusage
image = site.Images['Example.jpg']
print 'Image', image.name.encode('utf-8'), 'usage:'
for page in image.imageusage():
        print 'Used:', page.name.encode('utf-8'), '; namespace', page.namespace
        print 'Image info:', image.imageinfo

# Uploading a file
site.upload(open('file.jpg'), 'destination.jpg', 'Image description')

# Listing all categories (don't do this in reality)
for category in site.allcategories():
        print category

The Eclipse ICE team has adapted this script to upload synchronized edits from regularly regenerated LaTeX documentation to the wiki.

Back to the top