<commit_before>// <nowiki>
(function(){

if (typeof(UnblockZhIpbe) == 'undefined')
    UnblockZhIpbe = {};

if (typeof(UnblockZhIpbe.enableOn) != 'function') {
    UnblockZhIpbe.enableOn = function() {
        if (mw.config.get('wgCanonicalSpecialPageName') == 'Userrights') {
            return true;
        }
        return false;
    }
}

if (typeof(UnblockZhIpbe.duration) != 'object') {
    UnblockZhIpbe.duration = ['3 months', '6 months'];
}
UnblockZhIpbe.duration.push('infinite');

function AskUnblockZhUrl() {
    var url;
    var msgprefix = '';
    while (true) {
        url = prompt(msgprefix + '請輸入 unblock-zh 郵件網址\n形如 https://lists.wikimedia.org/mailman/private/unblock-zh/2018-November/012345.html');
        if (url === null) {
            return false;
        }
        if ((m = url.match(/(https?:\/\/lists\.wikimedia\.org\/mailman\/private\/(unblock-zh\/\d+\-.+\/\d+)\.html)/)) !== null) {
            return {'long': m[1], 'short': m[2]};
        }
        msgprefix = '格式錯誤！請重新輸入\n';
    }
}

function AskDuration() {
    var duration;
    var msgprefix = '';
    var msg = '授權期限？';
    for (var i = 0; i < UnblockZhIpbe.duration.length; i++) {
        msg += '\n' + (i + 1) + '. ' + UnblockZhIpbe.duration[i];
    }
    while (true) {
        duration = prompt(msgprefix + msg);
        if (duration === null) {
            return false;
        }
        duration = duration.trim() - 1;
        if (UnblockZhIpbe.duration[duration] !== undefined) {
            return UnblockZhIpbe.duration[duration];
        }
        msgprefix = '輸入不在列表內，請重新輸入';
    }
}

function GrantIpbe(username, duration, urlshort) {
    new mw.Api().postWithToken('userrights', {
        action: 'userrights',
        user: username,
        add: 'ipblock-exempt',
        expiry: duration,
        reason: urlshort
    }).then(function(e) {
        mw.notify('成功授予 ' + username + ' IPBE ' + duration);
    }, function(e) {
        mw.notify('未知錯誤：' + e);
    });
}

function NotifyUser(username, duration) {
    var message = '{{subst:Ipexemptgranted|temp=1}}';
    if (duration == 'infinite') {
        message = '{{subst:Ipexemptgranted}}';
    }

    var usertalk = 'User talk:' + username;
    new mw.Api().get({
        action: 'query',
        prop: 'info',
        titles: usertalk
    }).done(function(data) {
        if (Object.values(data.query.pages)[0].contentmodel == 'flow-board') {
            new mw.Api().postWithEditToken({
                action: 'flow',
                page: usertalk,
                submodule: 'new-topic',
                nttopic: '授予IP封禁例外權通知',
                ntcontent: message,
                ntformat: 'wikitext',
            }).then(function(e) {
                mw.notify('成功發送通知給 ' + username);
            }, function(e) {
                mw.notify('未知錯誤：' + e);
            });
        } else {
            new mw.Api().newSection(usertalk,
                '',
                message
            ).then(function(e) {
                mw.notify('成功發送通知給 ' + username);
            }, function(e) {
                mw.notify('未知錯誤：' + e);
            });
        }
    });
}

function Report(username, urllong) {
    new mw.Api().newSection('Wikipedia:權限申請/申請IP封禁例外權',
        '',
        '{{subst:rfp|' + username + '|2=[' + urllong + ' unblock-zh]|status=+}}--~~~~'
    ).then(function(e) {<commit_msg>Update unblock-zh-ipbe to add summary to report<commit_after>// <nowiki>
(function(){

if (typeof(UnblockZhIpbe) == 'undefined')
    UnblockZhIpbe = {};

if (typeof(UnblockZhIpbe.enableOn) != 'function') {
    UnblockZhIpbe.enableOn = function() {
        if (mw.config.get('wgCanonicalSpecialPageName') == 'Userrights') {
            return true;
        }
        return false;
    }
}

if (typeof(UnblockZhIpbe.duration) != 'object') {
    UnblockZhIpbe.duration = ['3 months', '6 months'];
}
UnblockZhIpbe.duration.push('infinite');

function AskUnblockZhUrl() {
    var url;
    var msgprefix = '';
    while (true) {
        url = prompt(msgprefix + '請輸入 unblock-zh 郵件網址\n形如 https://lists.wikimedia.org/mailman/private/unblock-zh/2018-November/012345.html');
        if (url === null) {
            return false;
        }
        if ((m = url.match(/(https?:\/\/lists\.wikimedia\.org\/mailman\/private\/(unblock-zh\/\d+\-.+\/\d+)\.html)/)) !== null) {
            return {'long': m[1], 'short': m[2]};
        }
        msgprefix = '格式錯誤！請重新輸入\n';
    }
}

function AskDuration() {
    var duration;
    var msgprefix = '';
    var msg = '授權期限？';
    for (var i = 0; i < UnblockZhIpbe.duration.length; i++) {
        msg += '\n' + (i + 1) + '. ' + UnblockZhIpbe.duration[i];
    }
    while (true) {
        duration = prompt(msgprefix + msg);
        if (duration === null) {
            return false;
        }
        duration = duration.trim() - 1;
        if (UnblockZhIpbe.duration[duration] !== undefined) {
            return UnblockZhIpbe.duration[duration];
        }
        msgprefix = '輸入不在列表內，請重新輸入';
    }
}

function GrantIpbe(username, duration, urlshort) {
    new mw.Api().postWithToken('userrights', {
        action: 'userrights',
        user: username,
        add: 'ipblock-exempt',
        expiry: duration,
        reason: urlshort
    }).then(function(e) {
        mw.notify('成功授予 ' + username + ' IPBE ' + duration);
    }, function(e) {
        mw.notify('未知錯誤：' + e);
    });
}

function NotifyUser(username, duration) {
    var message = '{{subst:Ipexemptgranted|temp=1}}';
    if (duration == 'infinite') {
        message = '{{subst:Ipexemptgranted}}';
    }

    var usertalk = 'User talk:' + username;
    new mw.Api().get({
        action: 'query',
        prop: 'info',
        titles: usertalk
    }).done(function(data) {
        if (Object.values(data.query.pages)[0].contentmodel == 'flow-board') {
            new mw.Api().postWithEditToken({
                action: 'flow',
                page: usertalk,
                submodule: 'new-topic',
                nttopic: '授予IP封禁例外權通知',
                ntcontent: message,
                ntformat: 'wikitext',
            }).then(function(e) {
                mw.notify('成功發送通知給 ' + username);
            }, function(e) {
                mw.notify('未知錯誤：' + e);
            });
        } else {
            new mw.Api().newSection(usertalk,
                '',
                message
            ).then(function(e) {
                mw.notify('成功發送通知給 ' + username);
            }, function(e) {
                mw.notify('未知錯誤：' + e);
            });
        }
    });
}

function Report(username, urllong) {
    new mw.Api().edit('Wikipedia:權限申請/申請IP封禁例外權', function(revision) {
        return {
            text: revision.content + '\n\n{{subst:rfp|' + username + '|2=[' + urllong + ' unblock-zh]|status=+}}--~~~~',
            summary: '授予 ' + username + ' IP封禁例外權備案'
        };
    }).then(function(e) {
{'fraction_non_alphanumeric': 0.1708169506334644, 'fraction_numerical': 0.005824959953400321, 'mean_word_length': 1.9641778161415624, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5587625', 'n_tokens_mistral': 2436, 'n_tokens_neox': 2455, 'n_words': 398}