Skip to content

Commit 627601a

Browse files
authored
fix(QueryContributors): display styles of anon. contributors (qiuwenbaike#1768)
* fix(QueryContributors): display styles of anon. contributors
1 parent aa39166 commit 627601a

File tree

6 files changed

+36
-28
lines changed

6 files changed

+36
-28
lines changed

dist/QueryContributors/QueryContributors.js

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

src/QueryContributors/QueryContributors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {getContributors} from './modules/util/getContributors';
1212
return;
1313
}
1414

15-
const contributors: string[] = await getContributors(wgPageName);
15+
const contributors: (string | number)[] = await getContributors(wgPageName);
1616

1717
appendElement(contributors);
1818
})();

src/QueryContributors/modules/appendElement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as OPTIONS from '../options.json';
22
import {FooterUserList} from './components/react';
33
import React from 'ext.gadget.JSX';
44

5-
const appendElement = (userNames: string[]): void => {
5+
const appendElement = (userNames: (string | number)[]): void => {
66
if (!userNames || !userNames.length) {
77
return;
88
}

src/QueryContributors/modules/components/react.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,36 @@ const FooterNotice = ({children = <></>}: FooterNoticeProps) => {
3434
};
3535

3636
interface UserListProps {
37-
userNames: string[];
37+
userNames: (string | number)[];
3838
}
3939

4040
const UserList = ({userNames}: UserListProps) => (
4141
<>
4242
<>{getMessage('Based on contributions of')}</>
4343
{userNames.map((userName, index) => (
4444
<>
45-
<a
46-
href={
47-
/(>|&gt;)/.test(userName)
48-
? mw.util.getUrl(
49-
`Special:GoToInterWiki/${sanitize(
50-
userName.replace(/(>|&gt;)/, ':User:').replace(/(>|&gt;)/g, '&gt;')
51-
)}`
52-
)
53-
: mw.util.getUrl(`User:${sanitize(userName)}`)
54-
}
55-
key={userName}
56-
>
57-
{userName}
58-
</a>
45+
{typeof userName === 'number' ? (
46+
<span key={`${userName}`}>
47+
{getMessage('Other $1 anonymous contributors').replace('$1', `${userName}`)}
48+
</span>
49+
) : (
50+
<a
51+
href={
52+
/(>|&gt;)/.test(userName)
53+
? mw.util.getUrl(
54+
`Special:GoToInterWiki/${sanitize(
55+
userName.replace(/(>|&gt;)/, ':User:').replace(/(>|&gt;)/g, '&gt;')
56+
)}`
57+
)
58+
: mw.util.getUrl(`User:${sanitize(userName)}`)
59+
}
60+
rel="noopener noreferrer"
61+
target="_blank"
62+
key={userName}
63+
>
64+
{userName}
65+
</a>
66+
)}
5967
<>{index < userNames.length - 1 ? getMessage('Seperator') : getMessage('Period')}</>
6068
</>
6169
))}

src/QueryContributors/modules/i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const getI18nMessages = () => {
1616
en: '.',
1717
zh: '。',
1818
}),
19-
'Other anonymous contributors': localize({
19+
'Other $1 anonymous contributors': localize({
2020
en: 'other $1 anonymous contributor(s)',
2121
'zh-hans': '其他$1位匿名贡献者',
2222
'zh-hant': '其他$1位匿名貢獻者',

src/QueryContributors/modules/util/getContributors.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {getMessage} from '../i18n';
21
import {queryContributors} from '../queryContributors';
32
import {uniqueArray} from 'ext.gadget.Util';
43

54
const getContributors = async (title: string) => {
6-
let pclist: string[] = [];
5+
let pclist: (string | number)[] = [];
76
let pccontinue: string | undefined;
87

98
const CACHE_KEY_PREFIX = 'ext.gadget.QueryContributors_getContributors-';
@@ -32,10 +31,7 @@ const getContributors = async (title: string) => {
3231
}
3332

3433
if (page?.anoncontributors) {
35-
pclist[pclist.length] = getMessage('Other anonymous contributors').replace(
36-
'$1',
37-
`${page.anoncontributors}`
38-
);
34+
pclist[pclist.length] = page.anoncontributors;
3935
}
4036
}
4137
} else {

0 commit comments

Comments
 (0)