Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config.example.wikimedia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ default_project: &default_project
host: http://appservice.wmflabs.org
related:
cache_control: s-maxage=86400, max-age=86400
citoid:
host: http://citoid-beta.wmflabs.org
# 10 days Varnish caching, one day client-side
purged_cache_control: s-maxage=864000, max-age=86400
skip_updates: false
Expand Down
2 changes: 2 additions & 0 deletions config.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ default_project: &default_project
cache-control: s-maxage=864000, max-age=86400
mobileapps:
host: http://appservice.wmflabs.org
citoid:
host: http://citoid-beta.wmflabs.org
events: {}
purged_cache_control: test_purged_cache_control
skip_updates: false
Expand Down
4 changes: 4 additions & 0 deletions projects/wmf_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ paths:
x-modules:
- path: v1/mathoid.yaml
options: '{{options.mathoid}}'
/data:
x-modules:
- path: v1/citoid.js
options: '{{options.citoid}}'
options: '{{options}}'

/{api:sys}:
Expand Down
4 changes: 4 additions & 0 deletions projects/wmf_wiktionary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ paths:
x-modules:
- path: v1/mathoid.yaml
options: '{{options.mathoid}}'
/data:
x-modules:
- path: v1/citoid.js
options: '{{options.citoid}}'
options: '{{options}}'

/{api:sys}:
Expand Down
48 changes: 48 additions & 0 deletions v1/citoid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

const HyperSwitch = require('hyperswitch');
const P = require('bluebird');
const mwUtil = require('../lib/mwUtil');
const spec = HyperSwitch.utils.loadSpec(`${__dirname}/citoid.yaml`);

class Citoid {
constructor(options) {
this._options = options;
}

getCitation(hyper, req) {
const rp = req.params;
let acceptLanguagePromise;
if (req.headers && req.headers['accept-language']) {
acceptLanguagePromise = P.resolve(req.headers['accept-language']);
} else {
acceptLanguagePromise = mwUtil.getSiteInfo(hyper, req).get('general').get('lang');
}
return acceptLanguagePromise.then((acceptLanguage) => {
let reqURI;
if (rp.format === 'mediawiki-basefields') {
reqURI = `${this._options.host}/api?format=mediawiki&`
+ `search=${encodeURIComponent(rp.query)}&basefields=true`;
} else {
reqURI = `${this._options.host}/api?format=${rp.format}&`
+ `search=${encodeURIComponent(rp.query)}`;
}
return hyper.get({
uri: reqURI,
headers: {
'accept-language': acceptLanguage
}
});
});
}
}

module.exports = (options) => {
const citoid = new Citoid(options);
return {
spec,
operations: {
getCitation: citoid.getCitation.bind(citoid)
}
};
};
105 changes: 105 additions & 0 deletions v1/citoid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
swagger: '2.0'
info:
version: '1.0.0-beta'
title: MediaWiki Citation API
description: Citation API based on the Citoid services
termsOfService: https://github.com/wikimedia/restbase#restbase
contact:
name: Services
email: services@lists.wikimedia.org
url: https://www.mediawiki.org/wiki/Services
license:
name: Apache licence, v2
url: https://www.apache.org/licenses/LICENSE-2.0
paths:
/citation/{format}/{query}:
get:
tags:
- Citation
summary: Get citation data given an article identifyer.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifier is misspelled :).

description: |
Generates citation data given a URL, DOI, PMID, or PMCID.

See more at [Citoid service documentation](https://www.mediawiki.org/wiki/Citoid)

The citation data could be requested in one of the following formats:
- `bibtex`: format used to describe and process lists of references,
mostly in conjunction with LaTeX documents. See [bibtex.org](http://www.bibtex.org/).
- `zotero`: format used by the [Zotero](https://www.zotero.org/) research tool.
- `mediawiki`: format designed specifically for MediaWiki to be used with `templateData`.
- `mediawiki-basefields`: `mediawiki` format extended with Zotero `basefields`

Stability: [experimental](https://www.mediawiki.org/wiki/API_versioning#Experimental)
produces:
- application/json; charset=utf-8;
- application/x-bibtex; charset=utf-8
parameters:
- name: format
in: path
description: "The format to use for the resulting citation data"
enum:
- bibtex
- zotero
- mediawiki
- mediawiki-basefields
required: true
- name: query
in: path
description: >
URL of an article, DOI, PMCID or PMID in the URL-encoded format.
Note that on the Swagger-UI doc page you don't need to URI-encode the
parameter manually, it will be done by the docs engine.
type: string
required: true
- name: Accept-Language
in: header
type: string
required: false
description: >
For some articles the result depends on the `Accept-Language` header, so
provide it if localized content is required.
responses:
'200':
description: The citation data in the requested format
'404':
description: Citation data was not found.
schema:
$ref: '#/definitions/problem'
default:
description: Error
schema:
$ref: '#/definitions/problem'

operationId: getCitation
x-monitor: true
x-amples:
- title: Get citation for Darth Vader
request:
params:
domain: en.wikipedia.org
format: bibtex
query: 'https://en.wikipedia.org/wiki/Darth_Vader'
responce:
status: 200
headers:
content-type: /^application\/x-bibtex/
body:
title: 'Darth Vader'
language: en
itemType: encyclopediaArticle
encyclopediaTitle: Wikipedia

definitions:
# A https://tools.ietf.org/html/draft-nottingham-http-problem
problem:
required:
- type
properties:
type:
type: string
title:
type: string
detail:
type: string
instance:
type: string