LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-site-shared.js”的版本间差异
跳转到导航
跳转到搜索
小 |
小 |
||
第6行: | 第6行: | ||
*/ |
*/ |
||
"use strict"; |
"use strict"; |
||
/*global OO, wgULS*/ |
/*global OO, wgULS, wgUCS*/ |
||
const pagename = mw.config.get('wgPageName'), |
const pagename = mw.config.get('wgPageName'), |
||
specialPage = mw.config.get( 'wgCanonicalSpecialPageName' ), |
specialPage = mw.config.get( 'wgCanonicalSpecialPageName' ), |
||
第12行: | 第12行: | ||
editable = mw.config.get( 'wgIsProbablyEditable' ), |
editable = mw.config.get( 'wgIsProbablyEditable' ), |
||
username = mw.config.get('wgUserName'), |
username = mw.config.get('wgUserName'), |
||
$body = $('body') |
$body = $('body'), |
||
uri = new mw.Uri(); |
|||
mw.messages.set( wgUCS({'gadget-ss-sandbox': '欢迎来到沙盒!您可以在此进行编辑测试。', 'gadget-ss-request': '编辑请求_-_'}, |
|||
{'gadget-ss-sandbox': '歡迎來到沙盒!您可以在此進行編輯測試。', 'gadget-ss-request': '編輯請求_-_'}) ); |
|||
/** |
/** |
||
第21行: | 第24行: | ||
*/ |
*/ |
||
if (pagename.endsWith( '/' ) && specialPage != 'Prefixindex') { |
if (pagename.endsWith( '/' ) && specialPage != 'Prefixindex') { |
||
const uri = new mw.Uri(); |
|||
delete uri.query.title; |
delete uri.query.title; |
||
const query = uri.getQueryString(); |
const query = uri.getQueryString(); |
||
// 最稳健的短地址方案 |
// 最稳健的短地址方案 |
||
location.replace('/zh/' + mw.util.wikiUrlencode( pagename.slice(0, -1) ) + (query ? '?' + query : '')); |
location.replace('/zh/' + mw.util.wikiUrlencode( pagename.slice(0, -1) ) + (query ? '?' + query : '')); |
||
} |
|||
/** |
|||
* @Function: 生成沙盒顶部 |
|||
* @Dependencies: mediawiki.Uri |
|||
*/ |
|||
// 即使是最新版本,在差异模式下也不会添加沙盒顶部 |
|||
if (['LLWiki:沙盒', 'Template:Sandbox'].includes(pagename) && action == 'view' && |
|||
!(uri.query.diff || uri.query.oldid)) { |
|||
$('#mw-content-text').prepend( '<table class="infobox" style="background-color:#f3f5f7;width:70%;border-left-color:#c5c5c5" cellpadding="2" align="center">' + |
|||
'<tbody><tr>' + |
|||
'<td width="15%">' + |
|||
'<img src="/mediawiki/img_auth.php/0/04/Bandeau-avertisement-3.png" width="50" height="50">' + |
|||
'</td>' + |
|||
'<td><span style="color:">' + mw.msg( 'gadget-ss-sandbox' ) + '</span></td>' + |
|||
'</tr></tbody>' + |
|||
'</table>' ); |
|||
} |
} |
||
第41行: | 第60行: | ||
} ); |
} ); |
||
}); |
}); |
||
} |
|||
/** |
|||
* @Function: 生成完整的编辑请求链接 |
|||
* @Dependencies: mediawiki.Uri |
|||
*/ |
|||
const $editRequest = $('.editRequest > a'); |
|||
if (['edit', 'submit'].includes(action) && !editable && username && $editRequest.length) { |
|||
$editRequest.attr('href', function(i, val) { |
|||
return new mw.Uri( val ).extend({ preloadtitle: mw.msg('gadget-ss-request') + |
|||
// 不能出现空格,否则会被转换为+ |
|||
username.replaceAll(' ', '_') + '_(' + new Date().toISOString().slice(0, 10) + ')' |
|||
}).toString(); |
|||
}); |
|||
} |
|||
/** |
|||
* @Function: 嵌入外部站点时进行提示 |
|||
* @Dependencies: oojs-ui-core, oojs-ui-windows, ext.gadget.site-lib |
|||
* @Source: [[moegirl:mediawiki:common.js]] |
|||
* @EditedBy: [[User:Bhsd]] |
|||
*/ |
|||
if (top !== window || location.host !== 'llwiki.org') { |
|||
mw.messages.set( wgULS({ |
|||
'gadget-ss-title': '<p>LLWiki提醒您</p><p>您正在非LLWiki域名访问</p>', |
|||
'gadget-ss-label': '<p>请注意不要在此域名下输入您的用户名或密码,以策安全!</p><p>LLWiki的域名为 llwiki.org</p>', |
|||
'gadget-jump': '前往LLWiki', 'gadget-continue': '我知道了' |
|||
}, { |
|||
'gadget-ss-title': '<p>LLWiki提醒您</p><p>您正在非LLWiki域名訪問</p>', |
|||
'gadget-ss-label': '<p>請注意不要在此域名下輸入您的用戶名或密碼,以策安全!</p><p>LLWiki的域名為 llwiki.org</p>', |
|||
'gadget-jump': '前往LLWiki', 'gadget-continue': '我知道了' |
|||
}) ); |
|||
const dialog = new OO.ui.MessageDialog(), |
|||
actionP = new OO.ui.ActionWidget({label: mw.msg('gadget-ss-jump'), flags: ['primary', 'progressive'], |
|||
href: top === window ? 'https://llwiki.org' : location.href}), |
|||
actionC = new OO.ui.ActionWidget({label: mw.msg('gadget-ss-continue'), flags: ['primary', 'destructive']}); |
|||
mw.dialog(dialog, [actionC, actionP], mw.msg('gadget-ss-label'), mw.msg('gadget-ss-title')); |
|||
} |
} |
||
第48行: | 第104行: | ||
* @Dependencies: mediawiki.util, mediawiki.Title |
* @Dependencies: mediawiki.util, mediawiki.Title |
||
*/ |
*/ |
||
console.log('Hook: wikipage.content, 开始处理其他用户主页面的红链'); |
|||
$content.find( '.new' ).attr('href', function(i, val) { |
$content.find( '.new' ).attr('href', function(i, val) { |
||
const query = mw.util.getParamValue('title', val); |
const query = mw.util.getParamValue('title', val); |
||
第57行: | 第114行: | ||
return title.getUrl(); |
return title.getUrl(); |
||
}); |
}); |
||
/** |
|||
* @Function: 生成完整的编辑请求链接 |
|||
* @Dependencies: mediawiki.Uri |
|||
*/ |
|||
const $ele = $('.editRequest > a'); |
|||
if (['edit', 'submit'].includes(action) && !editable && username && $ele.length) { |
|||
$ele.attr('href', function(i, val) { |
|||
return mw.Uri( val ).extend({ preloadtitle: |
|||
// 不能出现空格,否则会被转换为+ |
|||
'编辑请求_-_' + username.replaceAll(' ', '_') + '_(' + new Date().toISOString().slice(0, 10) + ')' |
|||
}).toString(); |
|||
}); |
|||
} |
|||
// 引自[[moegirl:mediawiki:common.js]] |
|||
if (top !== window || location.host !== 'llwiki.org') { |
|||
var messageDialog = new OO.ui.MessageDialog(), |
|||
windowManager = new OO.ui.WindowManager(); |
|||
$("body").append(windowManager.$element); |
|||
windowManager.addWindows([messageDialog]); |
|||
messageDialog.title.$label.html('<p>LLWiki提醒您</p><p>您正在非LLWiki域名' + wgULS('访问', '訪問') + '</p>'); |
|||
messageDialog.message.$label.html('<p>' + wgULS('请注意不要在此域名下输入您的用户名或密码', '請注意不要在此域名下輸入您的用戶名或密碼') + ',以策安全!</p><p>LLWiki' + wgULS('域名为 ', '域名為') + ' llwiki.org</p>'); |
|||
windowManager.openWindow(messageDialog, { |
|||
actions: [{ |
|||
action: "continue", |
|||
label: "我知道了", |
|||
flags: ["primary", "destructive"] |
|||
}, { |
|||
action: "jump", |
|||
label: "前往LLWiki", |
|||
flags: ["primary", "progressive"], |
|||
href: top === window ? "https://llwiki.org" : location.href, |
|||
target: "_blank" |
|||
}] |
|||
}); |
|||
var timer = setInterval(function() { |
|||
if ($('.oo-ui-windowManager .oo-ui-buttonElement-button').length) { |
|||
clearInterval(timer); |
|||
$('.oo-ui-windowManager .oo-ui-buttonElement-button').each(function() { |
|||
if (this.href) { $(this).off('click'); } |
|||
}); |
|||
} |
|||
}, 100); |
|||
} |
|||
}); |
}); |
||
第108行: | 第120行: | ||
*/ |
*/ |
||
mw.hook( 'wikipage.categories' ).add(function($content) { |
mw.hook( 'wikipage.categories' ).add(function($content) { |
||
console.log('Hook: wikipage.categories, 开始替换小写分类'); |
|||
$content.find( 'a:contains("Μ\'s")' ).text(function(i, text) { return text.replace("Μ's", "μ's"); }); |
$content.find( 'a:contains("Μ\'s")' ).text(function(i, text) { return text.replace("Μ's", "μ's"); }); |
||
$content.find( 'a:contains("Lily white")' ).text(function(i, text) { return text.replace('Lily', 'lily'); }); |
$content.find( 'a:contains("Lily white")' ).text(function(i, text) { return text.replace('Lily', 'lily'); }); |
||
}); |
}); |
||
//</nowiki> |
|||
// [[category:桌面版小工具]] [[category:手机版小工具]] [[category:作为模块的小工具]] [[category:系统工具]] [[category:不可关闭的小工具]] |
|||
$(function() { |
|||
// {{DEFAULTSORT:site-shared.js}} |
|||
/* 沙盒顶部 */ |
|||
var uri = new mw.Uri(); |
|||
if ( ['LLWiki:沙盒', 'Template:Sandbox'].includes(pagename) && action == 'view' && |
|||
!(uri.query.diff || uri.query.oldid) ) { |
|||
$('#mw-content-text').prepend('<table class="infobox" style="background-color:#f3f5f7;width:70%;border-left-color:#c5c5c5" cellpadding="2" align="center">' + |
|||
'<tbody><tr>' + |
|||
'<td width="15%">' + |
|||
'<img src="/mediawiki/img_auth.php/0/04/Bandeau-avertisement-3.png" width="50" height="50">' + |
|||
'</td>' + |
|||
'<td><span style="color:">欢迎来到沙盒!您可以在此进行编辑测试。</span></td>' + |
|||
'</tr></tbody>' + |
|||
'</table>'); |
|||
} |
|||
}); |
2021年1月24日 (日) 13:22的版本
//<nowiki> // 由ResourceLoader直接调用,不可使用ES6语法 /** * @Description: 这里是桌面版和手机版通用的全局JS * @Author: 如无特殊说明,均为[[User:Bhsd]] */ "use strict"; /*global OO, wgULS, wgUCS*/ const pagename = mw.config.get('wgPageName'), specialPage = mw.config.get( 'wgCanonicalSpecialPageName' ), action = mw.config.get('wgAction'), editable = mw.config.get( 'wgIsProbablyEditable' ), username = mw.config.get('wgUserName'), $body = $('body'), uri = new mw.Uri(); mw.messages.set( wgUCS({'gadget-ss-sandbox': '欢迎来到沙盒!您可以在此进行编辑测试。', 'gadget-ss-request': '编辑请求_-_'}, {'gadget-ss-sandbox': '歡迎來到沙盒!您可以在此進行編輯測試。', 'gadget-ss-request': '編輯請求_-_'}) ); /** * @Function: 去掉地址栏最后的"/" * @Dependencies: mediawiki.util, mediawiki.Uri * @Author: [[wikipedia:User:Majavah]] * @EditedBy: [[User:Bhsd]] */ if (pagename.endsWith( '/' ) && specialPage != 'Prefixindex') { delete uri.query.title; const query = uri.getQueryString(); // 最稳健的短地址方案 location.replace('/zh/' + mw.util.wikiUrlencode( pagename.slice(0, -1) ) + (query ? '?' + query : '')); } /** * @Function: 生成沙盒顶部 * @Dependencies: mediawiki.Uri */ // 即使是最新版本,在差异模式下也不会添加沙盒顶部 if (['LLWiki:沙盒', 'Template:Sandbox'].includes(pagename) && action == 'view' && !(uri.query.diff || uri.query.oldid)) { $('#mw-content-text').prepend( '<table class="infobox" style="background-color:#f3f5f7;width:70%;border-left-color:#c5c5c5" cellpadding="2" align="center">' + '<tbody><tr>' + '<td width="15%">' + '<img src="/mediawiki/img_auth.php/0/04/Bandeau-avertisement-3.png" width="50" height="50">' + '</td>' + '<td><span style="color:">' + mw.msg( 'gadget-ss-sandbox' ) + '</span></td>' + '</tr></tbody>' + '</table>' ); } /** * @Function: 更复杂的快速插入 * @Source: [[mw:Extension:CharInsert]] * @Dependencies: jquery.textSelection(已由CharInsert扩展加载) */ if (['edit', 'submit'].includes( action ) && editable) { $body.on('click', 'span.mw-charinsert-item', function() { const $this = $(this); $('#wpTextbox1').textSelection( 'encapsulateSelection', { pre: $this.data( 'mw-charinsert-start' ) || $this.data( 'start' ), // undefined也没关系 post: $this.data( 'mw-charinsert-end' ) || $this.data( 'end' ) } ); }); } /** * @Function: 生成完整的编辑请求链接 * @Dependencies: mediawiki.Uri */ const $editRequest = $('.editRequest > a'); if (['edit', 'submit'].includes(action) && !editable && username && $editRequest.length) { $editRequest.attr('href', function(i, val) { return new mw.Uri( val ).extend({ preloadtitle: mw.msg('gadget-ss-request') + // 不能出现空格,否则会被转换为+ username.replaceAll(' ', '_') + '_(' + new Date().toISOString().slice(0, 10) + ')' }).toString(); }); } /** * @Function: 嵌入外部站点时进行提示 * @Dependencies: oojs-ui-core, oojs-ui-windows, ext.gadget.site-lib * @Source: [[moegirl:mediawiki:common.js]] * @EditedBy: [[User:Bhsd]] */ if (top !== window || location.host !== 'llwiki.org') { mw.messages.set( wgULS({ 'gadget-ss-title': '<p>LLWiki提醒您</p><p>您正在非LLWiki域名访问</p>', 'gadget-ss-label': '<p>请注意不要在此域名下输入您的用户名或密码,以策安全!</p><p>LLWiki的域名为 llwiki.org</p>', 'gadget-jump': '前往LLWiki', 'gadget-continue': '我知道了' }, { 'gadget-ss-title': '<p>LLWiki提醒您</p><p>您正在非LLWiki域名訪問</p>', 'gadget-ss-label': '<p>請注意不要在此域名下輸入您的用戶名或密碼,以策安全!</p><p>LLWiki的域名為 llwiki.org</p>', 'gadget-jump': '前往LLWiki', 'gadget-continue': '我知道了' }) ); const dialog = new OO.ui.MessageDialog(), actionP = new OO.ui.ActionWidget({label: mw.msg('gadget-ss-jump'), flags: ['primary', 'progressive'], href: top === window ? 'https://llwiki.org' : location.href}), actionC = new OO.ui.ActionWidget({label: mw.msg('gadget-ss-continue'), flags: ['primary', 'destructive']}); mw.dialog(dialog, [actionC, actionP], mw.msg('gadget-ss-label'), mw.msg('gadget-ss-title')); } mw.hook( 'wikipage.content' ).add(function($content) { /** * @Function: 点击其他用户主页面的红链不会进入创建页面 * @Dependencies: mediawiki.util, mediawiki.Title */ console.log('Hook: wikipage.content, 开始处理其他用户主页面的红链'); $content.find( '.new' ).attr('href', function(i, val) { const query = mw.util.getParamValue('title', val); if (!query) { return; } // 特殊页面 const title = new mw.Title( query ), // 借助mediawiki.Title规范用户名格式 name = title.getMainText(); // 不处理非用户空间或用户子页面 if (title.namespace != 2 || name.includes( '/' ) || name == username) { return; } return title.getUrl(); }); }); /** * @Function: 分类栏显示小写标题 */ mw.hook( 'wikipage.categories' ).add(function($content) { console.log('Hook: wikipage.categories, 开始替换小写分类'); $content.find( 'a:contains("Μ\'s")' ).text(function(i, text) { return text.replace("Μ's", "μ's"); }); $content.find( 'a:contains("Lily white")' ).text(function(i, text) { return text.replace('Lily', 'lily'); }); }); //</nowiki> // [[category:桌面版小工具]] [[category:手机版小工具]] [[category:作为模块的小工具]] [[category:系统工具]] [[category:不可关闭的小工具]] // {{DEFAULTSORT:site-shared.js}}