打开主菜单
首页
随机
最近更改
特殊页面
沙盒
互助客栈
方针与指引
帮助
页面信息
链入页面
相关更改
设置
关于LLWiki
免责声明
LLWiki
搜索
用户菜单
18.117.77.76
讨论
监视列表
贡献
登录
LLWiki正在建设中,欢迎
加入我们
!
查看“MediaWiki:Gadget-inspect.js”的源代码
←
MediaWiki:Gadget-inspect.js
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
该页提供此wiki软件的界面文字,它已被保护以防止恶意修改。您可以点击右侧按钮在讨论页提出编辑请求,让管理人员代为编辑:
提出编辑请求
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
// 由[[special:mypage/vector.js]]调用,可以使用ES6语法 /** * @dependencies: mediawiki.api, mediawiki.storage, mediawiki.util, oojs-ui-core, oojs-windows, oojs-styles.icons-movement, jquery.ui, ext.CodeMirror.lib, ext.CodeMirror.mode.mediawiki */ "use strict"; /*global mw, $, OO, CodeMirror*/ mw.loader.using( 'mediawiki.util' ).then(() => { let dialog, actionP, actionD; const $content = $('#mw-content-text, #mw-imagepage-content').last(), original = $content.children( '.mw-parser-output' ), placeholder = $('<div>', {class: "mw-parser-output"}).css('display', 'none'), script = mw.config.get('wgScript'), id = mw.config.get( 'wgArticleId' ), urlDisplay = $('<a>', {href: "#"}).click(e => { e.preventDefault(); }), css = mw.util.addCSS( '#mw-content-text .mw-parser-output p { border:1px dashed; }' + '#mw-content-text .mw-parser-output { display:flow-root; overflow:hidden; word-wrap:break-word; }'), 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(); const ele = $(this), promise = dialog ? Promise.resolve() : mw.loader.using( 'oojs-ui-windows' ).then(() => { dialog = new OO.ui.MessageDialog(); actionP = new OO.ui.ActionWidget({label: '是', target: '_blank', flags: 'progressive'}); 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.hasClass( 'cm-mw-template-name' )) { url = `模板:${url}`; } else if (ele.next( '.cm-mw-link' ).text() == '#') { url += `#${ele.next().next( '.cm-mw-link-tosection' ).text()}`; } urlDisplay.text( url ); promise.then(() => { actionP.setHref( `${script}/${url}` ); mw.windowManager.openWindow( dialog, {actions: [actionP, actionD]}).opening.then(() => { actionP.$button.off( 'click' ).click(() => { dialog.close(); }); }); }); }); mw.loader.using( 'jquery.ui' ).then(() => { outer.resizable({handles: 'w', minWidth: 350}); }); mw.loader.using( ['mediawiki.api', 'mediawiki.storage', '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', rvprop: 'content', curtimestamp: 1, formatversion: 2}); let text, editor, wrapper, btns; const next = function() { const list = mw.storage.getObject( 'inspect-category' ); if (!list) { return id + 1; } if (list[0][ list[1] ] == id) { list[1]++; if (list[1] >= list[0].length) { btns[4].setDisabled( true ); } mw.storage.setObject( 'inspect-category', list ); } return list[0][ list[1] ]; }, getJSON = $.ajax({ dataType: 'json', cache: true, url: '/zh?title=mediawiki:gadget-CodeMirror.json&action=raw&ctype=application/json' }); btns = [new OO.ui.ButtonWidget({label: '提交', flags: ['primary', 'progressive']}).on('click', () => { btns[0].setDisabled( true ); console.log('API request: 查询最新编辑时间戳'); const now = mw.now(); api.get({action: 'query', prop: 'revisions', pageids: id, rvprop: 'timestamp', formatversion: 2}) .then(res => { console.log(`End API request: 已获得最新编辑时间戳,用时 ${mw.now() - now} ms`); if (new Date(res.query.pages[0].revisions[0].timestamp) > new Date(mw.request.curtimestamp)) { mw.notify('编辑冲突!', {type: 'error'}); return; } api.postWithEditToken({action: 'edit', pageid: id, text: editor.getValue(), summary: '使用页面/文本对比查看器快速编辑'}).then(() => { window.location.reload(); }, reason => { mw.notify(`编辑失败!错误信息:${reason}`, {type: 'error'}); }); }, reason => { mw.notify(`无法获得最新编辑时间戳!错误信息:${reason}`, {type: 'error'}); }); }), new OO.ui.ButtonWidget({label: '预览'}).on('click', () => { btns[1].setDisabled( true ); console.log('API request: 请求预览'); const now = mw.now(); api.parse( editor.getValue(), { disablelimitreport: 1, disableeditsection: 1} ).then(html => { console.log(`End API request: 已生成预览,用时 ${mw.now() - now} ms`); if ($.contains( $content[0], original[0] )) { original.after( placeholder ).detach(); } $content.children( '.mw-parser-output' ).replaceWith( html ); mw.hook( 'wikipage.content' ).fire($content); btns[1].setDisabled( false ); }, reason => { mw.notify(`无法生成预览!错误信息:${reason}`, {type: 'error'}); }); }), new OO.ui.ButtonWidget({label: '还原', flags: 'destructive'}).on('click', () => { editor.setValue( text ); $content.children( '.mw-parser-output' ).replaceWith( original ); }), 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=${next()}`})], btns[4].$element.contextmenu(e => { e.preventDefault(); OO.ui.prompt( '请输入分类名:' ).then(cat => { if (cat === null) { return; } btns[4].setDisabled( false ); if (cat === '') { mw.storage.remove( 'inspect-category' ); btns[4].setHref( `/?redirect=no&curid=${next()}` ); } if (!/^([Cc]ategory|分[类類]):/.test( cat )) { cat = `Category:${cat}`; } console.log('API request: 查询标准的页面名'); let now = mw.now(); api.get({action: 'query', titles: cat, converttitles: 1, formatversion: 2}).then(response => { const target = response.query.pages[0]; if (target.missing) { mw.notify('错误的分类名!', {type: 'error'}); return; } console.log(`End API request: 已获得标准的页面名,用时 ${mw.now() - now} ms`); console.log('API request: 查询分类下的页面列表'); now = mw.now(); api.get({action: 'query', list: 'categorymembers', cmtitle: target.title, cmprop: 'ids', cmlimit: 'max', formatversion: 2}).then(cm => { console.log(`End API request: 已获得分类下的页面列表,用时 ${mw.now() - now} ms`); const pages = cm.query.categorymembers.map(ele => ele.pageid).sort((a, b) => a > b); if (pages.length === 0) { mw.notify('该分类下无页面!', {type: 'warn'}); return; } const currentIndex = pages[0] == id ? 1 : 0; mw.storage.setObject( 'inspect-category', [pages, currentIndex] ); btns[4].setHref( `/?redirect=no&curid=${pages[ currentIndex ]}` ); }, reason => { mw.notify(`无法获得该分类下的页面列表!错误信息:${reason}`, {type: 'error'}); }); }, reason => { mw.notify(`无法获得页面名称!错误信息:${reason}`, {type: 'error'}); }); }); }); $.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[0], 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'}); }); }); }); });
返回
MediaWiki:Gadget-inspect.js
。