Skip to content

Commit cdca9f3

Browse files
authored
feat(add): Editform_Attribution (qiuwenbaike#1697)
1 parent 72f1992 commit cdca9f3

File tree

17 files changed

+1154
-0
lines changed

17 files changed

+1154
-0
lines changed

dist/Editform_Attribution/Editform_Attribution.js

Lines changed: 571 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/definition.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
* EditCount[ResourceLoader|rights=edit|skins=gongbi,vector,vector-2022|requiresES6]|EditCount.js
101101
* EditForm[ResourceLoader|hidden|rights=edit|requiresES6]|EditForm.css
102102
* Editform_AiAssisted[ResourceLoader|default|dependencies=ext.gadget.i18n,ext.gadget.Util,mediawiki.util,oojs-ui-core|rights=edit|requiresES6]|Editform_AiAssisted.js
103+
* Editform_Attribution[ResourceLoader|dependencies=ext.gadget.i18n,ext.gadget.Util,mediawiki.util,oojs-ui-core|rights=edit|requiresES6]|Editform_Attribution.js
103104
* EditForm_JS[ResourceLoader|dependencies=ext.gadget.i18n,ext.gadget.Util,mediawiki.util,oojs-ui-core|hidden|peers=EditForm|rights=edit|requiresES6]|EditForm_JS.js
104105
* Editform_Patch2017[ResourceLoader|default|dependencies=ext.gadget.i18n,ext.gadget.Util,mediawiki.jqueryMsg|hidden|rights=edit|requiresES6]|Editform_Patch2017.js
105106
* Edittools-customizeToolbar[ResourceLoader|actions=edit|dependencies=ext.gadget.Util,ext.wikiEditor,user.options|hidden|requiresES6]|Edittools-customizeToolbar.js

src/DefaultSummaries/modules/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ type Ve = {
22
readonly init: {
33
target: {
44
saveDialog: {
5+
on(arg0: string, arg1: () => void): unknown;
56
$saveCheckboxes: JQuery<HTMLElement>;
67
$element: JQuery<HTMLElement>;
78
$saveOptions: JQuery;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as OPTIONS from './options.json';
2+
import {getBody} from 'ext.gadget.Util';
3+
import {processVisualEditor} from './modules/processVisualEditor';
4+
import {processWikiEditor} from './modules/processWikiEditor';
5+
6+
/**
7+
* @description 第三方来源特殊声明
8+
*/
9+
void getBody().then(function editForm($body: JQuery<HTMLBodyElement>): void {
10+
mw.hook('wikipage.editform').add(($editForm): void => {
11+
processWikiEditor({
12+
$body,
13+
$editForm,
14+
});
15+
});
16+
17+
mw.hook('ve.saveDialog.stateChanged').add((): void => {
18+
processVisualEditor({
19+
$body,
20+
});
21+
});
22+
23+
// When switching between VE and NWE, re-initialization is required
24+
mw.hook('ve.activationComplete').add(() => {
25+
if (mw.config.get(OPTIONS.configKey)) {
26+
mw.config.set(OPTIONS.configKey, false);
27+
}
28+
});
29+
});

src/Editform_Attribution/LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* SPDX-License-Identifier: CC-BY-SA-4.0
3+
* _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}'
4+
*
5+
* @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/Editform_Attribution}
6+
* @license CC-BY-SA-4.0 {@link https://www.qiuwenbaike.cn/wiki/H:CC-BY-SA-4.0}
7+
*/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"enable": false,
3+
"description": "<sup><abbr title=\"默认为所有注册用户启用\">U</abbr></sup><span id=\"Gadget-Editform_Attribution\"></span> 声明编辑在人工智能(AI)辅助下进行",
4+
"section": "edit",
5+
"excludeSites": ["loginwiki", "mncqiuwenbaike"],
6+
"dependencies": ["ext.gadget.i18n", "ext.gadget.Util", "mediawiki.util", "oojs-ui-core"],
7+
"rights": ["edit"]
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const LICENSES = [
2+
{
3+
label: 'CC BY-SA 4.0',
4+
data: 'https://creativecommons.org/licenses/by-sa/4.0/',
5+
},
6+
{
7+
label: 'CC BY-SA 3.0',
8+
data: 'https://creativecommons.org/licenses/by-sa/3.0/',
9+
},
10+
{
11+
label: 'CC BY-SA 3.0 CN',
12+
data: 'https://creativecommons.org/licenses/by-sa/3.0/cn/',
13+
},
14+
{
15+
label: 'CC0-1.0',
16+
data: 'https://creativecommons.org/publicdomain/zero/1.0/',
17+
},
18+
{
19+
label: 'KOGL Type I: Attribution',
20+
data: 'https://www.kogl.or.kr/info/licenseType1.do',
21+
},
22+
];
23+
24+
export {LICENSES};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {localize} from 'ext.gadget.i18n';
2+
3+
const getI18nMessages = () => {
4+
return {
5+
Add: localize({
6+
en: 'Add',
7+
zh: '增加',
8+
}),
9+
Delete: localize({
10+
en: 'Delete',
11+
zh: '移除',
12+
}),
13+
Source: localize({
14+
en: 'Source',
15+
'zh-hans': '内容来源',
16+
'zh-hant': '內容來源',
17+
}),
18+
License: localize({
19+
en: 'License',
20+
'zh-hans': '许可证',
21+
'zh-hant': '許可證',
22+
}),
23+
'Sources and Licenses': localize({
24+
en: 'Sources and Licenses',
25+
'zh-hans': '内容来源及许可证',
26+
'zh-hant': '內容來源及許可證',
27+
}),
28+
ThirdPartyContentContained: localize({
29+
en: 'This editor contains third-party content.',
30+
'zh-hans': '此编辑含有第三方内容',
31+
'zh-hant': '此編輯含有第三方內容',
32+
}),
33+
QiuwenContentContained: localize({
34+
en: 'This editor contains content from other pages of Qiuwen Baike.',
35+
'zh-hans': '此编辑含有求闻百科其他页面的内容',
36+
'zh-hant': '此編輯含有求聞百科其他頁面的內容',
37+
}),
38+
};
39+
};
40+
41+
const i18nMessages = getI18nMessages();
42+
43+
const getMessage: GetMessages<typeof i18nMessages> = (key) => {
44+
return i18nMessages[key] || key;
45+
};
46+
47+
export {getMessage};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as OPTIONS from '~/Editform_Attribution/options.json';
2+
import {generateVisualEditorCheckboxLayout} from './util/generateCheckboxLayout';
3+
import {getMessage} from './i18n';
4+
5+
const processVisualEditor = ({$body}: {$body: JQuery<HTMLBodyElement>}): void => {
6+
// Guard against double inclusions
7+
if (mw.config.get(OPTIONS.configKey)) {
8+
return;
9+
}
10+
11+
const $target: JQuery = $body.find(`.${OPTIONS.targetClassVe}`);
12+
if (!$target.length) {
13+
return;
14+
}
15+
16+
mw.config.set(OPTIONS.configKey, true);
17+
18+
const get$Layout = () => {
19+
return generateVisualEditorCheckboxLayout({
20+
inputId: OPTIONS.inputId,
21+
label: getMessage('ThirdPartyContentContained'),
22+
// changeTag: OPTIONS.changeTag,
23+
$body,
24+
});
25+
};
26+
27+
const $layout = get$Layout();
28+
29+
if (!$body.find(`#${OPTIONS.inputId}`).length) {
30+
$target.append($layout);
31+
}
32+
33+
const {target} = window.ve.init;
34+
const {saveDialog} = target;
35+
36+
saveDialog.on('save', () => {
37+
$layout.replaceWith(get$Layout());
38+
});
39+
};
40+
41+
export {processVisualEditor};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as OPTIONS from '~/Editform_Attribution/options.json';
2+
import {generateWikiEditorCheckboxLayout} from './util/generateCheckboxLayout';
3+
import {getMessage} from './i18n';
4+
5+
const processWikiEditor = ({$body, $editForm}: {$body: JQuery<HTMLBodyElement>; $editForm: JQuery}): void => {
6+
// Guard against double inclusions
7+
if (mw.config.get(OPTIONS.configKey)) {
8+
return;
9+
}
10+
11+
const $target: JQuery = $editForm.find(OPTIONS.targetWikiEditor);
12+
if (!$target.length) {
13+
return;
14+
}
15+
16+
mw.config.set(OPTIONS.configKey, true);
17+
18+
const get$Layout = () => {
19+
return generateWikiEditorCheckboxLayout({
20+
inputId: OPTIONS.inputId,
21+
label: getMessage('ThirdPartyContentContained'),
22+
$body,
23+
$editForm,
24+
// changeTag: OPTIONS.changeTag,
25+
});
26+
};
27+
28+
const $layout = get$Layout();
29+
30+
if (!$body.find(`#${OPTIONS.inputId}`).length) {
31+
$target.after($layout);
32+
}
33+
34+
$editForm.on('submit', () => {
35+
$layout.replaceWith(get$Layout());
36+
});
37+
};
38+
39+
export {processWikiEditor};

0 commit comments

Comments
 (0)