ညးလွပ်:Crowley666/js/export.js
မံက်ပြာကတ်
(ကလေၚ်ထ္ၜး နူ ညးလွပ်:EdwardAlexanderCrowley/js/export.js)
တင်စၟတ်: ကြဴနူ မသီဂိုင်တုဲ တၞဟ်နမဂွံညာတ် အပြံင်အလှာဲ မၞးသ္ဒးကၟာတ်ထောအ် မုက်လိက်ဗြောဝ်သာဂှ်ရောင်။
- Firefox / Safari:မ္ဂး ဍဵုလဝ် Shift အဃောမဍဵု Reload၊ ဟွံသေင်မ္ဂး ဍဵု either Ctrl-F5 ဟွံသေင်မ္ဂး Ctrl-R (⌘-R သွက် Mac)
- Google Chrome:မ္ဂး ဍဵု Ctrl-Shift-R (⌘-Shift-R သွက် Mac)
- Internet Explorer / Edge:မ္ဂး ဍဵုလဝ် Ctrl အဃော မဍဵု Refresh, ဟွံသေင်မ္ဂး ဍဵု Ctrl-F5
- Opera: မ္ဂး ဍဵု Ctrl-F5။
// 见[[mw:Manual:CORS]]、[[mw:API:Cross-site requests]]
mw.loader.using('mediawiki.ForeignApi');
var pn = mw.config.get('wgPageName');
if (pn.startsWith('User:Qnm/') || // User:Qnm/9至99随便用
pn.startsWith('Template:') || pn.startsWith('Module:')) {
mw.util.addPortletLink('p-cactions', 'javascript:exportpage()', '导出页面', 'ca-export-page',
'导出页面', '', document.getElementById('ca-history')); // 快捷键设为''
mw.util.addPortletLink('p-cactions', 'javascript:exportdoc()', '导出文档', 'ca-export-doc',
'导出文档', '', document.getElementById('ca-history'));
mw.util.addPortletLink('p-cactions', 'javascript:exportboth()', '导出两者', 'ca-export-both',
'导出两者', '', document.getElementById('ca-history'));
} else if (pn == 'Wiktionary:Sandbox') {
mw.util.addPortletLink('p-cactions', 'javascript:exportsandbox()', '导出沙盒', 'ca-export-sandbox',
'导出沙盒', '', document.getElementById('ca-history'));
mw.util.addPortletLink('p-cactions', 'javascript:revertsandbox()', '复原沙盒', 'ca-revert-sandbox',
'复原沙盒', '', document.getElementById('ca-history'));
}
function exportpage() {
var from = pn, to = pn;
exportpagecore(from, to);
}
function exportdoc() {
var from = pn, to = pn;
if (!from.endsWith('/documentation')) {
from = from + '/documentation';
to = to + '/documentation';
}
if (mw.config.get('wgWikibaseItemId')) {
link = $("a.interlanguage-link-target[lang='mnw']").attr('href');
if (link) {
to = decodeURI(link.split('/wiki/')[1]) + '/documentation';
}
}
exportpagecore(from, to);
}
function exportboth() {
var from = pn, to = pn;
if (from.endsWith('/documentation')) {
from = from.replace('/documentation', '');
to = to.replace('/documentation', '');
}
[from, to] = exportpagecore(from, to);
exportpagecore(from + '/documentation', to + '/documentation');
}
function exportsandbox() {
exportpagecore('Wiktionary:Sandbox', 'Wiktionary:Sandbox');
}
function revertsandbox() {
const api = new mw.ForeignApi('https://mnw.wiktionary.org/w/api.php');
api.postWithToken('csrf', {
action: 'edit',
title: 'Wiktionary:Sandbox',
text: '{{sandbox}}',
summary: '复原沙盒'
}).fail(function(){ mw.notify('复原失败'); }).done(function(){ mw.notify('复原成功'); });
}
function exportpagecore(from, to) {
if (mw.config.get('wgWikibaseItemId')) {
link = $("a.interlanguage-link-target[lang='mnw']").attr('href');
if (link) {
to = decodeURI(link.split('/wiki/')[1]);
}
}
var apifrom = new mw.Api();
apifrom.get({
action: 'query',
titles: from,
prop: 'revisions|langlinks',
indexpageids: 1,
rvprop: 'content',
lllang: 'mnw'
}).then(function(result) {
result = result.query;
var rpage = result.pages[result.pageids[0]];
if (rpage.langlinks) {
to = rpage.langlinks[0]['*'];
}
var text = rpage.revisions[0]['*'];
var summary = '[[User:EdwardAlexanderCrowley/js/import.js|搬运]]自[[:en:' + from + ']]';
if (from == 'Wiktionary:Sandbox') text = '{{sandbox}}\n' + text;
const apito = new mw.ForeignApi('https://mnw.wiktionary.org/w/api.php');
return apito.postWithToken('csrf', {
action: 'edit',
title: to,
text: text,
summary: summary,
}).fail(function() {
mw.notify('搬运失败');
}).then(function() {
mw.notify('搬运成功');
if (!rpage.langlinks && canlink(from)) {
const apidata = new mw.ForeignApi('https://www.wikidata.org/w/api.php');
apidata.postWithToken('csrf', {
action: 'wblinktitles',
fromsite: 'enwiktionary',
fromtitle: from,
tosite: 'mnwwiktionary',
totitle: to,
bot: 1
}).fail(function() {
mw.notify('链接失败,可能需要IPBE');
}).done(function() {
mw.notify('链接成功');
});
}
});
});
return [from, to];
}
function canlink(p) {
return !(p.endsWith('/documentation') || p.endsWith('/documentation')
|| p.endsWith('/testcase') || p.endsWith('/testcases')
|| p.startsWith('User:') ||p.startsWith('Module:User:'));
}