|
MediaWiki讨论:Gadget-autosign.js
Ff98sha在话题“提请更改”中的最新留言:2020年4月8日 (星期三)
汉化提示文本[编辑源代码]
js文件里的"Autosign previous comment"是悬浮在按钮上时出现的提示文本,这一部分完全可以翻译成中文。如果更改后不会出错,建议将那一部分翻译成中文。——Icyphantom 讨论I贡献 2020年3月2日 (一) 03:11 (UTC)
- 已由Cuervo 完成。--葉月 桐§ 2020年3月2日 (一) 12:47 (UTC)
提请更改[编辑源代码]
原脚本对date.getUTCMonth
使用不当,因为其是从0开始计数。
现对其修复,请管理员更改。
// pads a time to 2 digits
function padtime(time) {
return (time + '').padStart(2, '0');
}
$(function() {
'use strict';
// only run when editing
if (mw.user.options.get('showtoolbar') &&
mw.user.options.get('usebetatoolbar') &&
$.inArray(mw.config.get('wgAction'), ['edit', 'submit']) > -1) {
// wait on the API library
$.when(mw.loader.using('mediawiki.api'), $.ready).then(function() {
// fetch the username and timestamp of the last revision
new mw.Api().get({
action: 'query',
titles: mw.config.get('wgPageName'),
prop: 'revisions',
rvprop: 'user|timestamp',
formatversion: 2
}).done(function(data) {
var page = data.query.pages[0];
// if the revision is missing, skip
if (page.missing) {
return;
}
// fetch data from the revision
var revision = page.revisions[0];
var user = revision.user;
var date = new Date(revision.timestamp);
// on the odd chance it fails to parse the date, skip date
var insert;
if (isNaN(date.getTime())) {
insert = '{{subst:'+'unsigned|'+user+'}}';
} else {
// wish there was an easier way to do this, I miss moment.js
var timestamp = padtime(date.getUTCFullYear() + '年' +date.toLocaleDateString('zh-cn', {month:'long', timeZone:'UTC'}) + +date.getUTCDate() + '日 ' + padtime(date.getUTCHours()) + ':' + date.getUTCMinutes());
insert = '{{subst:'+'unsigned|'+user+'|'+timestamp+'}}';
}
// add the editor button
$.when(mw.loader.using('ext.wikiEditor'), $.ready).then(function() {
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'insert',
tools: {
autosign: {
label: '自动签名上一次留言',
type: 'button',
icon: 'https://upload.wikimedia.org/wikipedia/commons/b/b3/Insert-signature.svg',
action: {type: 'replace', options: {pre: insert}}
}
}
});
});
});
});
}
});
-- Dianliang233 T•C 2020年4月8日 (三) 02:56 (UTC)
- 已完成。--
Ff98sha(讨论·贡献) 2020年4月8日 (三) 03:01 (UTC)