User:Bosco-bot/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
Undid revisions from 69986 to 69954 // AdvancedRollback Tag: Undo |
mNo edit summary Tag: Reverted |
||
| Line 1: | Line 1: | ||
/** |
|||
// JWB |
|||
* Protection helper (zh-Hans / zh-Hant) |
|||
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js&action=raw&ctype=text/javascript'); |
|||
* - Handles protect and unprotect |
|||
* - Default language zh-Hans |
|||
* - Always ask for expiry (default indefinite) |
|||
* - Split edit/move protection levels |
|||
* - Namespace restrictions |
|||
* - Direct protect URL construction |
|||
*/ |
|||
mw.loader.using(['mediawiki.util'], function () { |
|||
// MarkRights-zh |
|||
var ns = mw.config.get('wgNamespaceNumber'); |
|||
importScript('User:Bosco/MediaWiki:Gadget-MarkRights.js'); // Backlink: [[User:Bosco/MediaWiki:Gadget-MarkRights.js]] |
|||
if (ns === -1 || ns === -2) return; |
|||
// Language detection (default zh-Hans) |
|||
// Mass block |
|||
var rawLang = mw.config.get('wgContentLanguage') || 'zh-hans'; |
|||
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Timotheus_Canens/massblock.js&action=raw&ctype=text/javascript'); |
|||
var lang = (['zh', 'zh-hans', 'zh-cn', 'zh-my', 'zh-sg'].includes(rawLang)) ? 'zh-hans' : 'zh-hant'; |
|||
// Reasons dictionary |
|||
// AdvancedRollback |
|||
var reasonsHans = { |
|||
mw.loader.load('//dev.miraheze.org/w/index.php?title=User:PB2008/AdvancedRollback/auto.js&action=raw&ctype=text/javascript'); |
|||
G1: "遭到过度破坏的页面", |
|||
G2: "拥有过多垃圾信息的页面", |
|||
G3: "拥有负面的编辑战的页面", |
|||
G4: "高流量页面", |
|||
G5: "当时有争议和谣言风靡的页面", |
|||
G6: "备受争议的页面", |
|||
G7: "同一时间或不同时间针对性被破坏的页面", |
|||
G8: "动画中的宝可梦被公布可能会进化", |
|||
R2: "译名备受争议但并无错误的重定向", |
|||
// Diffedit |
|||
R3: "需要保护的重定向", |
|||
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=User:Jon_Harald_Søby/diffedit.js&action=raw&ctype=text/javascript' ); |
|||
R4: "刻意双重重定向或者指向不存在页面的重定向", |
|||
F1: "有必要保护的文件", |
|||
// Edit count |
|||
F2: "刻意拥有重复文件", |
|||
(function(editCount) { |
|||
F3: "备受争议的文件", |
|||
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 + ')"}') |
|||
})(mw.config.get('wgUserEditCount')); |
|||
O1: "用户请求保护自己的用户页或子页面", |
|||
O2: "神奇宝贝百科站务或方针方面的页面", |
|||
O3: "刻意使用的空的类别(没有条目也没有子类别)" |
|||
}; |
|||
var reasonsHant = { |
|||
G1: "遭到過度破壞的頁面", |
|||
G2: "擁有過多垃圾資訊的頁面", |
|||
G3: "擁有負面的編輯戰的頁面", |
|||
G4: "高流量頁面", |
|||
G5: "當時有爭議和謠言風靡的頁面", |
|||
G6: "備受爭議的頁面", |
|||
G7: "同一時間或不同時間針對性被破壞的頁面", |
|||
G8: "動畫中的寶可夢被公布可能會進化", |
|||
R2: "譯名備受爭議但並無錯誤的重定向", |
|||
R3: "需要保護的重定向", |
|||
R4: "刻意雙重重定向或者指向不存在頁面的重定向", |
|||
F1: "有必要保護的檔案", |
|||
F2: "刻意擁有重複檔案", |
|||
F3: "備受爭議的檔案", |
|||
O1: "用戶請求保護自己的用戶頁或子頁面", |
|||
O2: "神奇寶貝百科站務或方針方面的頁面", |
|||
O3: "刻意使用的空的類別(沒有條目也沒有子類別)" |
|||
}; |
|||
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 reasonPrompt = (lang === 'zh-hans') ? '请输入保护/解除保护理由:' : '請輸入保護/解除保護理由:'; |
|||
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 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); |
|||
var expiry = prompt(expiryPrompt) || "indefinite"; |
|||
var reason = prompt(reasonPrompt) || ""; |
|||
var pageName = mw.config.get('wgPageName'); |
|||
var baseUrl = mw.util.getUrl(pageName); |
|||
// Protect mode: require code |
|||
var finalReason = reason; |
|||
if (protections.length > 0) { |
|||
var validReasons = getValidReasons(); |
|||
var codePrompt = (lang === 'zh-hans' ? "请输入保护代碼:\n" : "請輸入保護代碼:\n") + |
|||
Object.keys(validReasons).map(function (k) { |
|||
return k + ":" + validReasons[k]; |
|||
}).join("\n"); |
|||
var code = prompt(codePrompt); |
|||
if (!code || !validReasons[code]) { |
|||
alert((lang === 'zh-hans') ? "无效代碼,请重新输入。" : "無效代碼,請重新輸入。"); |
|||
return; |
|||
} |
|||
// O1 requires reason |
|||
if (code === "O1" && !reason) { |
|||
alert((lang === 'zh-hans') ? "O1 必须提供理由。" : "O1 必須提供理由。"); |
|||
return; |
|||
} |
|||
finalReason = code + ":" + validReasons[code] + (reason ? ";" + reason : ""); |
|||
} |
|||
var finalUrl = baseUrl + "?action=protect" + |
|||
(protections.length ? "&" + protections.join("&") : "") + |
|||
"&mwProtect-reason=" + encodeURIComponent(finalReason) + |
|||
"&mwProtect-expiry=" + encodeURIComponent(expiry); |
|||
window.location.href = finalUrl; |
|||
}); |
|||
}); |
|||