MediaWiki:Common.js:修订间差异
外观
第3行: | 第3行: | ||
const STORAGE_KEY = 'uploadPreference'; | const STORAGE_KEY = 'uploadPreference'; | ||
const savedChoice = mw.storage.get(STORAGE_KEY); | |||
const | // 获取页面的 wpDestFile 参数(如果有) | ||
const urlParams = new URLSearchParams(location.search); | |||
const destFile = urlParams.get('wpDestFile'); | |||
// 生成带参数的 UploadWizard 链接 | |||
function getUploadWizardUrl() { | |||
let base = mw.util.getUrl('Special:UploadWizard'); | |||
if (destFile) { | |||
base += '?wpDestFile=' + encodeURIComponent(destFile); | |||
} | |||
return base; | |||
} | |||
// | // 自动跳转 | ||
if (savedChoice === 'wizard') { | if (savedChoice === 'wizard') { | ||
window.location.href = | window.location.href = getUploadWizardUrl(); | ||
return; | return; | ||
} | } | ||
if (savedChoice === 'classic') { | if (savedChoice === 'classic') { | ||
return; | return; | ||
} | } | ||
// | // 弹窗逻辑 | ||
var windowManager = new OO.ui.WindowManager(); | var windowManager = new OO.ui.WindowManager(); | ||
$(document.body).append(windowManager.$element); | $(document.body).append(windowManager.$element); | ||
第42行: | 第53行: | ||
var panel = new OO.ui.PanelLayout({ padded: true, expanded: false }); | var panel = new OO.ui.PanelLayout({ padded: true, expanded: false }); | ||
var rememberCheckbox = new OO.ui.CheckboxInputWidget({ selected: false }); | var rememberCheckbox = new OO.ui.CheckboxInputWidget({ selected: false }); | ||
this._rememberCheckbox = rememberCheckbox; | this._rememberCheckbox = rememberCheckbox; | ||
第51行: | 第61行: | ||
}); | }); | ||
var wizardButton = new OO.ui.ButtonWidget({ | var wizardButton = new OO.ui.ButtonWidget({ | ||
label: '✅ 使用上传向导(推荐)', | label: '✅ 使用上传向导(推荐)', | ||
flags: ['primary', 'progressive'], | flags: ['primary', 'progressive'], | ||
href: | href: getUploadWizardUrl(), | ||
target: '_self', | target: '_self', | ||
framed: true | framed: true | ||
}); | }); | ||
wizardButton.on('click', () => { | wizardButton.on('click', () => { | ||
if (rememberCheckbox.isSelected()) { | if (rememberCheckbox.isSelected()) { | ||
第67行: | 第75行: | ||
}); | }); | ||
panel.$element.append( | panel.$element.append( | ||
$('<p>').text('请选择你要使用的上传方式:'), | $('<p>').text('请选择你要使用的上传方式:'), |
2025年5月10日 (六) 11:52的版本
mw.loader.using(['mediawiki.util', 'oojs-ui', 'mediawiki.storage'], function () { if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload') { const STORAGE_KEY = 'uploadPreference'; const savedChoice = mw.storage.get(STORAGE_KEY); // 获取页面的 wpDestFile 参数(如果有) const urlParams = new URLSearchParams(location.search); const destFile = urlParams.get('wpDestFile'); // 生成带参数的 UploadWizard 链接 function getUploadWizardUrl() { let base = mw.util.getUrl('Special:UploadWizard'); if (destFile) { base += '?wpDestFile=' + encodeURIComponent(destFile); } return base; } // 自动跳转 if (savedChoice === 'wizard') { window.location.href = getUploadWizardUrl(); return; } if (savedChoice === 'classic') { return; } // 弹窗逻辑 var windowManager = new OO.ui.WindowManager(); $(document.body).append(windowManager.$element); function UploadDialog(config) { UploadDialog.super.call(this, config); } OO.inheritClass(UploadDialog, OO.ui.ProcessDialog); UploadDialog.static.name = 'UploadDialog'; UploadDialog.static.title = '请选择上传方式'; UploadDialog.static.actions = [ { action: 'classic', label: '❌ 使用传统上传方式(更快)', flags: ['safe'] } ]; UploadDialog.prototype.initialize = function () { UploadDialog.super.prototype.initialize.call(this); var panel = new OO.ui.PanelLayout({ padded: true, expanded: false }); var rememberCheckbox = new OO.ui.CheckboxInputWidget({ selected: false }); this._rememberCheckbox = rememberCheckbox; var rememberField = new OO.ui.FieldLayout(rememberCheckbox, { label: '记住我的选择,下次不再提示', align: 'inline' }); var wizardButton = new OO.ui.ButtonWidget({ label: '✅ 使用上传向导(推荐)', flags: ['primary', 'progressive'], href: getUploadWizardUrl(), target: '_self', framed: true }); wizardButton.on('click', () => { if (rememberCheckbox.isSelected()) { mw.storage.set(STORAGE_KEY, 'wizard'); } }); panel.$element.append( $('<p>').text('请选择你要使用的上传方式:'), $('<div>').css({ 'margin': '12px 0', 'background': '#f8f9fa', 'padding': '10px', 'border': '1px solid #ccc', 'border-radius': '5px' }).append( $('<strong>').text('✅ 上传向导(推荐)'), $('<ul>').append( $('<li>').text('支持多文件批量上传'), $('<li>').text('显示上传进度条'), $('<li>').text('信息填写更完整') ), $('<div>').css('margin-top', '8px').append(wizardButton.$element) ), $('<div>').css({ 'margin-top': '15px', 'background': '#ffffff', 'padding': '10px', 'border': '1px dashed #bbb', 'border-radius': '5px' }).append( $('<strong>').text('⚡️ 传统上传方式'), $('<ul>').append( $('<li>').text('界面更简单'), $('<li>').text('加载速度快'), $('<li>').text('适合上传单个文件') ) ), $('<div>').css('margin-top', '15px').append(rememberField.$element) ); this.$body.append(panel.$element); }; UploadDialog.prototype.getActionProcess = function (action) { if (action === 'classic') { if (this._rememberCheckbox.isSelected()) { mw.storage.set(STORAGE_KEY, 'classic'); } return new OO.ui.Process(() => this.close()); } return UploadDialog.super.prototype.getActionProcess.call(this, action); }; var dialog = new UploadDialog(); windowManager.addWindows([dialog]); windowManager.openWindow(dialog); } });