-
Notifications
You must be signed in to change notification settings - Fork 81
Set up citoid proxy endpoint #699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifier is misspelled :).