Help:Extension:OttrParser/API

The Extension:OttrParser comes with an API to import and export .stotter files.

Comprehensive documentation can be found on the main page of the running instance, this will most likely be http://localhost:5000/.

Settings edit

An example config is included. You need to insert your own wikiurl.

[SERVER]
port=5000

# relative or absolute path to logifle
logfile_path=ottr_server.log

# python logging library ligging level.
# One of DEBUG, INFO, WARNIN, ERROR, CRITICAL
loglevel=DEBUG


[WIKI]
# The base url of you mediawiki, needs to end with a '/' !
# The example is applicable for a mediawiki with main page url 'http://localhost/mediawiki-1.37.1/index.php/Main_Page'
wikiurl=http://localhost/mediawiki-1.37.1/

# Get these from you mediawikis Special:BotPasswords page.
# The option $wgEnableBotPasswords must be set to true in the Localsettings.php

# More on this here: https://www.mediawiki.org/wiki/Manual:Bot_passwords
bot_user_name=Oliver Tautz@ottrbot
bot_user_password=ceilaco9nmc2o33ub9t2740fnek227sn

Change values as desired. Afterward, you can start the API.

Start the API edit

Use

python3 /includes/ottrToSmwPython/ottrServer.py --config /path/to/config

with your config file to start the API. You can then find more docs at http://localhost:5000/.

Bot Passwords (Optional) edit

To use the API you can use Mediawiki-API credentials. For this, you must enable Bot Passwords by adding

$wgEnableBotPasswords=true;

to your LocalSettings.php. Afterwards go to the Special:BotPasswords page of your wiki, create a new bot password and write down the username and password.

This way all edits will be done by a single user. Otherwise they will be done by a user without login.

Export edit

The API provides 4 endpoints to export .stottr data from mediawiki:

/ottr_get/api/get_all
/ottr_get/api/get_instances
/ottr_get/api/get_prefixes
/ottr_get/api/get_templates

All endpoints can be accessed with a simple get request :

curl -X 'GET' \
  'http://localhost:5001/ottr_get/api/get_templates' \
  -H 'accept: application/json'

and return a JSON object of the form

{
  "templates": "string",
  "instances": "string",
  "prefixes": "string"
}

containing valid .stottr syntax strings.

Import edit

To import all data from a .stottr file into the wiki the endpoint

ottr_post/api/stottr_file

is used. A minimal example in python looks like this:

import requests

file = open('stottr_file.stotter')
data = file.read()
file.close()

body = {"data": data,
        "template_namespace": "Template",
        "instance_namespace": "",
        "overwrite":"True"
}

r = requests.post("http://127.0.0.1:5000/ottr_post/api/stottr_file",json=body)

print(r.text)

data contains a full .stottr file as string.

template_namespace and instance_namespace can be set to put imported templates or instances in a namespace.

overwrite can be set to overwrite existing pages. If set to False, existing pages will not be updated.

The API will do the following things when importing: edit

  • Create a new wikipage for each template in the .stotter file
  • Create a new wikipage for each instance in the .stotter file
  • Add prefixes present in the .stottr file to the Ottr:OttrPrefixes page
  • create list entries in the Special:OttrApiEdits page