模組:沙盒/逆襲的天邪鬼/vandal

维基百科,自由的百科全书
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

eatuserbox

顧名思義,就是把某個維基人的用戶框全部吃掉。用法:

{{ #invoke:沙盒/逆襲的天邪鬼/vandal | eatuserbox |
{{babel|zh|en}}
... 把用戶框包上
}}

該函數支持兩個參數,notaunt和nocategory,只要該兩個參數不為空就會被視為true。

如果未設置notaunt,那麼該函數不會吃掉{{User 坐等删除}},而是會把其中的文字換成「该用户的用户框被人删光啦!」。如果未設置nocategory,該函數會給維基人加一個分類:Category:用戶框被刪光了的維基人

如果哪個用戶框沒有被吃掉,請找到那個用戶框的原始碼,把它更正為使用{{Userbox}}或{{Userbox-m}}的標準化用戶框。

由於{{#invoke}}內不能放入表格,所以如果哪個維基人的用戶框是用表格組織起來的,也可以另外開一個頁面,然後把用戶框引用過來,例如:

{{ #invoke:沙盒/逆襲的天邪鬼/vandal | eatuserbox | {{User:Hat600/用户框}} }}

其實吧,為了方便使用,它已經變成了一個模板:{{User 全部删光}}。

countstars

數一下文本裡面有多少個星號「*」。如果想查其他符號,請修改第二個參數。

數一下星號「*」
{{ #invoke:沙盒/逆襲的天邪鬼/vandal | countstars |
#*A--~~~~
#**B--~~~~
#***C--~~~~}}

6

改成井號「#」
{{ #invoke:沙盒/逆襲的天邪鬼/vandal | countstars | 2=# |
#*A--~~~~
#**B--~~~~
#***C--~~~~}}

3

strrev

天邪鬼的特技,把一個字符串顛倒過來。注意不要往裡面放HTML標籤一類的代碼——它們也會被顛倒。(可以考慮考慮不破壞HTML標籤的顛倒……)

{{ #invoke:沙盒/逆襲的天邪鬼/vandal | strrev |這本來是一個連結,但是不知為什麼,突然就點不動了,也許是需要清除首頁快取吧。 }}

��㧐喏嫿偠閦餙酸恦耜鯘汨蟹䌼䕋卸䞻鱰嶄灪猼Z逻亂祟獸䯘憽䌼磀鋀倸䯘憾䬜晀�

雖說很奇怪就是了......

eatlinks

{{ #invoke:沙盒/逆襲的天邪鬼/vandal | eatlinks |這本來是一個[[Help:連結|連結]],但是不知為什麼,突然就點不動了,也許是需要[https://zh.wikipedia.org/w/index.php?title{{=}}Wikipedia:首页&action{{=}}purge 清除首頁快取]吧。 }}

這本來是一個連結,但是不知為什麼,突然就點不動了,也許是需要清除首頁快取吧。

eatlinks2

{{ #invoke:沙盒/逆襲的天邪鬼/vandal | eatlinks2 |這本來是一個[[Help:連結|連結]],但是不知為什麼,點進去之後也不正常了,也許同樣需要[https://zh.wikipedia.org/w/index.php?title{{=}}Wikipedia:首页&action{{=}}purge 清除首頁快取]吧。| target=Special:Logout }}

這本來是一個連結,但是不知為什麼,點進去之後也不正常了,也許同樣需要清除首頁快取吧。

local func = {}

local function rfind(s, pattern, init)
    local x, y
    local len = #s
    local i = init or len
    x, y = string.find(string.reverse(s), string.reverse(pattern), len-i+1, true)
    if x then
        return len-y+1, len-x+1
    end
end

function func.eatuserbox(frame)
    local text = frame.args[1] or ''
    local output = ''
    
    output = string.gsub(text, '(class="wikipediauserbox" style=".-)"', '%1;visibility:hidden;"')
    output = string.gsub(output, '(style=".-)(" class="wikipediauserbox")', '%1;visibility:hidden;%2')
    output = string.gsub(output, '(class="wikipediauserbox%-m" style=".-)"', '%1;visibility:hidden;"')
    output = string.gsub(output, '(<div style=".-)(">%s*{%|%s*cellspacing="0")', '%1;visibility:hidden;%2')
    -- 專殺{{現在}}
    output = string.gsub(output, '(<div style="float:left; border: 1px solid orange; margin:1px; background: white; width: 238px; height:45px; text%-align: center; vertical%-align: middle;.-)(">)', '%1;visibility:hidden;%2')
    
    -- 將「坐等刪除」換成已被刪光
    if (not frame.args['notaunt']) or (mw.text.trim(frame.args['notaunt']) == '') then
        local x, y = string.find(output, '這個用戶正坐等他人來.-刪除用戶框.-</td>', 1, false)
        if x then
            local left1, left2 = rfind(output, 'visibility:hidden;', x)
            output = string.sub(output, 1, left1-1) .. string.sub(output, left2+1, x-1) .. '這個用戶的用戶框全都被人刪光啦!</td>' .. string.sub(output, y+1, -1)
        end
    end

    if (not frame.args['nocategory']) or (mw.text.trim(frame.args['nocategory']) == '') then
        output = output .. '[[Category:用戶框被刪光了的維基人]]'
    end

    return output
end

function func.countstars(frame)
    local text = frame.args[1] or ''
    local pattern = frame.args[2] or '%*'
    local count = 0
    for _ in string.gmatch(text, pattern) do
    	count = count + 1
    end
    return count
end

function func.strrev(frame)
    local text = frame.args[1] or ''
    return string.reverse(text)
end

function func.strreplace(frame)
    local text = frame.args[1] or ''
    local i=2
    local from, to
    while frame.args[i] do
        from = frame.args[i]
        to = frame.args[i+1] or ''
        text = string.gsub(text, from, to)
        i=i+2
    end
    return text
end

function func.nowiki(frame)
    local text = frame.args[1] or ''
    return mw.text.nowiki(text)
end

function func.nowiki2(frame)
    local text = mw.title.new(frame.args[1]):getContent()
    return mw.text.nowiki(text)
end

local function islinkeatable(text)
    local test = string.lower(text)
    return not (string.find(test, 'category:') == 1 or string.find(test, '分类:') == 1 or 
           string.find(test, '分類:') == 1 or string.find(test, 'file:') == 1 or
           string.find(test, '文件:') == 1 or string.find(test, '檔案:') == 1 or
           string.find(test, 'en:') == 1 or string.find(test, 'ja:') == 1)
end

function func.eatlinks(frame)
    local text = frame.args[1] or ''
    text = (string.gsub(text, '%[%[([^\n]-)%]%]', function(x)
        if islinkeatable(x) then
            local target = string.gsub(x, '^(.-)%|.-$', '%1')
            local text = string.gsub(x, '^.-%|(.-)$', '%1')

            if string.find(target, ':') == 1 then
                if text == target then
                    text = string.sub(text, 2)
                end
                return '<span style="color:#36b;cursor:pointer;">' .. text .. '</span>'
            else
                if (not mw.title.new(target):getContent()) and (not frame.args['nored']) then
                    return '<span style="color:#ba0000;cursor:pointer;">' .. text .. '</span>'
                else
                    return '<span style="color:#0645ad;cursor:pointer;">' .. text .. '</span>'
                end
            end
        else
            return '[[' .. x .. ']]'
        end
    end))

    text = (string.gsub(text, '%[https?://[^\n]- ([^\n]-)%]', function(x)
        return '<span style="color:#36b;cursor:pointer;">' .. x .. '</span>'
    end))

    return text
end

function func.eatlinks2(frame)
    local text = frame.args[1] or ''
    local badtarget = frame.args['target'] or 'Special:Logout'
    text = (string.gsub(text, '%[%[([^\n]-)%]%]', function(x)
        if islinkeatable(x) then
            local target = string.gsub(x, '^(.-)%|.-$', '%1')
            local text = string.gsub(x, '^.-%|(.-)$', '%1')

            if string.find(target, ':') == 1 then
                if text == target then
                    text = string.sub(text, 2)
                end
                return '[[' .. badtarget .. '|<span style="color:#36b;cursor:pointer;">' .. text .. '</span>]]'
            else
                if (not mw.title.new(target):getContent()) and (not frame.args['nored']) then
                    return '[[' .. badtarget .. '|<span style="color:#ba0000;cursor:pointer;">' .. text .. '</span>]]'
                else
                    return '[[' .. badtarget .. '|<span style="color:#0645ad;cursor:pointer;">' .. text .. '</span>]]'
                end
            end
        else
            return '[[' .. x .. ']]'
        end
    end))

    text = (string.gsub(text, '%[https?://[^\n]- ([^\n]-)%]', function(x)
        return '[[' .. badtarget .. '|<span style="color:#36b;cursor:pointer;">' .. x .. '</span>]]'
    end))

    return text
end

return func