wikibase-cli 16.1.1 → 16.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/wb-remove-description +13 -0
- package/bin/wb-remove-label +13 -0
- package/bin/wb-remove-sitelink +13 -0
- package/bin/wb-set-sitelink +9 -0
- package/lib/edit/edit_command.js +9 -1
- package/lib/make_sparql_query.js +1 -1
- package/lib/output_templates.js +14 -1
- package/lib/parse_simplify_options.js +2 -1
- package/lib/tolerant_id_parser.js +2 -0
- package/metadata/remove-description.js +9 -0
- package/metadata/remove-label.js +9 -0
- package/metadata/remove-sitelink.js +9 -0
- package/metadata/set-sitelink.js +10 -0
- package/package.json +3 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const program = require('commander')
|
|
3
|
+
const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
|
|
4
|
+
const inlineArgsParser = ([ id, language ]) => {
|
|
5
|
+
return [ { id, language, value: null } ]
|
|
6
|
+
}
|
|
7
|
+
program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
|
|
8
|
+
program.customHelpOption = require('../lib/command_with_template_custom_help')
|
|
9
|
+
require('../lib/edit/edit_command')({
|
|
10
|
+
name: 'remove-description',
|
|
11
|
+
section: 'description',
|
|
12
|
+
action: 'set',
|
|
13
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const program = require('commander')
|
|
3
|
+
const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
|
|
4
|
+
const inlineArgsParser = ([ id, language ]) => {
|
|
5
|
+
return [ { id, language, value: null } ]
|
|
6
|
+
}
|
|
7
|
+
program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
|
|
8
|
+
program.customHelpOption = require('../lib/command_with_template_custom_help')
|
|
9
|
+
require('../lib/edit/edit_command')({
|
|
10
|
+
name: 'remove-label',
|
|
11
|
+
section: 'label',
|
|
12
|
+
action: 'set',
|
|
13
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const program = require('commander')
|
|
3
|
+
const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
|
|
4
|
+
const inlineArgsParser = ([ id, site ]) => {
|
|
5
|
+
return [ { id, site, title: null } ]
|
|
6
|
+
}
|
|
7
|
+
program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
|
|
8
|
+
program.customHelpOption = require('../lib/command_with_template_custom_help')
|
|
9
|
+
require('../lib/edit/edit_command')({
|
|
10
|
+
name: 'remove-sitelink',
|
|
11
|
+
section: 'sitelink',
|
|
12
|
+
action: 'set',
|
|
13
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const program = require('commander')
|
|
3
|
+
const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
|
|
4
|
+
const inlineArgsParser = ([ id, site, title, badges = '' ]) => {
|
|
5
|
+
return [ { id, site, title, badges: badges.split(/[,|]/) } ]
|
|
6
|
+
}
|
|
7
|
+
program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
|
|
8
|
+
program.customHelpOption = require('../lib/command_with_template_custom_help')
|
|
9
|
+
require('../lib/edit/edit_command')('sitelink', 'set')
|
package/lib/edit/edit_command.js
CHANGED
|
@@ -10,7 +10,15 @@ const { red } = require('chalk')
|
|
|
10
10
|
const { inspect } = require('util')
|
|
11
11
|
|
|
12
12
|
module.exports = async (section, action) => {
|
|
13
|
-
|
|
13
|
+
let name
|
|
14
|
+
if (typeof section === 'object') {
|
|
15
|
+
// Pass a name when it can not be deduced from the wikibase-edit section
|
|
16
|
+
// and action name, typically when a command uses a wikibase-edit function
|
|
17
|
+
// but with a different name
|
|
18
|
+
;({ name, section, action } = section)
|
|
19
|
+
} else {
|
|
20
|
+
name = `${action}-${section}`
|
|
21
|
+
}
|
|
14
22
|
program.process(name)
|
|
15
23
|
|
|
16
24
|
if (program.showHelp) return program.customHelpOption()
|
package/lib/make_sparql_query.js
CHANGED
|
@@ -24,7 +24,7 @@ module.exports = (sparql, format = 'json') => {
|
|
|
24
24
|
|
|
25
25
|
const makeRequest = (url, format) => {
|
|
26
26
|
const acceptHeader = formatAcceptHeader[format]
|
|
27
|
-
if (!acceptHeader) throw new Error(`
|
|
27
|
+
if (!acceptHeader) throw new Error(`unknown format: ${format}`)
|
|
28
28
|
// Avoid making a POST request when not necessary as those aren't cached
|
|
29
29
|
// see https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual#SPARQL_endpoint
|
|
30
30
|
if (url.length < 5000) {
|
package/lib/output_templates.js
CHANGED
|
@@ -13,6 +13,7 @@ const simplifyOptions = {
|
|
|
13
13
|
keepNonTruthy: true,
|
|
14
14
|
keepSnaktypes: true,
|
|
15
15
|
keepRanks: true,
|
|
16
|
+
keepBadges: true,
|
|
16
17
|
// No need to keep the hashes as every edited claim (identified with a GUID)
|
|
17
18
|
// will have it's qualifiers and references fully overriden
|
|
18
19
|
keepHashes: false
|
|
@@ -37,6 +38,18 @@ const FormatEntity = (batchMode, propsToPick, requestedPropsAndSubProps, minimiz
|
|
|
37
38
|
if (createMode) delete entity.id
|
|
38
39
|
entity = pick(entity, propsToPick)
|
|
39
40
|
dropNonSelectedSubprops(entity, requestedPropsAndSubProps)
|
|
40
|
-
if (!batchMode && minimize !== false)
|
|
41
|
+
if (!batchMode && minimize !== false) {
|
|
42
|
+
minimizeClaims(entity.claims)
|
|
43
|
+
minimizeSitelinks(entity.sitelinks)
|
|
44
|
+
}
|
|
41
45
|
return entity
|
|
42
46
|
}
|
|
47
|
+
|
|
48
|
+
const minimizeSitelinks = sitelinks => {
|
|
49
|
+
if (!sitelinks) return
|
|
50
|
+
for (const [ site, siteObj ] of Object.entries(sitelinks)) {
|
|
51
|
+
if (siteObj.badges.length === 0) {
|
|
52
|
+
sitelinks[site] = siteObj.title
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -9,7 +9,8 @@ const propsMap = {
|
|
|
9
9
|
hashes: 'keepHashes',
|
|
10
10
|
nontruthy: 'keepNonTruthy',
|
|
11
11
|
nondeprecated: 'keepNonDeprecated',
|
|
12
|
-
ranks: 'keepRanks'
|
|
12
|
+
ranks: 'keepRanks',
|
|
13
|
+
badges: 'keepBadges',
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
module.exports = ({ simplify: simplifyOption, keep: props, timeConverter }) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Accept anything looking like an id:
|
|
2
2
|
// Q33977
|
|
3
|
+
// or q33977
|
|
3
4
|
// or wd:Q33977
|
|
4
5
|
// or 33977
|
|
5
6
|
// or https://www.wikidata.org/entity/Q33977
|
|
@@ -13,6 +14,7 @@ const nestedEntityIdPattern = /L[1-9][0-9]*-(F|S)[1-9][0-9]*/
|
|
|
13
14
|
const entitySchemaIdPattern = /(E)[1-9][0-9]*/
|
|
14
15
|
|
|
15
16
|
module.exports = (options = {}) => input => {
|
|
17
|
+
input = input.toUpperCase()
|
|
16
18
|
const { allowNestedIds = false, allowEntitiesSchemasIds = false } = options
|
|
17
19
|
|
|
18
20
|
if (allowNestedIds) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
alias: 'rd',
|
|
3
|
+
args: '<entity> <language>',
|
|
4
|
+
description: 'remove a description on an entity for a given language',
|
|
5
|
+
options: require('../lib/common_options').editCommands,
|
|
6
|
+
examples: [
|
|
7
|
+
{ args: 'Q4115189 it', comment: 'Remove Q4115189 description in Italian' },
|
|
8
|
+
]
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
alias: 'rl',
|
|
3
|
+
args: '<entity> <language>',
|
|
4
|
+
description: 'remove a label on an entity for a given language',
|
|
5
|
+
options: require('../lib/common_options').editCommands,
|
|
6
|
+
examples: [
|
|
7
|
+
{ args: 'Q4115189 it', comment: 'Remove Q4115189 label in Italian' },
|
|
8
|
+
]
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
alias: 'rs',
|
|
3
|
+
args: '<entity> <site>',
|
|
4
|
+
description: 'remove a sitelink on an entity for a given site',
|
|
5
|
+
options: require('../lib/common_options').editCommands,
|
|
6
|
+
examples: [
|
|
7
|
+
{ args: 'Q4115189 enwikiquote', comment: 'Remove the link from Q4115189 to any article in the English Wikiquote' },
|
|
8
|
+
]
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
alias: 'ss',
|
|
3
|
+
args: '<entity> <site> <title> [badges]',
|
|
4
|
+
description: 'set a sitelink on an entity for a given site',
|
|
5
|
+
options: require('../lib/common_options').editCommands,
|
|
6
|
+
examples: [
|
|
7
|
+
{ args: 'Q4115189 enwikiquote "The Sandbox"', comment: "Link Q4115189 to the article 'The Sandbox' on the English Wikiquote" },
|
|
8
|
+
{ args: 'Q4115189 enwikiquote "The Sandbox" Q17437796,Q17437798', comment: 'Also set badges for that sitelink' },
|
|
9
|
+
]
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikibase-cli",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.2.0",
|
|
4
4
|
"description": "A command-line interface to Wikibase",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"shell-quote": "^1.7.3",
|
|
51
51
|
"split": "^1.0.1",
|
|
52
52
|
"through": "^2.3.8",
|
|
53
|
-
"wikibase-edit": "^5.0
|
|
54
|
-
"wikibase-sdk": "^8.
|
|
53
|
+
"wikibase-edit": "^5.2.0",
|
|
54
|
+
"wikibase-sdk": "^8.1.0",
|
|
55
55
|
"wikidata-lang": "^2.0.11"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|