LLWiki正在建设中,欢迎
加入我们
!
查看“MediaWiki:Gadget-inspect.js”的源代码
←
MediaWiki:Gadget-inspect.js
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
该页提供此wiki软件的界面文字,它已被保护以防止恶意修改。您可以点击右侧按钮在讨论页提出编辑请求,让管理人员代为编辑:
提出编辑请求
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
// 由[[special:mypage/vector.js]]调用,可以使用ES6语法 /** * @dependencies: mediawiki.api, mediawiki.util, oojs-ui-core, ext.CodeMirror.lib, ext.CodeMirror.mode.mediawiki */ "use strict"; /*global mw, $, OO, CodeMirror*/ mw.util.addCSS( '#mw-content-text > .mw-parser-output, .CodeMirror { display:inline-block; width:49%; }' + '.CodeMirror { float:right; position:sticky; top:7px; border:1px solid; height:90vh; }' + '.oo-ui-buttonWidget { margin:0.5em; }'); $.getJSON( '/zh?title=mediawiki:gadget-CodeMirror.json&action=raw&ctype=application/json', config => { let text = ''; const $content = $('#mw-content-text'), id = mw.config.get( 'wgArticleId' ), api = new mw.Api(), editor = new CodeMirror($content[0], {mode: 'text/mediawiki', mwConfig: config, lineWrapping: true}), btn1 = new OO.ui.ButtonWidget({label: '提交', flags: ['primary', 'progressive']}).on('click', () => { console.log('API request: 查询最新编辑时间戳'); const now = mw.now(); api.get({action: 'query', prop: 'revisions', pageids: id, rvlimit: 1, 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()}).then(() => { window.location.reload(); }, reason => { mw.notify(`编辑失败!错误信息:${reason}`, {type: 'error'}); }); }, reason => { mw.notify(`无法获得最新编辑时间戳!错误信息:${reason}`, {type: 'error'}); }); }), btn2 = new OO.ui.ButtonWidget({label: '预览'}).on('click', () => { 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`); $content.children( '.mw-parser-output' ).replaceWith( html ); }, reason => { mw.notify(`无法生成预览!错误信息:${reason}`, {type: 'error'}); }); }), btn3 = new OO.ui.ButtonWidget({label: '还原', flags: ['destructive']}).on('click', () => { editor.setValue( text ); }); $('<div>', {html: [btn1.$element, btn2.$element, btn3.$element]}).appendTo( $content ).css('float', 'right'); mw.request = mw.request || api.get({action: 'query', revids: mw.config.get('wgRevisionId'), prop: 'revisions', rvprop: 'content', curtimestamp: 1, formatversion: 2}); 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
。
导航菜单
个人工具
创建账号
登录
命名空间
系统消息
讨论
变体
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
随机页面
最近更改
沙盒
互助客栈
方针与指引
帮助
工具
链入页面
相关更改
特殊页面
页面信息