User:Bosco-bot/common.js: Difference between revisions

From Test Wiki
Content deleted Content added
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 6: Line 6:
* - Namespace restrictions
* - Namespace restrictions
* - Direct protect URL construction
* - Direct protect URL construction
* - Reason optional for all codes except O4/O5 (mandatory)
* - Reason optional except O4/O5 (mandatory)
*/
*/


Line 17: Line 17:
var lang = (['zh', 'zh-hans', 'zh-cn', 'zh-my', 'zh-sg'].includes(rawLang)) ? 'zh-hans' : 'zh-hant';
var lang = (['zh', 'zh-hans', 'zh-cn', 'zh-my', 'zh-sg'].includes(rawLang)) ? 'zh-hans' : 'zh-hant';


// Reasons dictionary (Simplified Chinese)
// Reasons dictionary
var reasonsHans = {
var reasonsHans = {
G1: "遭到过度破坏的页面",
G1: "遭到过度破坏的页面",
Line 43: Line 43:
};
};


// Reasons dictionary (Traditional Chinese)
var reasonsHant = {
var reasonsHant = {
G1: "遭到過度破壞的頁面",
G1: "遭到過度破壞的頁面",
Line 120: Line 119:
if (moveLevel) protections.push("mwProtect-level-move=" + moveLevel);
if (moveLevel) protections.push("mwProtect-level-move=" + moveLevel);


// Expiry normalization
var expiry = prompt(expiryPrompt) || "indefinite";
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 pageName = mw.config.get('wgPageName');
Line 126: Line 133:


var finalReason = "";
var finalReason = "";

var validReasons = getValidReasons();
var validReasons = getValidReasons();


Line 139: Line 145:


if (!code || !validReasons[code]) {
if (!code || !validReasons[code]) {
// Unknown code → force O4, must have reason
if (!reason) {
if (!reason) {
alert((lang === 'zh-hans') ? "O4 必须提供理由。" : "O4 必須提供理由。");
alert((lang === 'zh-hans') ? "O4 必须提供理由。" : "O4 必須提供理由。");