mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2025-04-22 06:11:32 -06:00
Added MediaWiki (hopefully correctly this time)
This commit is contained in:
parent
496be64e82
commit
b9bc3c84a4
2 changed files with 157 additions and 0 deletions
src/serviceProviders
|
@ -43,6 +43,7 @@ import * as discord from './discord.js'
|
|||
import * as bsky from './bsky.js'
|
||||
import * as sourcehut from './sourcehut.js'
|
||||
import * as pronounspage from './pronounspage.js'
|
||||
import * as mediawiki from './mediawiki.js'
|
||||
|
||||
const _data = {
|
||||
aspe,
|
||||
|
|
156
src/serviceProviders/mediawiki.js
Normal file
156
src/serviceProviders/mediawiki.js
Normal file
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
Copyright 2025 Daniel Levi
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* MediaWiki service provider ({@link https://docs.keyoxide.org/service-providers/mediawiki/|Keyoxide docs})
|
||||
* @module serviceProviders/mediawiki
|
||||
* @example
|
||||
* import { ServiceProviderDefinitions } from 'doipjs';
|
||||
* const sp = ServiceProviderDefinitions.data.matrix.processURI('http(s)://domain.tld/script_path/index.php?title=TITLE&revid=REVID');
|
||||
*/
|
||||
|
||||
import * as E from "../enums.js";
|
||||
import { ServiceProvider } from "../serviceProvider.js";
|
||||
|
||||
// [1] - MediaWiki script path
|
||||
// [2] - Revision ID
|
||||
export const reURI = /^(https?:\/\/[^/]+\/(?:[^/]+\/)*)index\.php\?(?:[^&]*&)*(?:oldid|revid)=([^&#]+)(?:&.*)?$/;
|
||||
|
||||
/**
|
||||
* @function
|
||||
* @param {string} uri - Claim URI to process
|
||||
* @returns {ServiceProvider} The service provider information based on the claim URI
|
||||
*/
|
||||
export function processURI(uri) {
|
||||
const match = uri.match(reURI);
|
||||
|
||||
return new ServiceProvider({
|
||||
about: {
|
||||
id: "mediawiki",
|
||||
name: "MediaWiki Wiki",
|
||||
homepage: null,
|
||||
},
|
||||
profile: {
|
||||
display: "Unknown username",
|
||||
uri: null,
|
||||
qr: null,
|
||||
},
|
||||
claim: {
|
||||
uriRegularExpression: reURI.toString(),
|
||||
uriIsAmbiguous: true,
|
||||
},
|
||||
proof: {
|
||||
request: {
|
||||
uri: `${match[1]}index.php?oldid=${match[2]}`,
|
||||
fetcher: E.Fetcher.HTTP,
|
||||
accessRestriction: E.ProofAccessRestriction.NOCORS,
|
||||
data: {
|
||||
url: `${match[1]}api.php?action=query&format=json&formatversion=2&prop=revisions&&revids=${match[2]}&rvprop=user%7Ccontent%7Ccomment&meta=siteinfo&siprop=general%7Cnamespaces`,
|
||||
format: E.ProofFormat.JSON,
|
||||
},
|
||||
},
|
||||
response: {
|
||||
format: E.ProofFormat.JSON,
|
||||
},
|
||||
target: [
|
||||
{
|
||||
format: E.ClaimFormat.URI,
|
||||
encoding: E.EntityEncodingFormat.PLAIN,
|
||||
relation: E.ClaimRelation.EQUALS,
|
||||
path: ["query", "pages", "revisions", "content"],
|
||||
},
|
||||
{
|
||||
format: E.ClaimFormat.URI,
|
||||
encoding: E.EntityEncodingFormat.PLAIN,
|
||||
relation: E.ClaimRelation.EQUALS,
|
||||
path: ["query", "pages", "revisions", "comment"],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export const functions = {
|
||||
postprocess: async (claimData, proofData, opts) => {
|
||||
const match = claimData.proof.request.uri.match(reURI);
|
||||
|
||||
claimData.about.name = proofData.result.query.general.sitename;
|
||||
claimData.about.homepage = proofData.result.query.general.base;
|
||||
|
||||
const userName = `${proofData.result.query.namespaces["2"].name}:${proofData.result.query.pages[0].revisions[0].user}`;
|
||||
|
||||
claimData.profile.display = userName;
|
||||
claimData.profile.uri = `${match[1]}index.php?title=${encodeURIComponent(
|
||||
userName.replace(/ /g, "_")
|
||||
)}`;
|
||||
|
||||
return { claimData, proofData };
|
||||
},
|
||||
};
|
||||
|
||||
export const tests = [
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?oldid=1234",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/index.php?oldid=1234",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?title=Some_title&oldid=1234",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?oldid=1234&title=Some_title",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?revid=1234",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/index.php?revid=1234",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?title=Some_title&revid=1234",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?revid=1234&title=Some_title",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/w/index.php?title=Some_title",
|
||||
shouldMatch: false,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/wiki/Some_title",
|
||||
shouldMatch: false,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/wiki/Some_title?oldid=1234",
|
||||
shouldMatch: false,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/wiki/Some_title?revid=1234",
|
||||
shouldMatch: false,
|
||||
},
|
||||
{
|
||||
uri: "https://somewiki.tld/",
|
||||
shouldMatch: false,
|
||||
},
|
||||
];
|
Loading…
Add table
Add a link
Reference in a new issue