16,874
个编辑
LLWiki正在建设中,欢迎加入我们!
小 |
|||
"use strict";
/*global mw, $, OO, CodeMirror*/
mw.loader.using( 'mediawiki.util' ).then(() => {
let
const
script = mw.config.get('wgScript'),
urlDisplay = $('<a>', {href: "#"}).click(e => { e.preventDefault(); }),
css = mw.util.addCSS( '#mw-content-text .mw-parser-output p { border:1px dashed; }' +
cssHide = mw.util.addCSS( '.inspector > div:last-child { margin-bottom:0.5em; }' +
'.inspector { position:fixed; right:24px; left:unset !important; width:calc(50% - 7rem - 0.5px); }' );
cssHide.disabled = true;
const outer = $('<div>', {class: 'inspector mw-ajax-loader'}).insertBefore( original )
.on('contextmenu', '.cm-mw-template-name, .cm-mw-link-pagename', function(e) {
e.preventDefault();
promise = dialog ? Promise.resolve() : mw.loader.using( 'oojs-ui-windows' ).then(() => {
actionP = new OO.
actionD = new OO.ui.ActionWidget({label: '否', flags: 'destructive'});
if (!mw.windowManager) {
mw.windowManager = new OO.ui.WindowManager();
$('body').append( mw.windowManager.$element );
}
mw.windowManager.addWindows( [dialog] );
dialog.message.$label.html( ["要打开", urlDisplay, "吗?"] );
});
let url = ele.text();
if (ele.
else if (ele.next( '.cm-mw-link' ).text() == '#') {
url += `#${ele.next().next( '.cm-mw-link-tosection' ).text()}`;
}
urlDisplay.text( url );
actionP.setHref( `${script}/${url}` );
actionP.$button.off( 'click' ).click(() => { dialog.close(); });
});
});
})
mw.loader.using( 'jquery.ui' ).then(() => { outer.resizable({handles: 'w', minWidth: 350}); });
mw.loader.using( ['mediawiki.api', 'oojs-ui-core', 'oojs-ui.styles.icons-movement'] ).then(() => {
const api = new mw.Api();
mw.request = mw.request || api.get({action: 'query', revids: mw.config.get('wgRevisionId'), prop: 'revisions',
let text, editor,
const btns = [new OO.ui.ButtonWidget({label: '提交', flags: ['primary', 'progressive']}).on('click', () => {
btns[0].setDisabled( true );
const now =
api.get({action: 'query', prop: 'revisions', pageids: id, rvprop: 'timestamp', formatversion: 2})
.then(res => {
if (new Date(res.query.pages[0].revisions[0].timestamp) > new Date(mw.request.curtimestamp)) {
return;
}
api.postWithEditToken({action: 'edit', pageid: id, text: editor.getValue(),
summary: '使用页面/文本对比查看器快速编辑'}).then(() => {
}, reason => { mw.notify(`编辑失败!错误信息:${reason}`, {type: 'error'}); });
}, reason => { mw.notify(`无法获得最新编辑时间戳!错误信息:${reason}`, {type: 'error'}); });
}), new OO.ui.ButtonWidget({label: '预览'}).on('click', () => {
const now = mw.now();
api.parse( editor.getValue(), { disablelimitreport: 1, disableeditsection: 1} ).then(html => {
console.log(`End API request: 已生成预览,用时 ${mw.now() - now} ms`);
$content.children( '.mw-parser-output' ).replaceWith( html );
mw.hook( 'wikipage.content' ).fire($content);
}, reason => { mw.notify(`无法生成预览!错误信息:${reason}`, {type: 'error'}); });
}), new OO.ui.ButtonWidget({
editor.setValue( text );
$content.children( '.mw-parser-output' ).replaceWith( original.clone(true) );
}), new OO.ui.ButtonWidget({label: '隐藏'}).on('click', () => {
css.disabled = !css.disabled;
cssHide.disabled = !cssHide.disabled;
wrapper.toggle();
btns[3].setLabel( css.disabled ? '显示' : '隐藏');
}), new OO.ui.ButtonWidget({flags: 'progressive', icon: 'next', href: `/?redirect=no&curid=${id + 1}`})],
getJSON = $.ajax({ dataType: 'json', cache: true,
url: '/zh?title=mediawiki:gadget-CodeMirror.json&action=raw&ctype=application/json' });
$.when(getJSON, mw.loader.using( ['ext.CodeMirror.lib', 'ext.CodeMirror.mode.mediawiki'] )).then(config => {
outer.removeClass( 'mw-ajax-loader' );
editor = new CodeMirror(outer[0], {mode: 'text/mediawiki', mwConfig: config, lineWrapping: true});
wrapper = $( editor.getWrapperElement() );
$('<div>', {html: btns.map(ele => ele.$element)}).appendTo( outer );
mw.request.then(data => {
console.log('End API request: 已获得页面Wikitext');
text = data.query.pages[0].revisions[0].content;
editor.setValue( text );
}, reason => { mw.notify(`无法获得页面Wikitext!错误原因${reason}`, {type: 'error'}); });
});
});
}) ();
|