User:Bosco-bot/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
No edit summary Tag: Reverted |
Tag: Undo |
||
| Line 1: | Line 1: | ||
// JWB |
|||
/** |
|||
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js&action=raw&ctype=text/javascript'); |
|||
* Protection helper (zh-Hans / zh-Hant) |
|||
* - Default language zh-Hans |
|||
* - Always ask for expiry (default indefinite) |
|||
* - Split edit/move protection levels |
|||
* - Namespace restrictions |
|||
* - Direct protect URL construction |
|||
* - Reason optional except O4/O5 (mandatory) |
|||
*/ |
|||
// MarkRights-zh |
|||
mw.loader.using(['mediawiki.util'], function () { |
|||
importScript('User:Bosco/MediaWiki:Gadget-MarkRights.js'); // Backlink: [[User:Bosco/MediaWiki:Gadget-MarkRights.js]] |
|||
var ns = mw.config.get('wgNamespaceNumber'); |
|||
if (ns === -1 || ns === -2) return; |
|||
// Mass block |
|||
// Language detection (default zh-Hans) |
|||
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Timotheus_Canens/massblock.js&action=raw&ctype=text/javascript'); |
|||
var rawLang = mw.config.get('wgContentLanguage') || 'zh-hans'; |
|||
var lang = (['zh', 'zh-hans', 'zh-cn', 'zh-my', 'zh-sg'].includes(rawLang)) ? 'zh-hans' : 'zh-hant'; |
|||
// AdvancedRollback |
|||
// Reasons dictionary |
|||
mw.loader.load('//dev.miraheze.org/w/index.php?title=User:PB2008/AdvancedRollback/auto.js&action=raw&ctype=text/javascript'); |
|||
var reasonsHans = { |
|||
G1: "遭到过度破坏的页面", |
|||
G2: "拥有过多垃圾信息的页面", |
|||
G3: "拥有负面的编辑战的页面", |
|||
G4: "高流量页面", |
|||
G5: "当时有争议和谣言风靡的页面", |
|||
G6: "备受争议的页面", |
|||
G7: "同一时间或不同时间针对性被破坏的页面", |
|||
G8: "动画中的宝可梦被公布可能会进化", |
|||
// Diffedit |
|||
R2: "译名备受争议但并无错误的重定向", |
|||
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=User:Jon_Harald_Søby/diffedit.js&action=raw&ctype=text/javascript' ); |
|||
R3: "需要保护的重定向", |
|||
R4: "刻意双重重定向或者指向不存在页面的重定向", |
|||
// Edit count |
|||
F1: "有必要保护的文件", |
|||
(function(editCount) { |
|||
F2: "刻意拥有重复文件", |
|||
if (editCount !== null) mw.loader.addStyleTag('#pt-mycontris>a::after, .menu__item--userContributions>span>span::after, #mw-mf-page-left .menu__item--userContributions>span::after {content: " (' + editCount + ')"}') |
|||
F3: "备受争议的文件", |
|||
})(mw.config.get('wgUserEditCount')); |
|||
O1: "用户请求保护自己的用户页或子页面", |
|||
O2: "神奇宝贝百科站务或方针方面的页面", |
|||
O3: "刻意使用的空的类别(没有条目也没有子类别)", |
|||
O4: "其他需要保护的页面", |
|||
O5: "解除保护的页面" |
|||
}; |
|||
var reasonsHant = { |
|||
G1: "遭到過度破壞的頁面", |
|||
G2: "擁有過多垃圾資訊的頁面", |
|||
G3: "擁有負面的編輯戰的頁面", |
|||
G4: "高流量頁面", |
|||
G5: "當時有爭議和謠言風靡的頁面", |
|||
G6: "備受爭議的頁面", |
|||
G7: "同一時間或不同時間針對性被破壞的頁面", |
|||
G8: "動畫中的寶可夢被公布可能會進化", |
|||
R2: "譯名備受爭議但並無錯誤的重定向", |
|||
R3: "需要保護的重定向", |
|||
R4: "刻意雙重重定向或者指向不存在頁面的重定向", |
|||
F1: "有必要保護的檔案", |
|||
F2: "刻意擁有重複檔案", |
|||
F3: "備受爭議的檔案", |
|||
O1: "用戶請求保護自己的用戶頁或子頁面", |
|||
O2: "神奇寶貝百科站務或方針方面的頁面", |
|||
O3: "刻意使用的空的類別(沒有條目也沒有子類別)", |
|||
O4: "其他需要保護的頁面", |
|||
O5: "解除保護的頁面" |
|||
}; |
|||
var reasonsAll = (lang === 'zh-hans') ? reasonsHans : reasonsHant; |
|||
// Filter reasons by namespace |
|||
function getValidReasons() { |
|||
var valid = {}; |
|||
Object.keys(reasonsAll).forEach(function (code) { |
|||
if (['F1','F2','F3'].includes(code) && ns !== 6) return; |
|||
if (code === 'O1' && !(ns === 2 || ns === 3)) return; |
|||
if (code === 'O2' && !(ns === 4 || ns === 5)) return; |
|||
if (code === 'O3' && ns !== 14) return; |
|||
valid[code] = reasonsAll[code]; |
|||
}); |
|||
return valid; |
|||
} |
|||
var linkText = (lang === 'zh-hans') ? '保护/解除保护' : '保護/解除保護'; |
|||
var tooltip = linkText; |
|||
var editPrompt = (lang === 'zh-hans') |
|||
? "请输入编辑保护级别 (autoconfirmed/sysop/admin/none):" |
|||
: "請輸入編輯保護級別 (autoconfirmed/sysop/admin/none):"; |
|||
var movePrompt = (lang === 'zh-hans') |
|||
? "请输入移动保护级别 (autoconfirmed/sysop/admin/none):" |
|||
: "請輸入移動保護級別 (autoconfirmed/sysop/admin/none):"; |
|||
var expiryPrompt = (lang === 'zh-hans') ? "请输入保护期限 (默认 indefinite):" : "請輸入保護期限 (默認 indefinite):"; |
|||
var reasonTip = (lang === 'zh-hans') ? "提示:請提供額外理由(可選,O4/O5 必須提供理由)" : "提示:請提供額外理由(可選,O4/O5 必須提供理由)"; |
|||
var link = mw.util.addPortletLink('p-cactions', '#', linkText, 'ca-protectpage', tooltip); |
|||
$(link).on('click', function (e) { |
|||
e.preventDefault(); |
|||
var editChoice = prompt(editPrompt); |
|||
var moveChoice = prompt(movePrompt); |
|||
function normalizeLevel(input) { |
|||
if (!input) return ""; |
|||
var val = input.trim().toLowerCase(); |
|||
if (val === "autoconfirmed") return "autoconfirmed"; |
|||
if (val === "sysop" || val === "admin") return "sysop"; |
|||
if (val === "none") return ""; |
|||
return ""; |
|||
} |
|||
var editLevel = normalizeLevel(editChoice); |
|||
var moveLevel = normalizeLevel(moveChoice); |
|||
var protections = []; |
|||
if (editLevel) protections.push("mwProtect-level-edit=" + editLevel); |
|||
if (moveLevel) protections.push("mwProtect-level-move=" + moveLevel); |
|||
// Expiry normalization |
|||
var expiryInput = prompt(expiryPrompt) || "indefinite"; |
|||
var expiry = expiryInput.trim().toLowerCase(); |
|||
if (expiry === "1day" || expiry === "1 day" || expiry === "一天") expiry = "1 day"; |
|||
if (expiry === "2days" || expiry === "2 days" || expiry === "兩天") expiry = "2 days"; |
|||
if (expiry === "1week" || expiry === "1 week" || expiry === "一週" || expiry === "一周") expiry = "1 week"; |
|||
if (expiry === "2weeks" || expiry === "2 weeks" || expiry === "兩週" || expiry === "兩周") expiry = "2 weeks"; |
|||
if (expiry === "1month" || expiry === "1 month" || expiry === "一月" || expiry === "一個月") expiry = "1 month"; |
|||
if (expiry === "indefinite" || expiry === "infinite" || expiry === "forever" || expiry === "永久") expiry = "indefinite"; |
|||
var pageName = mw.config.get('wgPageName'); |
|||
var baseUrl = mw.util.getUrl(pageName); |
|||
var finalReason = ""; |
|||
var validReasons = getValidReasons(); |
|||
if (protections.length > 0) { |
|||
var codePrompt = (lang === 'zh-hans' ? "请输入保护代碼:\n" : "請輸入保護代碼:\n") + |
|||
Object.keys(validReasons).map(function (k) { |
|||
return k + ":" + validReasons[k]; |
|||
}).join("\n") + "\n" + reasonTip; |
|||
var code = prompt(codePrompt); |
|||
var reason = prompt((lang === 'zh-hans') ? "请输入理由:" : "請輸入理由:") || ""; |
|||
if (!code || !validReasons[code]) { |
|||
if (!reason) { |
|||
alert((lang === 'zh-hans') ? "O4 必须提供理由。" : "O4 必須提供理由。"); |
|||
return; |
|||
} |
|||
finalReason = "O4:" + reasonsAll.O4 + ";" + reason; |
|||
} else if (code === "O4" && !reason) { |
|||
alert((lang === 'zh-hans') ? "O4 必须提供理由。" : "O4 必須提供理由。"); |
|||
return; |
|||
} else { |
|||
finalReason = code + ":" + validReasons[code] + (reason ? ";" + reason : ""); |
|||
} |
|||
} else { |
|||
// Unprotect → O5, must have reason |
|||
var reason = prompt((lang === 'zh-hans') ? "请输入解除保护理由:" : "請輸入解除保護理由:") || ""; |
|||
if (!reason) { |
|||
alert((lang === 'zh-hans') ? "O5 必须提供理由。" : "O5 必須提供理由。"); |
|||
return; |
|||
} |
|||
finalReason = "O5:" + reasonsAll.O5 + ";" + reason; |
|||
} |
|||
var finalUrl = baseUrl + "?action=protect" + |
|||
(protections.length ? "&" + protections.join("&") : "") + |
|||
"&mwProtect-reason=" + encodeURIComponent(finalReason) + |
|||
"&mwProtect-expiry=" + encodeURIComponent(expiry); |
|||
// Directly navigate, no confirmation |
|||
window.location.href = finalUrl; |
|||
}); |
|||
}); |
|||