条件类别

时间:2018-10-23 12:21:40

标签: mediawiki mediawiki-extensions mediawiki-templates

我使用的模板{{MyTemplate|foo}}由以下代码组成:

{{#switch: {[[Category:Foo]]}
 | foo = [[Category:Foo]]
 | bar = [[Category:Bar]]
 | #default = [[Category:Unknown]]
}}

当我在页面上使用它时,类别会很好地显示在页面底部。但不幸的是,在该类别页面内(例如,Category:Foo),该页面没有显示。

如果我手动向该页面添加-Wall -pedantic-errors,则该页面将显示在Foo-category-page中。

有什么建议为什么不能通过模板使用?

3 个答案:

答案 0 :(得分:4)

包含先前代码的模板页面是否出现在Unknown类别下?如果是,则包含该模板的任何页面都必须出现在其类别中。您可能只需要清除缓存,如果您的维基百科很大,请等待几秒钟。

确保foo&bar类别未隐藏在您的Wiki中。看到这个:https://www.mediawiki.org/wiki/Help:Categories#Hidden_categories

编辑

也请尝试以下解决方案之一,它们可以实现相同的目标:

{{#switch: {{{#ifeq: {      if(response != nil)
            {
                // Print out reponse body
                let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
                //print("****** response data = \(responseString!)")

                do {
                    let json = try JSONSerialization.jsonObject(with: data!, options: []) as? NSDictionary

                    print(json ?? "Error")
                    print("responseString :-%@",responseString ?? "error");
                    DispatchQueue.main.async {

                        if((json?.count)! > 0)
                        {
                           //here you get json as dictionary now you can have your implementation
                        }

                    }

                }catch
                {
                    print(error)
                    failure(error as NSError);

                }
            }
} | foo | [[Category:Foo]] | {{#ifeq: {wget http://localhost:8080/account/login
} | bar | [[Category:Bar]] |  [[Category:Unknown]]}} }}
}
 | foo = [[Category:Foo]]
 | bar = [[Category:Bar]]
 | #default = [[Category:Unknown]]
}}

OR

$(document).ready(function()
{
    // Sorting function

    function getSorted(selector, attrName)
    {
        return $($(selector).toArray().sort(function(a, b)
        {
            var aVal = parseInt(a.getAttribute(attrName)),
            bVal = parseInt(b.getAttribute(attrName));
            return aVal - bVal;
        }));
    }

    var sortedItems = getSorted('div.question', 'data-answerCount').clone();
    var unsortedQuestionItems = $('.question');
    console.log("Replacing unsorted question items with sorted question items");
    console.log("oldArray is of length: " +unsortedQuestionItems.length);
    console.log("newArray is of length: " +sortedItems.length);
    unsortedQuestionItems.replaceWith(sortedItems);
    console.log("Replacing completed.");

    var afterReplaced = $('.question');
    console.log("After replacing, the length of .question is: " +afterReplaced.length);
}); //ends the document.ready function

答案 1 :(得分:0)

您是否在Wiki上运行作业队列?链接表是异步更新的,而不是在页面保存时更新。

https://www.mediawiki.org/wiki/Manual:Job_queue

https://www.mediawiki.org/wiki/Manual:RunJobs.php

答案 2 :(得分:0)

无法理解问题的描述,但是无论如何,您似乎可以通过以下方式实现相同的目标:

{{#vardefine: my_category |wow}}
[[Category: {{#ifeq: {{#var:my_category}}| default| unknown| {{#var:my_category}} }} ]]

将此类别添加到页面中, 我认为,在任何情况下添加类别时都应使用switch,但在另一种情况下决定添加类别。

如果您要在所有情况下添加类别,则可以像我在上面所述的那样编写,或者将最终类别导出到另一个变量并在类别内使用它。

对于您的问题,您可以在此页面上使用“?action = purge”,如果不起作用,请在此处写一些详细信息。

相关问题